evdev: implement horizontal scrolling

If the kernel reports REL_HWHELL, convert it to horizontal
scroll events.
Also reorganize a bit the recognition for the other event
enums.

https://bugzilla.gnome.org/show_bug.cgi?id=706494
This commit is contained in:
Giovanni Campagna 2013-09-06 17:54:59 +02:00
parent d882366d11
commit 5e005b4298

View File

@ -330,9 +330,10 @@ notify_relative_motion (ClutterEventSource *source,
} }
static void static void
notify_scroll (ClutterEventSource *source, notify_scroll (ClutterEventSource *source,
guint32 time_, guint32 time_,
gint32 value) gint32 value,
ClutterOrientation orientation)
{ {
ClutterInputDevice *input_device = (ClutterInputDevice *) source->device; ClutterInputDevice *input_device = (ClutterInputDevice *) source->device;
ClutterDeviceManagerEvdev *manager_evdev; ClutterDeviceManagerEvdev *manager_evdev;
@ -354,7 +355,10 @@ notify_scroll (ClutterEventSource *source,
event->scroll.stage = CLUTTER_STAGE (stage); event->scroll.stage = CLUTTER_STAGE (stage);
event->scroll.device = manager_evdev->priv->core_pointer; event->scroll.device = manager_evdev->priv->core_pointer;
_clutter_xkb_translate_state (event, manager_evdev->priv->xkb, manager_evdev->priv->button_state); _clutter_xkb_translate_state (event, manager_evdev->priv->xkb, manager_evdev->priv->button_state);
event->scroll.direction = value < 0 ? CLUTTER_SCROLL_DOWN : CLUTTER_SCROLL_UP; if (orientation == CLUTTER_ORIENTATION_VERTICAL)
event->scroll.direction = value < 0 ? CLUTTER_SCROLL_DOWN : CLUTTER_SCROLL_UP;
else
event->scroll.direction = value < 0 ? CLUTTER_SCROLL_LEFT : CLUTTER_SCROLL_RIGHT;
clutter_input_device_get_coords (manager_evdev->priv->core_pointer, NULL, &point); clutter_input_device_get_coords (manager_evdev->priv->core_pointer, NULL, &point);
event->scroll.x = point.x; event->scroll.x = point.x;
event->scroll.y = point.y; event->scroll.y = point.y;
@ -454,47 +458,21 @@ dispatch_one_event (ClutterEventSource *source,
switch (e->type) switch (e->type)
{ {
case EV_KEY: case EV_KEY:
/* don't repeat mouse buttons */ if (e->code < BTN_MISC || (e->code >= KEY_OK && e->code < BTN_TRIGGER_HAPPY))
if (e->code >= BTN_MOUSE && e->code < KEY_OK) notify_key (source, _time, e->code, e->value);
if (e->value == AUTOREPEAT_VALUE) else if (e->code >= BTN_MOUSE && e->code < BTN_JOYSTICK)
return;
switch (e->code)
{ {
case BTN_TOUCH: /* don't repeat mouse buttons */
case BTN_TOOL_PEN: if (e->value != AUTOREPEAT_VALUE)
case BTN_TOOL_RUBBER: notify_button (source, _time, e->code, e->value);
case BTN_TOOL_BRUSH:
case BTN_TOOL_PENCIL:
case BTN_TOOL_AIRBRUSH:
case BTN_TOOL_FINGER:
case BTN_TOOL_MOUSE:
case BTN_TOOL_LENS:
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(source, _time, e->code, e->value);
break;
default:
notify_key (source, _time, e->code, e->value);
break;
} }
else
/* We don't know about this code, ignore */;
break; break;
case EV_SYN: case EV_SYN:
/* Nothing to do here */
break;
case EV_MSC: case EV_MSC:
/* Nothing to do here */ /* Nothing to do here (actually, EV_SYN is handled by libevdev, we shouldn't see it) */
break; break;
case EV_REL: case EV_REL:
@ -508,12 +486,11 @@ dispatch_one_event (ClutterEventSource *source,
*dy += e->value; *dy += e->value;
break; break;
/* Note: we assume that REL_WHEEL is for *vertical* scroll wheels.
To implement horizontal scroll, we'll need a different enum
value.
*/
case REL_WHEEL: case REL_WHEEL:
notify_scroll (source, _time, e->value); notify_scroll (source, _time, e->value, CLUTTER_ORIENTATION_VERTICAL);
break;
case REL_HWHEEL:
notify_scroll (source, _time, e->value, CLUTTER_ORIENTATION_HORIZONTAL);
break; break;
} }
break; break;