[mutter/wip/tablet-protocol-v2: 49/65] wayland: Implement stylus button actions



commit f62f7c8a2f9c9743dc68dcbad4f60d97e79e766b
Author: Carlos Garnacho <carlosg gnome org>
Date:   Wed Jun 22 15:56:08 2016 +0200

    wayland: Implement stylus button actions
    
    Those just send different BTN_ keycodes.

 src/wayland/meta-wayland-tablet-tool.c |   72 +++++++++++++++++++++++++------
 1 files changed, 58 insertions(+), 14 deletions(-)
---
diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c
index 8e69f79..9058686 100644
--- a/src/wayland/meta-wayland-tablet-tool.c
+++ b/src/wayland/meta-wayland-tablet-tool.c
@@ -36,9 +36,11 @@
 #include "meta-wayland-tablet.h"
 #include "meta-wayland-tablet-seat.h"
 #include "meta-wayland-tablet-tool.h"
+#include "backends/meta-input-settings-private.h"
 
 #ifdef HAVE_NATIVE_BACKEND
 #include "backends/native/meta-backend-native.h"
+#include <linux/input-event-codes.h>
 #endif
 
 #define TABLET_AXIS_MAX 65535
@@ -651,6 +653,61 @@ broadcast_up (MetaWaylandTabletTool *tool,
     }
 }
 
+static guint32
+translate_button_action (MetaWaylandTabletTool *tool,
+                         const ClutterEvent    *event)
+{
+  MetaInputSettings *input_settings;
+  GDesktopStylusButtonAction action;
+
+  input_settings = meta_input_settings_get ();
+
+  if (input_settings)
+    {
+      ClutterInputDevice *device;
+
+      device = clutter_event_get_source_device (event);
+      action = meta_input_settings_get_stylus_button_action (input_settings,
+                                                             tool->device_tool,
+                                                             device,
+                                                             event->button.button);
+    }
+  else
+    {
+      action = G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT;
+    }
+
+  switch (action)
+    {
+    case G_DESKTOP_STYLUS_BUTTON_ACTION_MIDDLE:
+      return BTN_STYLUS;
+    case G_DESKTOP_STYLUS_BUTTON_ACTION_RIGHT:
+      return BTN_STYLUS2;
+    case G_DESKTOP_STYLUS_BUTTON_ACTION_BACK:
+      return BTN_BACK;
+    case G_DESKTOP_STYLUS_BUTTON_ACTION_FORWARD:
+      return BTN_FORWARD;
+    case G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT:
+    default:
+      {
+#ifdef HAVE_NATIVE_BACKEND
+        MetaBackend *backend = meta_get_backend ();
+        if (META_IS_BACKEND_NATIVE (backend))
+          {
+            return clutter_evdev_event_get_event_code (event);
+          }
+        else
+#endif
+          {
+            /* We can't do much better here, there's several
+             * different BTN_ ranges to cover.
+             */
+            return event->button.button;
+          }
+      }
+    }
+}
+
 static void
 broadcast_button (MetaWaylandTabletTool *tool,
                   const ClutterEvent    *event)
@@ -658,22 +715,9 @@ broadcast_button (MetaWaylandTabletTool *tool,
   struct wl_resource *resource;
   guint32 button;
 
+  button = translate_button_action (tool, event);
   tool->button_serial = wl_display_next_serial (tool->seat->manager->wl_display);
 
-#ifdef HAVE_NATIVE_BACKEND
-  MetaBackend *backend = meta_get_backend ();
-  if (META_IS_BACKEND_NATIVE (backend))
-    button = clutter_evdev_event_get_event_code (event);
-  else
-#endif
-    {
-      /* We can't do much better here, there's several
-       * different BTN_ ranges to cover.
-       */
-      button = event->button.button;
-    }
-
-
   wl_resource_for_each (resource, &tool->focus_resource_list)
     {
       zwp_tablet_tool_v2_send_button (resource, tool->button_serial, button,


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