]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/bitsy/mouse.c
merge
[plan9front.git] / sys / src / 9 / bitsy / mouse.c
1 #include "u.h"
2 #include "../port/lib.h"
3 #include "mem.h"
4 #include "dat.h"
5 #include "fns.h"
6 #include "../port/error.h"
7 #include "io.h"
8
9 #define Image   IMAGE
10 #include <draw.h>
11 #include <memdraw.h>
12 #include <cursor.h>
13 #include "screen.h"
14
15 enum {
16         Button1 = 0x1;
17         Button2 = 0x2;
18         Button3 = 0x4;
19 };
20
21 int             buttons;
22 Point   position;
23
24 static void
25 mousevent(void) {
26         static int              curbuttons;
27         static Point    curposition;
28
29         if (buttons == curbuttons && eqpt(position, curposition))
30                 return;
31
32         /* generate a mouse event */
33         curbuttons = buttons;
34         curposition = position;
35 }
36
37 void
38 buttonevent(int event) {
39         switch (event) {
40         case 0x02:
41                 /* Button 2 down */
42                 buttons |= Button2;
43                 mousevent();
44                 break;
45         case 0x82:
46                 /* Button 2 up */
47                 buttons &= ~Button2;
48                 mousevent();
49                 break;
50         case 0x03:
51                 /* Button 3 down */
52                 buttons |= Button3;
53                 mousevent();
54                 break;
55         case 0x83:
56                 /* Button 3 up */
57                 buttons &= ~Button3;
58                 mousevent();
59                 break;
60         default:
61                 /* other buttons */
62         }
63 }