mirror of
https://gitlab.freedesktop.org/libinput/libinput.git
synced 2026-05-09 05:58:01 +02:00
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:
parent
99476b1a69
commit
76dc338535
1 changed files with 118 additions and 92 deletions
|
|
@ -43,6 +43,116 @@ 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 inline void
|
||||||
|
evdev_process_key(struct evdev_input_device *device,
|
||||||
|
struct input_event *e, int value, int time)
|
||||||
|
{
|
||||||
|
switch (e->code) {
|
||||||
|
case BTN_TOUCH:
|
||||||
|
case BTN_TOOL_PEN:
|
||||||
|
case BTN_TOOL_RUBBER:
|
||||||
|
case BTN_TOOL_BRUSH:
|
||||||
|
case BTN_TOOL_PENCIL:
|
||||||
|
case BTN_TOOL_AIRBRUSH:
|
||||||
|
case BTN_TOOL_FINGER:
|
||||||
|
case BTN_TOOL_MOUSE:
|
||||||
|
case BTN_TOOL_LENS:
|
||||||
|
device->tool = value ? e->code : 0;
|
||||||
|
if (device->is_touchpad)
|
||||||
|
{
|
||||||
|
device->reset_x_value = 1;
|
||||||
|
device->reset_y_value = 1;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BTN_LEFT:
|
||||||
|
case BTN_RIGHT:
|
||||||
|
case BTN_MIDDLE:
|
||||||
|
case BTN_SIDE:
|
||||||
|
case BTN_EXTRA:
|
||||||
|
case BTN_FORWARD:
|
||||||
|
case BTN_BACK:
|
||||||
|
case BTN_TASK:
|
||||||
|
notify_button(&device->master->base.input_device,
|
||||||
|
time, e->code, value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
notify_key(&device->master->base.input_device,
|
||||||
|
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
|
static int
|
||||||
evdev_input_device_data(int fd, uint32_t mask, void *data)
|
evdev_input_device_data(int fd, uint32_t mask, void *data)
|
||||||
{
|
{
|
||||||
|
|
@ -53,13 +163,6 @@ evdev_input_device_data(int fd, uint32_t mask, void *data)
|
||||||
int x, y;
|
int x, y;
|
||||||
uint32_t time;
|
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 *)
|
ec = (struct wlsc_compositor *)
|
||||||
device->master->base.input_device.compositor;
|
device->master->base.input_device.compositor;
|
||||||
if (!ec->focus)
|
if (!ec->focus)
|
||||||
|
|
@ -86,97 +189,20 @@ evdev_input_device_data(int fd, uint32_t mask, void *data)
|
||||||
|
|
||||||
switch (e->type) {
|
switch (e->type) {
|
||||||
case EV_REL:
|
case EV_REL:
|
||||||
switch (e->code) {
|
evdev_process_relative_motion(e, value, &dx, &dy);
|
||||||
case REL_X:
|
|
||||||
dx += value;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case REL_Y:
|
|
||||||
dy += value;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case EV_ABS:
|
case EV_ABS:
|
||||||
if (device->is_touchpad) {
|
if (device->is_touchpad)
|
||||||
switch (e->code) {
|
evdev_process_absolute_motion_touchpad(device,
|
||||||
case ABS_X:
|
e, value, &dx, &dy);
|
||||||
value -= device->min_x;
|
else
|
||||||
if (device->reset_x_value)
|
evdev_process_absolute_motion(device, e, value,
|
||||||
device->reset_x_value = 0;
|
&x, &y, &absolute_event);
|
||||||
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;
|
break;
|
||||||
|
|
||||||
case EV_KEY:
|
case EV_KEY:
|
||||||
if (value == 2)
|
if (value == 2)
|
||||||
break;
|
break;
|
||||||
|
evdev_process_key(device, e, value, time);
|
||||||
switch (e->code) {
|
|
||||||
case BTN_TOUCH:
|
|
||||||
case BTN_TOOL_PEN:
|
|
||||||
case BTN_TOOL_RUBBER:
|
|
||||||
case BTN_TOOL_BRUSH:
|
|
||||||
case BTN_TOOL_PENCIL:
|
|
||||||
case BTN_TOOL_AIRBRUSH:
|
|
||||||
case BTN_TOOL_FINGER:
|
|
||||||
case BTN_TOOL_MOUSE:
|
|
||||||
case BTN_TOOL_LENS:
|
|
||||||
device->tool = value ? e->code : 0;
|
|
||||||
if (device->is_touchpad)
|
|
||||||
{
|
|
||||||
device->reset_x_value = 1;
|
|
||||||
device->reset_y_value = 1;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BTN_LEFT:
|
|
||||||
case BTN_RIGHT:
|
|
||||||
case BTN_MIDDLE:
|
|
||||||
case BTN_SIDE:
|
|
||||||
case BTN_EXTRA:
|
|
||||||
case BTN_FORWARD:
|
|
||||||
case BTN_BACK:
|
|
||||||
case BTN_TASK:
|
|
||||||
notify_button(&device->master->base.input_device,
|
|
||||||
time, e->code, value);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
notify_key(&device->master->base.input_device,
|
|
||||||
time, e->code, value);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue