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



commit e029f5556394a25311a5de2d53d2cc0ec50fdd00
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 4c87b8c..101a279 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -35,6 +35,7 @@
 
 #include <sys/time.h>
 #include <sys/mman.h>
+#include <linux/input.h>
 
 typedef struct _GdkWaylandTouchData GdkWaylandTouchData;
 typedef struct _GdkWaylandPointerData GdkWaylandPointerData;
@@ -2379,6 +2380,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)
 {
@@ -2419,11 +2455,6 @@ tablet_handle_frame (void             *data,
 }
 
 static void
-tablet_handler_placeholder ()
-{
-}
-
-static void
 tablet_handle_removed (void             *data,
                        struct wl_tablet *wl_tablet)
 {
@@ -2478,7 +2509,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]