From 280b8a6a3b1fe3cd300997c1a757973e03b0d672 Mon Sep 17 00:00:00 2001 From: Tiago Vignatti Date: Mon, 21 Nov 2011 14:55:23 +0200 Subject: tty: fix command line parsing revert typo from evdev commit 8b568806. Signed-off-by: Tiago Vignatti --- compositor/tty.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compositor/tty.c b/compositor/tty.c index 4989500..5ed921c 100644 --- a/compositor/tty.c +++ b/compositor/tty.c @@ -103,7 +103,7 @@ tty_create(struct wlsc_compositor *compositor, tty_vt_func_t vt_func, if (tty == NULL) return NULL; - snprintf(filename, sizeof filename, "/dev/tty0"); + snprintf(filename, sizeof filename, "/dev/tty%d", tty_nr); fprintf(stderr, "compositor: using %s\n", filename); memset(tty, 0, sizeof *tty); -- cgit v1.2.3 From a157fc11a9ce3788c3c7530959f85fda4a603f4d Mon Sep 17 00:00:00 2001 From: Tiago Vignatti Date: Mon, 21 Nov 2011 16:39:55 +0200 Subject: evdev: use a separate struct for abs information Signed-off-by: Tiago Vignatti --- compositor/evdev.c | 52 ++++++++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/compositor/evdev.c b/compositor/evdev.c index 5138c09..48e8d7c 100644 --- a/compositor/evdev.c +++ b/compositor/evdev.c @@ -44,8 +44,11 @@ struct evdev_input_device { char *devnode; int tool; int fd; - int min_x, max_x, min_y, max_y; - int is_touchpad, old_x_value, old_y_value, reset_x_value, reset_y_value; + struct { + int min_x, max_x, min_y, max_y; + int old_x, old_y, reset_x, reset_y; + } abs; + int is_touchpad; }; static inline void @@ -67,8 +70,8 @@ evdev_process_key(struct evdev_input_device *device, device->tool = e->value ? e->code : 0; if (device->is_touchpad) { - device->reset_x_value = 1; - device->reset_y_value = 1; + device->abs.reset_x = 1; + device->abs.reset_y = 1; } break; @@ -107,13 +110,13 @@ evdev_process_absolute_motion(struct evdev_input_device *device, switch (e->code) { case ABS_X: *absolute_event = device->tool; - *x = (e->value - device->min_x) * screen_width / - (device->max_x - device->min_x) + device->output->x; + *x = (e->value - device->abs.min_x) * screen_width / + (device->abs.max_x - device->abs.min_x) + device->output->x; break; case ABS_Y: *absolute_event = device->tool; - *y = (e->value - device->min_y) * screen_height / - (device->max_y - device->min_y) + device->output->y; + *y = (e->value - device->abs.min_y) * screen_height / + (device->abs.max_y - device->abs.min_y) + device->output->y; break; } } @@ -127,25 +130,25 @@ evdev_process_absolute_motion_touchpad(struct evdev_input_device *device, switch (e->code) { case ABS_X: - e->value -= device->min_x; - if (device->reset_x_value) - device->reset_x_value = 0; + e->value -= device->abs.min_x; + if (device->abs.reset_x) + device->abs.reset_x = 0; else { - *dx = (e->value - device->old_x_value) * touchpad_speed / - (device->max_x - device->min_x); + *dx = (e->value - device->abs.old_x) * touchpad_speed / + (device->abs.max_x - device->abs.min_x); } - device->old_x_value = e->value; + device->abs.old_x = e->value; break; case ABS_Y: - e->value -= device->min_y; - if (device->reset_y_value) - device->reset_y_value = 0; + e->value -= device->abs.min_y; + if (device->abs.reset_y) + device->abs.reset_y = 0; else { - *dy = (e->value - device->old_y_value) * touchpad_speed / + *dy = (e->value - device->abs.old_y) * touchpad_speed / /* maybe use x size here to have the same scale? */ - (device->max_y - device->min_y); + (device->abs.max_y - device->abs.min_y); } - device->old_y_value = e->value; + device->abs.old_y = e->value; break; } } @@ -287,17 +290,18 @@ evdev_configure_device(struct evdev_input_device *device) ioctl(device->fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits); if (TEST_BIT(ev_bits, EV_ABS)) { has_abs = 1; + ioctl(device->fd, EVIOCGBIT(EV_ABS, sizeof(abs_bits)), abs_bits); if (TEST_BIT(abs_bits, ABS_X)) { ioctl(device->fd, EVIOCGABS(ABS_X), &absinfo); - device->min_x = absinfo.minimum; - device->max_x = absinfo.maximum; + device->abs.min_x = absinfo.minimum; + device->abs.max_x = absinfo.maximum; } if (TEST_BIT(abs_bits, ABS_Y)) { ioctl(device->fd, EVIOCGABS(ABS_Y), &absinfo); - device->min_y = absinfo.minimum; - device->max_y = absinfo.maximum; + device->abs.min_y = absinfo.minimum; + device->abs.max_y = absinfo.maximum; } } if (TEST_BIT(ev_bits, EV_KEY)) { -- cgit v1.2.3 From a52b2e4b2042510abc0e6accf455cdd46ff3ff31 Mon Sep 17 00:00:00 2001 From: Tiago Vignatti Date: Mon, 21 Nov 2011 17:40:30 +0200 Subject: evdev: use a separate structure to denote accumulated motion events Signed-off-by: Tiago Vignatti --- compositor/evdev.c | 93 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 56 insertions(+), 37 deletions(-) diff --git a/compositor/evdev.c b/compositor/evdev.c index 48e8d7c..2dcfd5e 100644 --- a/compositor/evdev.c +++ b/compositor/evdev.c @@ -51,6 +51,16 @@ struct evdev_input_device { int is_touchpad; }; +/* event type flags */ +#define EVDEV_ABSOLUTE_MOTION (1 << 0) +#define EVDEV_RELATIVE_MOTION (1 << 1) + +struct evdev_motion_accumulator { + int x, y; + int dx, dy; + int type; /* event type flags */ +}; + static inline void evdev_process_key(struct evdev_input_device *device, struct input_event *e, int time) @@ -101,29 +111,30 @@ 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 *x, int *y, - int *absolute_event) + struct input_event *e, struct evdev_motion_accumulator *accum) { 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 = (e->value - device->abs.min_x) * screen_width / - (device->abs.max_x - device->abs.min_x) + device->output->x; + accum->x = (e->value - device->abs.min_x) * screen_width / + (device->abs.max_x - device->abs.min_x) + + device->output->x; + accum->type = EVDEV_ABSOLUTE_MOTION; break; case ABS_Y: - *absolute_event = device->tool; - *y = (e->value - device->abs.min_y) * screen_height / - (device->abs.max_y - device->abs.min_y) + device->output->y; + accum->y = (e->value - device->abs.min_y) * screen_height / + (device->abs.max_y - device->abs.min_y) + + device->output->y; + accum->type = EVDEV_ABSOLUTE_MOTION; break; } } static inline void evdev_process_absolute_motion_touchpad(struct evdev_input_device *device, - struct input_event *e, int *dx, int *dy) + struct input_event *e, struct evdev_motion_accumulator *accum) { /* FIXME: Make this configurable somehow. */ const int touchpad_speed = 700; @@ -134,34 +145,41 @@ evdev_process_absolute_motion_touchpad(struct evdev_input_device *device, if (device->abs.reset_x) device->abs.reset_x = 0; else { - *dx = (e->value - device->abs.old_x) * touchpad_speed / + accum->dx = (e->value - device->abs.old_x) * + touchpad_speed / (device->abs.max_x - device->abs.min_x); } device->abs.old_x = e->value; + accum->type = EVDEV_RELATIVE_MOTION; break; case ABS_Y: e->value -= device->abs.min_y; if (device->abs.reset_y) device->abs.reset_y = 0; else { - *dy = (e->value - device->abs.old_y) * touchpad_speed / + accum->dy = (e->value - device->abs.old_y) * + touchpad_speed / /* maybe use x size here to have the same scale? */ (device->abs.max_y - device->abs.min_y); } device->abs.old_y = e->value; + accum->type = EVDEV_RELATIVE_MOTION; break; } } static inline void -evdev_process_relative_motion(struct input_event *e, int *dx, int *dy) +evdev_process_relative_motion(struct input_event *e, + struct evdev_motion_accumulator *accum) { switch (e->code) { case REL_X: - *dx += e->value; + accum->dx += e->value; + accum->type = EVDEV_RELATIVE_MOTION; break; case REL_Y: - *dy += e->value; + accum->dy += e->value; + accum->type = EVDEV_RELATIVE_MOTION; break; } } @@ -188,13 +206,14 @@ is_motion_event(struct input_event *e) } static void -evdev_flush_motion(struct wl_input_device *device, uint32_t time, int x, int y, - int dx, int dy, int absolute_event) +evdev_flush_motion(struct wl_input_device *device, uint32_t time, + struct evdev_motion_accumulator accum) { - if (dx != 0 || dy != 0) - notify_motion(device, time, x + dx, y + dy); - if (absolute_event) - notify_motion(device, time, x, y); + if (accum.type == EVDEV_RELATIVE_MOTION) + notify_motion(device, time, accum.x + accum.dx, + accum.y + accum.dy); + if (accum.type == EVDEV_ABSOLUTE_MOTION) + notify_motion(device, time, accum.x, accum.y); } static int @@ -203,8 +222,8 @@ evdev_input_device_data(int fd, uint32_t mask, void *data) struct wlsc_compositor *ec; struct evdev_input_device *device = data; struct input_event ev[8], *e, *end; - int len, dx, dy, absolute_event; - int x, y; + int len; + struct evdev_motion_accumulator accumulator; uint32_t time; ec = (struct wlsc_compositor *) @@ -212,11 +231,11 @@ evdev_input_device_data(int fd, uint32_t mask, void *data) if (!ec->focus) return 1; - dx = 0; - dy = 0; - absolute_event = 0; - x = device->master->base.input_device.x; - y = device->master->base.input_device.y; + accumulator.dx = 0; + accumulator.dy = 0; + accumulator.type = 0; + accumulator.x = device->master->base.input_device.x; + accumulator.y = device->master->base.input_device.y; len = read(fd, &ev, sizeof ev); if (len < 0 || len % sizeof e[0] != 0) { @@ -234,23 +253,23 @@ evdev_input_device_data(int fd, uint32_t mask, void *data) * events and send as a bunch */ if (!is_motion_event(e)) { evdev_flush_motion(&device->master->base.input_device, - time, x, y, dx, dy, absolute_event); - dx = 0; - dy = 0; - absolute_event = 0; + time, accumulator); + accumulator.dx = 0; + accumulator.dy = 0; + accumulator.type = 0; } - + switch (e->type) { case EV_REL: - evdev_process_relative_motion(e, &dx, &dy); + evdev_process_relative_motion(e, &accumulator); break; case EV_ABS: if (device->is_touchpad) evdev_process_absolute_motion_touchpad(device, - e, &dx, &dy); + e, &accumulator); else evdev_process_absolute_motion(device, e, - &x, &y, &absolute_event); + &accumulator); break; case EV_KEY: evdev_process_key(device, e, time); @@ -258,8 +277,8 @@ evdev_input_device_data(int fd, uint32_t mask, void *data) } } - evdev_flush_motion(&device->master->base.input_device, time, x, y, dx, - dy, absolute_event); + evdev_flush_motion(&device->master->base.input_device, time, + accumulator); return 1; } -- cgit v1.2.3 From 80885e16b314ffeb33201f602d1eef1a66bc957a Mon Sep 17 00:00:00 2001 From: Tiago Vignatti Date: Mon, 21 Nov 2011 17:59:31 +0200 Subject: evdev: reset accumulator inside evdev_flush_motion Signed-off-by: Tiago Vignatti --- compositor/evdev.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/compositor/evdev.c b/compositor/evdev.c index 2dcfd5e..e557abb 100644 --- a/compositor/evdev.c +++ b/compositor/evdev.c @@ -207,13 +207,17 @@ is_motion_event(struct input_event *e) static void evdev_flush_motion(struct wl_input_device *device, uint32_t time, - struct evdev_motion_accumulator accum) + struct evdev_motion_accumulator *accum) { - if (accum.type == EVDEV_RELATIVE_MOTION) - notify_motion(device, time, accum.x + accum.dx, - accum.y + accum.dy); - if (accum.type == EVDEV_ABSOLUTE_MOTION) - notify_motion(device, time, accum.x, accum.y); + if (accum->type == EVDEV_RELATIVE_MOTION) { + notify_motion(device, time, accum->x + accum->dx, + accum->y + accum->dy); + accum->dx = accum->dy = 0; + } + if (accum->type == EVDEV_ABSOLUTE_MOTION) + notify_motion(device, time, accum->x, accum->y); + + accum->type = 0; } static int @@ -231,9 +235,7 @@ evdev_input_device_data(int fd, uint32_t mask, void *data) if (!ec->focus) return 1; - accumulator.dx = 0; - accumulator.dy = 0; - accumulator.type = 0; + memset(&accumulator, 0, sizeof accumulator); accumulator.x = device->master->base.input_device.x; accumulator.y = device->master->base.input_device.y; @@ -251,14 +253,9 @@ evdev_input_device_data(int fd, uint32_t mask, void *data) /* we try to minimize the amount of notifications to be * forwarded to the compositor, so we accumulate motion * events and send as a bunch */ - if (!is_motion_event(e)) { + if (!is_motion_event(e)) evdev_flush_motion(&device->master->base.input_device, - time, accumulator); - accumulator.dx = 0; - accumulator.dy = 0; - accumulator.type = 0; - } - + time, &accumulator); switch (e->type) { case EV_REL: evdev_process_relative_motion(e, &accumulator); @@ -278,7 +275,7 @@ evdev_input_device_data(int fd, uint32_t mask, void *data) } evdev_flush_motion(&device->master->base.input_device, time, - accumulator); + &accumulator); return 1; } -- cgit v1.2.3 From 5c900ce08ddf2a34c6b69de4af1c1223f366c03a Mon Sep 17 00:00:00 2001 From: Tiago Vignatti Date: Mon, 21 Nov 2011 18:29:40 +0200 Subject: evdev: remove useless field from device structure We'll want to enhance later the driver regarding the tool being used, but for now just remove unused bits. Signed-off-by: Tiago Vignatti --- compositor/evdev.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/compositor/evdev.c b/compositor/evdev.c index e557abb..96fb0cd 100644 --- a/compositor/evdev.c +++ b/compositor/evdev.c @@ -42,7 +42,6 @@ struct evdev_input_device { struct wl_event_source *source; struct wlsc_output *output; char *devnode; - int tool; int fd; struct { int min_x, max_x, min_y, max_y; @@ -77,7 +76,6 @@ evdev_process_key(struct evdev_input_device *device, case BTN_TOOL_FINGER: case BTN_TOOL_MOUSE: case BTN_TOOL_LENS: - device->tool = e->value ? e->code : 0; if (device->is_touchpad) { device->abs.reset_x = 1; @@ -354,7 +352,6 @@ evdev_input_device_create(struct evdev_input *master, device->output = container_of(ec->output_list.next, struct wlsc_output, link); - device->tool = 1; device->master = master; device->is_touchpad = 0; device->devnode = strdup(path); -- cgit v1.2.3 From f547bd36e67c85de8aaf1be6b704f153a15b36d6 Mon Sep 17 00:00:00 2001 From: Tiago Vignatti Date: Tue, 22 Nov 2011 12:05:22 +0200 Subject: evdev: fetch absolute coordinates inside flush_motion only Signed-off-by: Tiago Vignatti --- compositor/evdev.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/compositor/evdev.c b/compositor/evdev.c index 96fb0cd..06913cf 100644 --- a/compositor/evdev.c +++ b/compositor/evdev.c @@ -208,8 +208,9 @@ evdev_flush_motion(struct wl_input_device *device, uint32_t time, struct evdev_motion_accumulator *accum) { if (accum->type == EVDEV_RELATIVE_MOTION) { - notify_motion(device, time, accum->x + accum->dx, - accum->y + accum->dy); + accum->dx += device->x; + accum->dy += device->y; + notify_motion(device, time, accum->dx, accum->dy); accum->dx = accum->dy = 0; } if (accum->type == EVDEV_ABSOLUTE_MOTION) @@ -233,16 +234,14 @@ evdev_input_device_data(int fd, uint32_t mask, void *data) if (!ec->focus) return 1; - memset(&accumulator, 0, sizeof accumulator); - accumulator.x = device->master->base.input_device.x; - accumulator.y = device->master->base.input_device.y; - len = read(fd, &ev, sizeof ev); if (len < 0 || len % sizeof e[0] != 0) { /* FIXME: call device_removed when errno is ENODEV. */; return 1; } + memset(&accumulator, 0, sizeof accumulator); + e = ev; end = (void *) ev + len; for (e = ev; e < end; e++) { -- cgit v1.2.3