evdev: organize the code for processing events
Nothing was touched, just code moved around. Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
This commit is contained in:
committed by
Kristian Høgsberg
parent
9ebcf94b83
commit
8be003baba
+124
-98
@@ -43,105 +43,10 @@ struct evdev_input_device {
|
||||
int is_touchpad, old_x_value, old_y_value, reset_x_value, reset_y_value;
|
||||
};
|
||||
|
||||
static int
|
||||
evdev_input_device_data(int fd, uint32_t mask, void *data)
|
||||
static inline void
|
||||
evdev_process_key(struct evdev_input_device *device,
|
||||
struct input_event *e, int value, int time)
|
||||
{
|
||||
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;
|
||||
|
||||
/* 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;
|
||||
|
||||
/* FIXME: Make this configurable somehow. */
|
||||
const int touchpad_speed = 700;
|
||||
|
||||
ec = (struct wlsc_compositor *)
|
||||
device->master->base.input_device.compositor;
|
||||
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;
|
||||
|
||||
len = read(fd, &ev, sizeof ev);
|
||||
if (len < 0 || len % sizeof e[0] != 0) {
|
||||
/* FIXME: handle error... reopen device? */;
|
||||
return 1;
|
||||
}
|
||||
|
||||
e = ev;
|
||||
end = (void *) ev + len;
|
||||
for (e = ev; e < end; e++) {
|
||||
/* Get the signed value, earlier kernels had this as unsigned */
|
||||
value = e->value;
|
||||
time = e->time.tv_sec * 1000 + e->time.tv_usec / 1000;
|
||||
|
||||
switch (e->type) {
|
||||
case EV_REL:
|
||||
switch (e->code) {
|
||||
case REL_X:
|
||||
dx += value;
|
||||
break;
|
||||
|
||||
case REL_Y:
|
||||
dy += value;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case EV_ABS:
|
||||
if (device->is_touchpad) {
|
||||
switch (e->code) {
|
||||
case ABS_X:
|
||||
value -= device->min_x;
|
||||
if (device->reset_x_value)
|
||||
device->reset_x_value = 0;
|
||||
else {
|
||||
dx = (value - device->old_x_value) * touchpad_speed /
|
||||
(device->max_x - device->min_x);
|
||||
}
|
||||
device->old_x_value = value;
|
||||
break;
|
||||
case ABS_Y:
|
||||
value -= device->min_y;
|
||||
if (device->reset_y_value)
|
||||
device->reset_y_value = 0;
|
||||
else {
|
||||
dy = (value - device->old_y_value) * touchpad_speed /
|
||||
/* maybe use x size here to have the same scale? */
|
||||
(device->max_y - device->min_y);
|
||||
}
|
||||
device->old_y_value = value;
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
switch (e->code) {
|
||||
case ABS_X:
|
||||
absolute_event = device->tool;
|
||||
x = (value - device->min_x) * screen_width /
|
||||
(device->max_x - device->min_x);
|
||||
break;
|
||||
case ABS_Y:
|
||||
absolute_event = device->tool;
|
||||
y = (value - device->min_y) * screen_height /
|
||||
(device->max_y - device->min_y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case EV_KEY:
|
||||
if (value == 2)
|
||||
break;
|
||||
|
||||
switch (e->code) {
|
||||
case BTN_TOUCH:
|
||||
case BTN_TOOL_PEN:
|
||||
@@ -177,6 +82,127 @@ evdev_input_device_data(int fd, uint32_t mask, void *data)
|
||||
time, e->code, value);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
/* 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->code) {
|
||||
case ABS_X:
|
||||
*absolute_event = device->tool;
|
||||
*x = (value - device->min_x) * screen_width /
|
||||
(device->max_x - device->min_x);
|
||||
break;
|
||||
case ABS_Y:
|
||||
*absolute_event = device->tool;
|
||||
*y = (value - device->min_y) * screen_height /
|
||||
(device->max_y - device->min_y);
|
||||
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;
|
||||
|
||||
switch (e->code) {
|
||||
case ABS_X:
|
||||
value -= device->min_x;
|
||||
if (device->reset_x_value)
|
||||
device->reset_x_value = 0;
|
||||
else {
|
||||
*dx = (value - device->old_x_value) * touchpad_speed /
|
||||
(device->max_x - device->min_x);
|
||||
}
|
||||
device->old_x_value = value;
|
||||
break;
|
||||
case ABS_Y:
|
||||
value -= device->min_y;
|
||||
if (device->reset_y_value)
|
||||
device->reset_y_value = 0;
|
||||
else {
|
||||
*dy = (value - device->old_y_value) * touchpad_speed /
|
||||
/* maybe use x size here to have the same scale? */
|
||||
(device->max_y - device->min_y);
|
||||
}
|
||||
device->old_y_value = value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
evdev_process_relative_motion(struct input_event *e, int value, int *dx,
|
||||
int *dy)
|
||||
{
|
||||
switch (e->code) {
|
||||
case REL_X:
|
||||
*dx += value;
|
||||
break;
|
||||
case REL_Y:
|
||||
*dy += value;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
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, value, dx, dy, absolute_event;
|
||||
int x, y;
|
||||
uint32_t time;
|
||||
|
||||
ec = (struct wlsc_compositor *)
|
||||
device->master->base.input_device.compositor;
|
||||
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;
|
||||
|
||||
len = read(fd, &ev, sizeof ev);
|
||||
if (len < 0 || len % sizeof e[0] != 0) {
|
||||
/* FIXME: handle error... reopen device? */;
|
||||
return 1;
|
||||
}
|
||||
|
||||
e = ev;
|
||||
end = (void *) ev + len;
|
||||
for (e = ev; e < end; e++) {
|
||||
/* Get the signed value, earlier kernels had this as unsigned */
|
||||
value = e->value;
|
||||
time = e->time.tv_sec * 1000 + e->time.tv_usec / 1000;
|
||||
|
||||
switch (e->type) {
|
||||
case EV_REL:
|
||||
evdev_process_relative_motion(e, value, &dx, &dy);
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user