evdev: use a separate struct for abs information

Signed-off-by: Tiago Vignatti <tiago.vignatti@intel.com>
dev
Tiago Vignatti 13 years ago
parent 280b8a6a3b
commit a157fc11a9
  1. 52
      compositor/evdev.c

@ -44,8 +44,11 @@ struct evdev_input_device {
char *devnode; char *devnode;
int tool; int tool;
int fd; int fd;
int min_x, max_x, min_y, max_y; struct {
int is_touchpad, old_x_value, old_y_value, reset_x_value, reset_y_value; 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 static inline void
@ -67,8 +70,8 @@ evdev_process_key(struct evdev_input_device *device,
device->tool = e->value ? e->code : 0; device->tool = e->value ? e->code : 0;
if (device->is_touchpad) if (device->is_touchpad)
{ {
device->reset_x_value = 1; device->abs.reset_x = 1;
device->reset_y_value = 1; device->abs.reset_y = 1;
} }
break; break;
@ -107,13 +110,13 @@ evdev_process_absolute_motion(struct evdev_input_device *device,
switch (e->code) { switch (e->code) {
case ABS_X: case ABS_X:
*absolute_event = device->tool; *absolute_event = device->tool;
*x = (e->value - device->min_x) * screen_width / *x = (e->value - device->abs.min_x) * screen_width /
(device->max_x - device->min_x) + device->output->x; (device->abs.max_x - device->abs.min_x) + device->output->x;
break; break;
case ABS_Y: case ABS_Y:
*absolute_event = device->tool; *absolute_event = device->tool;
*y = (e->value - device->min_y) * screen_height / *y = (e->value - device->abs.min_y) * screen_height /
(device->max_y - device->min_y) + device->output->y; (device->abs.max_y - device->abs.min_y) + device->output->y;
break; break;
} }
} }
@ -127,25 +130,25 @@ evdev_process_absolute_motion_touchpad(struct evdev_input_device *device,
switch (e->code) { switch (e->code) {
case ABS_X: case ABS_X:
e->value -= device->min_x; e->value -= device->abs.min_x;
if (device->reset_x_value) if (device->abs.reset_x)
device->reset_x_value = 0; device->abs.reset_x = 0;
else { else {
*dx = (e->value - device->old_x_value) * touchpad_speed / *dx = (e->value - device->abs.old_x) * touchpad_speed /
(device->max_x - device->min_x); (device->abs.max_x - device->abs.min_x);
} }
device->old_x_value = e->value; device->abs.old_x = e->value;
break; break;
case ABS_Y: case ABS_Y:
e->value -= device->min_y; e->value -= device->abs.min_y;
if (device->reset_y_value) if (device->abs.reset_y)
device->reset_y_value = 0; device->abs.reset_y = 0;
else { 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? */ /* 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; break;
} }
} }
@ -287,17 +290,18 @@ evdev_configure_device(struct evdev_input_device *device)
ioctl(device->fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits); ioctl(device->fd, EVIOCGBIT(0, sizeof(ev_bits)), ev_bits);
if (TEST_BIT(ev_bits, EV_ABS)) { if (TEST_BIT(ev_bits, EV_ABS)) {
has_abs = 1; has_abs = 1;
ioctl(device->fd, EVIOCGBIT(EV_ABS, sizeof(abs_bits)), ioctl(device->fd, EVIOCGBIT(EV_ABS, sizeof(abs_bits)),
abs_bits); abs_bits);
if (TEST_BIT(abs_bits, ABS_X)) { if (TEST_BIT(abs_bits, ABS_X)) {
ioctl(device->fd, EVIOCGABS(ABS_X), &absinfo); ioctl(device->fd, EVIOCGABS(ABS_X), &absinfo);
device->min_x = absinfo.minimum; device->abs.min_x = absinfo.minimum;
device->max_x = absinfo.maximum; device->abs.max_x = absinfo.maximum;
} }
if (TEST_BIT(abs_bits, ABS_Y)) { if (TEST_BIT(abs_bits, ABS_Y)) {
ioctl(device->fd, EVIOCGABS(ABS_Y), &absinfo); ioctl(device->fd, EVIOCGABS(ABS_Y), &absinfo);
device->min_y = absinfo.minimum; device->abs.min_y = absinfo.minimum;
device->max_y = absinfo.maximum; device->abs.max_y = absinfo.maximum;
} }
} }
if (TEST_BIT(ev_bits, EV_KEY)) { if (TEST_BIT(ev_bits, EV_KEY)) {

Loading…
Cancel
Save