summaryrefslogtreecommitdiff
path: root/src/hwdata.c
blob: 212e86034d928ed87ca2f7f4b86eb70e14cde449 (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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "hwdata.h"
#include <errno.h>

/******************************************************/

static int parse_event(struct HWData *hw)
{
	const struct input_event *ev = hw->event + hw->at++;
	bool on = ev->value != 0;
	switch (ev->type) {
	case EV_SYN:
		switch (ev->code) {
		case SYN_REPORT:
			return 0;
		}
		break;
	case EV_KEY:
		switch (ev->code) {
		case BTN_LEFT:
			hw->left = on;
			break;
		case BTN_MIDDLE:
			hw->middle = on;
			break;
		case BTN_RIGHT:
			hw->right = on;
			break;
		case BTN_MT_REPORT_PACKET:
			if (on)
				hw->nfinger = 0;
			break;
		case BTN_MT_REPORT_FINGER:
			if (!on && hw->nfinger < DIM_FINGER)
				hw->nfinger++;
			break;
		}
		break;
	case EV_ABS:
		switch (ev->code) {
		case ABS_MT_TOUCH_MAJOR:
			hw->finger[hw->nfinger].touch_major = ev->value;
			break;
		case ABS_MT_TOUCH_MINOR:
			hw->finger[hw->nfinger].touch_minor = ev->value;
			break;
		case ABS_MT_WIDTH_MAJOR:
			hw->finger[hw->nfinger].width_major = ev->value;
			break;
		case ABS_MT_WIDTH_MINOR:
			hw->finger[hw->nfinger].width_minor = ev->value;
			break;
		case ABS_MT_ORIENTATION:
			hw->finger[hw->nfinger].orientation = ev->value;
			break;
		case ABS_MT_POSITION_X:
			hw->finger[hw->nfinger].position_x = ev->value;
			break;
		case ABS_MT_POSITION_Y:
			hw->finger[hw->nfinger].position_y = ev->value;
			break;
		}
		break;
	}
	return -EAGAIN;
}

/******************************************************/

int read_hwdata(struct HWData *hw, int fd)
{
	int n;
	do {
		while (hw->at < hw->nev)
			if (!parse_event(hw))
				return 0;
		n = read(fd, hw->event, sizeof(hw->event));
		hw->at = 0;
		hw->nev = n / sizeof(struct input_event);
		xf86Msg(X_INFO, "multitouch: read: %d %d\n", n, hw->nev);
	} while (n > 0);
	return -EIO;
};

/******************************************************/

void output_hwdata(const struct HWData *hw)
{
}

/******************************************************/