[mutter/gnome-3-24] wayland: Provide basic tablet wheel event support



commit 726296f0224b112c3305252f27bb9eeec54d54ba
Author: Jason Gerecke <killertofu gmail com>
Date:   Mon Jun 12 15:25:10 2017 -0700

    wayland: Provide basic tablet wheel event support
    
    Adds basic support for the "wheel" event from the Wayland tablet protocol.
    Ideally we would accumulate the angle and report a wheel event with an
    appropriate value for "clicks". We can get away with a much cruder method
    for the time being, however, since no Wacom tablet puck actually provides
    a smooth scrollwheel. Checking whether the angle in CLUTTER_INPUT_AXIS_WHEEL
    exceeds a nominally-small threshold is sufficient to determine that the
    wheel has advanced by at least one physical click.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=783716

 clutter/clutter/evdev/clutter-input-device-evdev.c |    3 ++
 src/wayland/meta-wayland-tablet-tool.c             |   36 ++++++++++++++++++-
 2 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/clutter/clutter/evdev/clutter-input-device-evdev.c 
b/clutter/clutter/evdev/clutter-input-device-evdev.c
index 6019d05..cb4340a 100644
--- a/clutter/clutter/evdev/clutter-input-device-evdev.c
+++ b/clutter/clutter/evdev/clutter-input-device-evdev.c
@@ -163,6 +163,9 @@ clutter_input_device_evdev_update_from_tool (ClutterInputDevice     *device,
   if (libinput_tablet_tool_has_slider (evdev_tool->tool))
     _clutter_input_device_add_axis (device, CLUTTER_INPUT_AXIS_SLIDER, -1, 1, 0);
 
+  if (libinput_tablet_tool_has_wheel (evdev_tool->tool))
+    _clutter_input_device_add_axis (device, CLUTTER_INPUT_AXIS_WHEEL, -180, 180, 0);
+
   g_object_thaw_notify (G_OBJECT (device));
 }
 
diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c
index cd55f20..f20d448 100644
--- a/src/wayland/meta-wayland-tablet-tool.c
+++ b/src/wayland/meta-wayland-tablet-tool.c
@@ -801,6 +801,38 @@ broadcast_rotation (MetaWaylandTabletTool *tool,
 }
 
 static void
+broadcast_wheel (MetaWaylandTabletTool *tool,
+                 const ClutterEvent    *event)
+{
+  struct wl_resource *resource;
+  ClutterInputDevice *source;
+  gdouble angle;
+  gint32 clicks = 0;
+
+  source = clutter_event_get_source_device (event);
+
+  if (!clutter_input_device_get_axis_value (source, event->motion.axes,
+                                            CLUTTER_INPUT_AXIS_WHEEL,
+                                            &angle))
+    return;
+
+  /* FIXME: Perform proper angle-to-clicks accumulation elsewhere */
+  if (angle > 0.01)
+    clicks = 1;
+  else if (angle < -0.01)
+    clicks = -1;
+  else
+    return;
+
+  wl_resource_for_each (resource, &tool->focus_resource_list)
+    {
+      zwp_tablet_tool_v2_send_wheel (resource,
+                                     wl_fixed_from_double (angle),
+                                     clicks);
+    }
+}
+
+static void
 broadcast_axes (MetaWaylandTabletTool *tool,
                 const ClutterEvent    *event)
 {
@@ -823,8 +855,8 @@ broadcast_axes (MetaWaylandTabletTool *tool,
     broadcast_rotation (tool, event);
   if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_SLIDER))
     broadcast_axis (tool, event, CLUTTER_INPUT_AXIS_SLIDER);
-
-  /* FIXME: Missing wp_tablet_tool.wheel */
+  if (capabilities & (1 << ZWP_TABLET_TOOL_V2_CAPABILITY_WHEEL))
+    broadcast_wheel (tool, event);
 }
 
 static void


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