1 /***************************************************************************
4 * Copyright (C) 2008 Henrik Rydberg <rydberg@euromail.se>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 **************************************************************************/
24 void hwstate_init(struct HWState *s, const struct Capabilities *caps)
27 memset(s, 0, sizeof(struct HWState));
28 for (i = 0; i < DIM_FINGER; i++)
29 s->data[i].tracking_id = MT_ID_NULL;
30 s->max_x = get_cap_xsize(caps);
31 s->max_y = get_cap_ysize(caps);
34 static void finish_packet(struct HWState *s, const struct Capabilities *caps,
35 const struct input_event *syn)
37 static const mstime_t ms = 1000;
39 foreach_bit(i, s->used) {
40 if (!caps->has_abs[MTDEV_TOUCH_MINOR])
41 s->data[i].touch_minor = s->data[i].touch_major;
42 if (!caps->has_abs[MTDEV_WIDTH_MINOR])
43 s->data[i].width_minor = s->data[i].width_major;
45 timercp(&s->evtime, &syn->time);
48 static int read_event(struct HWState *s, const struct Capabilities *caps,
49 const struct input_event *ev)
55 finish_packet(s, caps, ev);
62 MODBIT(s->button, MT_BUTTON_LEFT, ev->value);
65 MODBIT(s->button, MT_BUTTON_MIDDLE, ev->value);
68 MODBIT(s->button, MT_BUTTON_RIGHT, ev->value);
75 if (ev->value >= 0 && ev->value < DIM_FINGER)
78 case ABS_MT_TOUCH_MAJOR:
79 s->data[s->slot].touch_major = ev->value;
81 case ABS_MT_TOUCH_MINOR:
82 s->data[s->slot].touch_minor = ev->value;
84 case ABS_MT_WIDTH_MAJOR:
85 s->data[s->slot].width_major = ev->value;
87 case ABS_MT_WIDTH_MINOR:
88 s->data[s->slot].width_minor = ev->value;
90 case ABS_MT_ORIENTATION:
91 s->data[s->slot].orientation = ev->value;
94 s->data[s->slot].pressure = ev->value;
96 case ABS_MT_POSITION_X:
97 s->data[s->slot].position_x = ev->value;
99 case ABS_MT_POSITION_Y:
100 s->data[s->slot].position_y = ev->value;
102 case ABS_MT_TRACKING_ID:
103 s->data[s->slot].tracking_id = ev->value;
104 MODBIT(s->used, s->slot, ev->value != MT_ID_NULL);
112 int hwstate_modify(struct HWState *s, struct mtdev *dev, int fd,
113 const struct Capabilities *caps)
115 struct input_event ev;
117 while ((ret = mtdev_get(dev, fd, &ev, 1)) > 0) {
118 if (read_event(s, caps, &ev))
124 int find_finger(const struct HWState *s, int tracking_id) {
126 foreach_bit(i, s->used) {
127 if (s->data[i].tracking_id == tracking_id)