3 #include <linux/input.h>
7 #include <linux/input.h>
11 struct wl_input_device {
12 struct wl_object base;
13 struct wl_event_source *source;
14 struct wl_display *display;
20 static const struct wl_method input_device_methods[] = {
23 static const struct wl_interface input_device_interface = {
25 ARRAY_LENGTH(input_device_methods),
29 static void wl_input_device_data(int fd, uint32_t mask, void *data)
31 struct wl_input_device *device = data;
32 struct input_event ev[8], *e, *end;
33 int len, value, dx, dy, absolute_event;
39 len = read(fd, &ev, sizeof ev);
40 if (len < 0 || len % sizeof e[0] != 0) {
41 /* FIXME: handle error... reopen device? */;
46 end = (void *) ev + len;
47 for (e = ev; e < end; e++) {
48 /* Get the signed value, earlier kernels had this as unsigned */
84 case BTN_TOOL_AIRBRUSH:
88 device->tool = value ? e->code : 0;
92 wl_display_post_button_event(device->display,
93 &device->base, 0, value);
97 wl_display_post_button_event(device->display,
98 &device->base, 2, value);
102 wl_display_post_button_event(device->display,
103 &device->base, 1, value);
109 if (dx != 0 || dy != 0)
110 wl_display_post_relative_event(device->display,
111 &device->base, dx, dy);
112 if (absolute_event && device->tool)
113 wl_display_post_absolute_event(device->display,
115 device->x, device->y);
119 wl_input_device_create(struct wl_display *display,
120 const char *path, uint32_t id)
122 struct wl_input_device *device;
123 struct wl_event_loop *loop;
125 device = malloc(sizeof *device);
129 device->base.id = id;
130 device->base.interface = &input_device_interface;
131 device->display = display;
134 device->fd = open(path, O_RDONLY);
135 if (device->fd < 0) {
137 fprintf(stderr, "couldn't create pointer for %s: %m\n", path);
141 loop = wl_display_get_event_loop(display);
142 device->source = wl_event_loop_add_fd(loop, device->fd,
144 wl_input_device_data, device);
145 if (device->source == NULL) {
151 return &device->base;