[clutter/clutter-1.16] evdev: implement wheel events



commit 0e519e2b3b0de6880533631ddfb85362727524a8
Author: Giovanni Campagna <gcampagn redhat com>
Date:   Fri Aug 9 18:43:19 2013 +0200

    evdev: implement wheel events
    
    Mouse wheel events come as EV_REL/REL_WHEEL, and we can convert
    them to clutter events on the assumption that scrolling with
    the wheel is always vertical.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=705710

 clutter/evdev/clutter-device-manager-evdev.c |   43 ++++++++++++++++++++++++++
 1 files changed, 43 insertions(+), 0 deletions(-)
---
diff --git a/clutter/evdev/clutter-device-manager-evdev.c b/clutter/evdev/clutter-device-manager-evdev.c
index 5a92e8e..cf65fa4 100644
--- a/clutter/evdev/clutter-device-manager-evdev.c
+++ b/clutter/evdev/clutter-device-manager-evdev.c
@@ -275,6 +275,41 @@ notify_relative_motion (ClutterEventSource *source,
 }
 
 static void
+notify_scroll (ClutterEventSource *source,
+              guint32             time_,
+              gint32              value)
+{
+  ClutterInputDevice *input_device = (ClutterInputDevice *) source->device;
+  ClutterDeviceManagerEvdev *manager_evdev;
+  ClutterStage *stage;
+  ClutterEvent *event = NULL;
+  ClutterPoint point;
+
+  /* We can drop the event on the floor if no stage has been
+   * associated with the device yet. */
+  stage = _clutter_input_device_get_stage (input_device);
+  if (!stage)
+    return;
+
+  manager_evdev = CLUTTER_DEVICE_MANAGER_EVDEV (input_device->device_manager);
+
+  event = clutter_event_new (CLUTTER_SCROLL);
+
+  event->scroll.time = time_;
+  event->scroll.stage = CLUTTER_STAGE (stage);
+  event->scroll.device = manager_evdev->priv->core_pointer;
+  event->motion.modifier_state = xkb_state_serialize_mods (manager_evdev->priv->xkb, XKB_STATE_EFFECTIVE);
+  event->scroll.modifier_state |= manager_evdev->priv->button_state;
+  event->scroll.direction = value < 0 ? CLUTTER_SCROLL_DOWN : CLUTTER_SCROLL_UP;
+  clutter_input_device_get_coords (manager_evdev->priv->core_pointer, NULL, &point);
+  event->scroll.x = point.x;
+  event->scroll.y = point.y;
+  clutter_event_set_source_device (event, (ClutterInputDevice*) source->device);
+
+  queue_event (event);
+}
+
+static void
 notify_button (ClutterEventSource *source,
                guint32             time_,
                guint32             button,
@@ -469,6 +504,14 @@ clutter_event_dispatch (GSource     *g_source,
                  case REL_Y:
                    dy += e->value;
                    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:
+                  notify_scroll (source, _time, e->value);
+                  break;
                  }
                break;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]