From e7b5b41e9378791459d1e5b5016a6868ddf49ae1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristian=20H=C3=B8gsberg?= Date: Thu, 1 Sep 2011 13:25:50 -0400 Subject: [PATCH] evdev: Associate touchscreen devices with output up front This isn't going to change over time, so just tracking it in the evdev device is a little easier. Also, we need to adjust for the output position when transforming the device events to screen space. --- compositor/evdev.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/compositor/evdev.c b/compositor/evdev.c index 113eded9..f0cdf30b 100644 --- a/compositor/evdev.c +++ b/compositor/evdev.c @@ -36,6 +36,7 @@ struct evdev_input { struct evdev_input_device { struct evdev_input *master; struct wl_event_source *source; + struct wlsc_output *output; int tool, new_x, new_y; int base_x, base_y; int fd; @@ -91,23 +92,21 @@ evdev_process_key(struct evdev_input_device *device, static inline void evdev_process_absolute_motion(struct evdev_input_device *device, struct input_event *e, int value, int *x, int *y, - int *absolute_event, struct wlsc_compositor *ec) + int *absolute_event) { - const int screen_width = container_of(ec->output_list.prev, - struct wlsc_output, link)->current->width; - const int screen_height = container_of(ec->output_list.prev, - struct wlsc_output, link)->current->height; + const int screen_width = device->output->current->width; + const int screen_height = device->output->current->height; switch (e->code) { case ABS_X: *absolute_event = device->tool; *x = (value - device->min_x) * screen_width / - (device->max_x - device->min_x); + (device->max_x - device->min_x) + device->output->x; break; case ABS_Y: *absolute_event = device->tool; *y = (value - device->min_y) * screen_height / - (device->max_y - device->min_y); + (device->max_y - device->min_y) + device->output->y; break; } } @@ -202,7 +201,7 @@ evdev_input_device_data(int fd, uint32_t mask, void *data) e, value, &dx, &dy); else evdev_process_absolute_motion(device, e, value, - &x, &y, &absolute_event, ec); + &x, &y, &absolute_event); break; case EV_KEY: if (value == 2) @@ -283,11 +282,16 @@ evdev_input_device_create(struct evdev_input *master, { struct evdev_input_device *device; struct wl_event_loop *loop; + struct wlsc_compositor *ec; device = malloc(sizeof *device); if (device == NULL) return NULL; + ec = (struct wlsc_compositor *) master->base.input_device.compositor; + device->output = + container_of(ec->output_list.next, struct wlsc_output, link); + device->tool = 1; device->new_x = 1; device->new_y = 1;