summaryrefslogtreecommitdiff
path: root/sys/src/9/bitsy/mouse.c
blob: f266070222d90b938219696f34b68c48e0b63c93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "u.h"
#include "../port/lib.h"
#include "mem.h"
#include "dat.h"
#include "fns.h"
#include "../port/error.h"
#include "io.h"

#define	Image	IMAGE
#include <draw.h>
#include <memdraw.h>
#include <cursor.h>
#include "screen.h"

enum {
	Button1 = 0x1;
	Button2 = 0x2;
	Button3 = 0x4;
};

int		buttons;
Point	position;

static void
mousevent(void) {
	static int		curbuttons;
	static Point	curposition;

	if (buttons == curbuttons && eqpt(position, curposition))
		return;

	/* generate a mouse event */
	curbuttons = buttons;
	curposition = position;
}

void
buttonevent(int event) {
	switch (event) {
	case 0x02:
		/* Button 2 down */
		buttons |= Button2;
		mousevent();
		break;
	case 0x82:
		/* Button 2 up */
		buttons &= ~Button2;
		mousevent();
		break;
	case 0x03:
		/* Button 3 down */
		buttons |= Button3;
		mousevent();
		break;
	case 0x83:
		/* Button 3 up */
		buttons &= ~Button3;
		mousevent();
		break;
	default:
		/* other buttons */
	}
}