evdev: organize the code for processing events

Nothing was touched, just code moved around.

Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
dev
Tiago Vignatti 14 years ago committed by Kristian Høgsberg
parent 9ebcf94b83
commit 8be003baba
  1. 210
      compositor/evdev.c

@ -43,69 +43,84 @@ struct evdev_input_device {
int is_touchpad, old_x_value, old_y_value, reset_x_value, reset_y_value; int is_touchpad, old_x_value, old_y_value, reset_x_value, reset_y_value;
}; };
static int static inline void
evdev_input_device_data(int fd, uint32_t mask, void *data) evdev_process_key(struct evdev_input_device *device,
struct input_event *e, int value, int time)
{ {
struct wlsc_compositor *ec; switch (e->code) {
struct evdev_input_device *device = data; case BTN_TOUCH:
struct input_event ev[8], *e, *end; case BTN_TOOL_PEN:
int len, value, dx, dy, absolute_event; case BTN_TOOL_RUBBER:
int x, y; case BTN_TOOL_BRUSH:
uint32_t time; case BTN_TOOL_PENCIL:
case BTN_TOOL_AIRBRUSH:
/* FIXME: Obviously we need to not hardcode these here, but case BTN_TOOL_FINGER:
* instead get the values from the output it's associated with. */ case BTN_TOOL_MOUSE:
const int screen_width = 1024, screen_height = 600; case BTN_TOOL_LENS:
device->tool = value ? e->code : 0;
/* FIXME: Make this configurable somehow. */ if (device->is_touchpad)
const int touchpad_speed = 700; {
device->reset_x_value = 1;
ec = (struct wlsc_compositor *) device->reset_y_value = 1;
device->master->base.input_device.compositor; }
if (!ec->focus) break;
return 1;
dx = 0; case BTN_LEFT:
dy = 0; case BTN_RIGHT:
absolute_event = 0; case BTN_MIDDLE:
x = device->master->base.input_device.x; case BTN_SIDE:
y = device->master->base.input_device.y; case BTN_EXTRA:
case BTN_FORWARD:
case BTN_BACK:
case BTN_TASK:
notify_button(&device->master->base.input_device,
time, e->code, value);
break;
len = read(fd, &ev, sizeof ev); default:
if (len < 0 || len % sizeof e[0] != 0) { notify_key(&device->master->base.input_device,
/* FIXME: handle error... reopen device? */; time, e->code, value);
return 1; break;
} }
}
e = ev; static inline void
end = (void *) ev + len; evdev_process_absolute_motion(struct evdev_input_device *device,
for (e = ev; e < end; e++) { struct input_event *e, int value, int *x, int *y,
/* Get the signed value, earlier kernels had this as unsigned */ int *absolute_event)
value = e->value; {
time = e->time.tv_sec * 1000 + e->time.tv_usec / 1000; /* FIXME: Obviously we need to not hardcode these here, but
* instead get the values from the output it's associated with. */
const int screen_width = 1024, screen_height = 600;
switch (e->type) {
case EV_REL:
switch (e->code) { switch (e->code) {
case REL_X: case ABS_X:
dx += value; *absolute_event = device->tool;
*x = (value - device->min_x) * screen_width /
(device->max_x - device->min_x);
break; break;
case ABS_Y:
case REL_Y: *absolute_event = device->tool;
dy += value; *y = (value - device->min_y) * screen_height /
(device->max_y - device->min_y);
break; break;
} }
break; }
static inline void
evdev_process_absolute_motion_touchpad(struct evdev_input_device *device,
struct input_event *e, int value, int *dx, int *dy)
{
/* FIXME: Make this configurable somehow. */
const int touchpad_speed = 700;
case EV_ABS:
if (device->is_touchpad) {
switch (e->code) { switch (e->code) {
case ABS_X: case ABS_X:
value -= device->min_x; value -= device->min_x;
if (device->reset_x_value) if (device->reset_x_value)
device->reset_x_value = 0; device->reset_x_value = 0;
else { else {
dx = (value - device->old_x_value) * touchpad_speed / *dx = (value - device->old_x_value) * touchpad_speed /
(device->max_x - device->min_x); (device->max_x - device->min_x);
} }
device->old_x_value = value; device->old_x_value = value;
@ -115,68 +130,79 @@ evdev_input_device_data(int fd, uint32_t mask, void *data)
if (device->reset_y_value) if (device->reset_y_value)
device->reset_y_value = 0; device->reset_y_value = 0;
else { else {
dy = (value - device->old_y_value) * touchpad_speed / *dy = (value - device->old_y_value) * touchpad_speed /
/* maybe use x size here to have the same scale? */ /* maybe use x size here to have the same scale? */
(device->max_y - device->min_y); (device->max_y - device->min_y);
} }
device->old_y_value = value; device->old_y_value = value;
break; break;
} }
} else { }
static inline void
evdev_process_relative_motion(struct input_event *e, int value, int *dx,
int *dy)
{
switch (e->code) { switch (e->code) {
case ABS_X: case REL_X:
absolute_event = device->tool; *dx += value;
x = (value - device->min_x) * screen_width /
(device->max_x - device->min_x);
break; break;
case ABS_Y: case REL_Y:
absolute_event = device->tool; *dy += value;
y = (value - device->min_y) * screen_height /
(device->max_y - device->min_y);
break; break;
} }
} }
break;
case EV_KEY: static int
if (value == 2) evdev_input_device_data(int fd, uint32_t mask, void *data)
break; {
struct wlsc_compositor *ec;
struct evdev_input_device *device = data;
struct input_event ev[8], *e, *end;
int len, value, dx, dy, absolute_event;
int x, y;
uint32_t time;
switch (e->code) { ec = (struct wlsc_compositor *)
case BTN_TOUCH: device->master->base.input_device.compositor;
case BTN_TOOL_PEN: if (!ec->focus)
case BTN_TOOL_RUBBER: return 1;
case BTN_TOOL_BRUSH:
case BTN_TOOL_PENCIL: dx = 0;
case BTN_TOOL_AIRBRUSH: dy = 0;
case BTN_TOOL_FINGER: absolute_event = 0;
case BTN_TOOL_MOUSE: x = device->master->base.input_device.x;
case BTN_TOOL_LENS: y = device->master->base.input_device.y;
device->tool = value ? e->code : 0;
if (device->is_touchpad) len = read(fd, &ev, sizeof ev);
{ if (len < 0 || len % sizeof e[0] != 0) {
device->reset_x_value = 1; /* FIXME: handle error... reopen device? */;
device->reset_y_value = 1; return 1;
} }
break;
case BTN_LEFT: e = ev;
case BTN_RIGHT: end = (void *) ev + len;
case BTN_MIDDLE: for (e = ev; e < end; e++) {
case BTN_SIDE: /* Get the signed value, earlier kernels had this as unsigned */
case BTN_EXTRA: value = e->value;
case BTN_FORWARD: time = e->time.tv_sec * 1000 + e->time.tv_usec / 1000;
case BTN_BACK:
case BTN_TASK:
notify_button(&device->master->base.input_device,
time, e->code, value);
break;
default: switch (e->type) {
notify_key(&device->master->base.input_device, case EV_REL:
time, e->code, value); evdev_process_relative_motion(e, value, &dx, &dy);
break; break;
} case EV_ABS:
if (device->is_touchpad)
evdev_process_absolute_motion_touchpad(device,
e, value, &dx, &dy);
else
evdev_process_absolute_motion(device, e, value,
&x, &y, &absolute_event);
break;
case EV_KEY:
if (value == 2)
break;
evdev_process_key(device, e, value, time);
} }
} }

Loading…
Cancel
Save