[gtk+/wip/wayland-tablet: 23/23] wayland: Translate pen buttons into button events



commit 3d65afbf1ba76bfd0020f47628185e477bf79deb
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Jun 22 18:28:46 2015 +0200

    wayland: Translate pen buttons into button events
    
    up/down already take GDK_BUTTON_PRIMARY, we translate BTN_STYLUS(2)
    into GDK_BUTTON_MIDDLE/SECONDARY.

 gdk/wayland/gdkdevice-wayland.c |   43 +++++++++++++++++++++++++++++++++-----
 1 files changed, 37 insertions(+), 6 deletions(-)
---
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index 0789857..d19e25a 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -34,6 +34,7 @@
 
 #include <sys/time.h>
 #include <sys/mman.h>
+#include <linux/input.h>
 
 typedef struct _GdkWaylandTouchData GdkWaylandTouchData;
 typedef struct _GdkWaylandPointerData GdkWaylandPointerData;
@@ -2042,6 +2043,41 @@ tablet_handle_tilt (void             *data,
 }
 
 static void
+tablet_handle_button (void             *data,
+                      struct wl_tablet *wl_tablet,
+                      uint32_t          serial,
+                      uint32_t          time,
+                      uint32_t          button,
+                      uint32_t          state)
+{
+  GdkWaylandDeviceTabletPair *device_pair = data;
+  GdkEventType evtype;
+  guint n_button;
+
+  if (!device_pair->pointer_info.focus)
+    return;
+
+  device_pair->pointer_info.time = time;
+  device_pair->pointer_info.press_serial = serial;
+
+  if (button == BTN_STYLUS)
+    n_button = GDK_BUTTON_SECONDARY;
+  else if (button == BTN_STYLUS2)
+    n_button = GDK_BUTTON_MIDDLE;
+  else
+    return;
+
+  if (state == WL_TABLET_BUTTON_STATE_PRESSED)
+    evtype = GDK_BUTTON_PRESS;
+  else if (state == WL_TABLET_BUTTON_STATE_RELEASED)
+    evtype = GDK_BUTTON_RELEASE;
+  else
+    return;
+
+  tablet_notify_button_event (device_pair, evtype, n_button);
+}
+
+static void
 tablet_handle_frame (void             *data,
                      struct wl_tablet *wl_tablet)
 {
@@ -2082,11 +2118,6 @@ tablet_handle_frame (void             *data,
 }
 
 static void
-tablet_handler_placeholder ()
-{
-}
-
-static void
 tablet_handle_removed (void             *data,
                        struct wl_tablet *wl_tablet)
 {
@@ -2129,7 +2160,7 @@ static const struct wl_tablet_listener tablet_listener = {
   tablet_handle_pressure,
   tablet_handle_distance,
   tablet_handle_tilt,
-  tablet_handler_placeholder, /* button */
+  tablet_handle_button,
   tablet_handle_frame,
   tablet_handle_removed
 };


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