2 * Copyright © 2008 Kristian Høgsberg
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software Foundation,
16 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 #include <linux/input.h>
25 #include <linux/input.h>
28 #include "wayland-system-compositor.h"
30 struct evdev_input_device {
31 struct wlsc_input_device *device;
32 struct wl_event_source *source;
33 int tool, new_x, new_y;
38 static void evdev_input_device_data(int fd, uint32_t mask, void *data)
40 struct evdev_input_device *device = data;
41 struct input_event ev[8], *e, *end;
42 int len, value, dx, dy, absolute_event;
48 wlsc_device_get_position(device->device, &x, &y);
50 len = read(fd, &ev, sizeof ev);
51 if (len < 0 || len % sizeof e[0] != 0) {
52 /* FIXME: handle error... reopen device? */;
57 end = (void *) ev + len;
58 for (e = ev; e < end; e++) {
59 /* Get the signed value, earlier kernels had this as unsigned */
80 device->base_x = x - value;
83 x = device->base_x + value;
87 device->base_y = y - value;
90 y = device->base_y + value;
102 case BTN_TOOL_RUBBER:
104 case BTN_TOOL_PENCIL:
105 case BTN_TOOL_AIRBRUSH:
106 case BTN_TOOL_FINGER:
109 if (device->tool == 0 && value) {
113 device->tool = value ? e->code : 0;
124 notify_button(device->device, e->code, value);
128 notify_key(device->device, e->code, value);
134 if (dx != 0 || dy != 0)
135 notify_motion(device->device, x + dx, y + dy);
136 if (absolute_event && device->tool)
137 notify_motion(device->device, x, y);
140 struct evdev_input_device *
141 evdev_input_device_create(struct wlsc_input_device *master,
142 struct wl_display *display, const char *path)
144 struct evdev_input_device *device;
145 struct wl_event_loop *loop;
147 device = malloc(sizeof *device);
154 device->device = master;
156 device->fd = open(path, O_RDONLY);
157 if (device->fd < 0) {
159 fprintf(stderr, "couldn't create pointer for %s: %m\n", path);
163 loop = wl_display_get_event_loop(display);
164 device->source = wl_event_loop_add_fd(loop, device->fd,
166 evdev_input_device_data, device);
167 if (device->source == NULL) {