commit 4834576
Michael Forney
·
2014-01-20 22:36:16 +0000 UTC
parent 7c3bc48
evdev_device: Use libevdev properly Now sync events are dealt with correctly.
1 files changed,
+33,
-13
+33,
-13
1@@ -130,6 +130,19 @@ static void handle_motion_events(struct swc_evdev_device * device,
2 }
3 }
4
5+static void handle_event(struct swc_evdev_device * device,
6+ struct input_event * event)
7+{
8+ if (!is_motion_event(event))
9+ handle_motion_events(device, timeval_to_msec(&event->time));
10+
11+ if (event->type < ARRAY_SIZE(event_handlers)
12+ && event_handlers[event->type])
13+ {
14+ event_handlers[event->type](device, event);
15+ }
16+}
17+
18 static int handle_data(int fd, uint32_t mask, void * data)
19 {
20 struct swc_evdev_device * device = data;
21@@ -141,25 +154,32 @@ static int handle_data(int fd, uint32_t mask, void * data)
22 ret = libevdev_next_event(device->dev, LIBEVDEV_READ_FLAG_NORMAL,
23 &event);
24
25- if (ret == -EAGAIN)
26- break;
27-
28- while (ret == LIBEVDEV_READ_STATUS_SYNC)
29+ if (ret < 0)
30+ goto done;
31+ else if (ret == LIBEVDEV_READ_STATUS_SUCCESS)
32+ handle_event(device, &event);
33+ else
34 {
35- ret = libevdev_next_event(device->dev, LIBEVDEV_READ_FLAG_SYNC,
36- &event);
37- }
38+ while (ret == LIBEVDEV_READ_STATUS_SYNC)
39+ {
40+ ret = libevdev_next_event(device->dev, LIBEVDEV_READ_FLAG_SYNC,
41+ &event);
42
43- if (!is_motion_event(&event))
44- handle_motion_events(device, timeval_to_msec(&event.time));
45+ if (ret < 0)
46+ goto done;
47
48- if (event.type < ARRAY_SIZE(event_handlers)
49- && event_handlers[event.type])
50- {
51- event_handlers[event.type](device, &event);
52+ handle_event(device, &event);
53+ }
54 }
55 }
56
57+ done:
58+ if (ret == -ENODEV)
59+ {
60+ wl_event_source_remove(device->source);
61+ device->source = NULL;
62+ }
63+
64 handle_motion_events(device, timeval_to_msec(&event.time));
65
66 return 1;