[mutter] clutter/evdev: Take over stylus configuration



commit b252771a8f08932fc1fadaa3d971ff931c4ba568
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Oct 31 17:43:38 2016 +0100

    clutter/evdev: Take over stylus configuration
    
    Stylus configuration (stylus buttons, pressure) was handled
    at the very high level, doing the button and pressure translations
    right before sending these to wayland clients.
    
    However, it makes more sense to store these settings into the
    ClutterInputDeviceTool itself, and have clutter apply the config
    at the lower level so 1) the settings actually apply desktop-wide,
    not just in clients and 2) X11 and wayland may share similar
    configuration paths. The settings are now just applied whenever
    the tool enters proximity, in reaction to
    ClutterDeviceManager::tool-changed.
    
    This commit moves all handling of these two settings to
    the clutter level, and removes the wayland-specific paths
    
    https://bugzilla.gnome.org/show_bug.cgi?id=773779

 .../clutter/evdev/clutter-device-manager-evdev.c   |    7 +-
 clutter/clutter/evdev/clutter-evdev.h              |    8 +
 .../evdev/clutter-input-device-tool-evdev.c        |   96 ++++++++++++
 .../evdev/clutter-input-device-tool-evdev.h        |    7 +
 clutter/clutter/evdev/clutter-seat-evdev.c         |   16 ++-
 src/backends/meta-input-settings-private.h         |   19 ++--
 src/backends/meta-input-settings.c                 |  152 +++++++++++---------
 src/backends/native/meta-input-settings-native.c   |   52 +++++++
 src/wayland/meta-wayland-tablet-tool.c             |   89 ++----------
 9 files changed, 290 insertions(+), 156 deletions(-)
---
diff --git a/clutter/clutter/evdev/clutter-device-manager-evdev.c 
b/clutter/clutter/evdev/clutter-device-manager-evdev.c
index eeddc22..732f0a3 100644
--- a/clutter/clutter/evdev/clutter-device-manager-evdev.c
+++ b/clutter/clutter/evdev/clutter-device-manager-evdev.c
@@ -1219,7 +1219,8 @@ input_device_update_tool (ClutterInputDevice          *input_device,
 }
 
 static gdouble *
-translate_tablet_axes (struct libinput_event_tablet_tool *tablet_event)
+translate_tablet_axes (struct libinput_event_tablet_tool *tablet_event,
+                       ClutterInputDeviceTool            *tool)
 {
   GArray *axes = g_array_new (FALSE, FALSE, sizeof (gdouble));
   struct libinput_tablet_tool *libinput_tool;
@@ -1241,6 +1242,7 @@ translate_tablet_axes (struct libinput_event_tablet_tool *tablet_event)
   if (libinput_tablet_tool_has_pressure (libinput_tool))
     {
       value = libinput_event_tablet_tool_get_pressure (tablet_event);
+      value = clutter_input_device_tool_evdev_translate_pressure (tool, value);
       g_array_append_val (axes, value);
     }
 
@@ -1718,7 +1720,8 @@ process_device_event (ClutterDeviceManagerEvdev *manager_evdev,
         if (!stage)
           break;
 
-        axes = translate_tablet_axes (tablet_event);
+        axes = translate_tablet_axes (tablet_event,
+                                      evdev_device->last_tool);
         if (!axes)
           break;
 
diff --git a/clutter/clutter/evdev/clutter-evdev.h b/clutter/clutter/evdev/clutter-evdev.h
index 1f5485c..8e8f8d9 100644
--- a/clutter/clutter/evdev/clutter-evdev.h
+++ b/clutter/clutter/evdev/clutter-evdev.h
@@ -150,6 +150,14 @@ gboolean clutter_evdev_event_get_relative_motion (const ClutterEvent *event,
                                                   double             *dx_unaccel,
                                                   double             *dy_unaccel);
 
+CLUTTER_AVAILABLE_IN_ALL
+void clutter_evdev_input_device_tool_set_pressure_curve (ClutterInputDeviceTool *tool,
+                                                         gdouble                 curve[4]);
+CLUTTER_AVAILABLE_IN_ALL
+void clutter_evdev_input_device_tool_set_button_code    (ClutterInputDeviceTool *tool,
+                                                         guint                   button,
+                                                         guint                   evcode);
+
 G_END_DECLS
 
 #endif /* __CLUTTER_EVDEV_H__ */
diff --git a/clutter/clutter/evdev/clutter-input-device-tool-evdev.c 
b/clutter/clutter/evdev/clutter-input-device-tool-evdev.c
index e0cdb31..1210606 100644
--- a/clutter/clutter/evdev/clutter-input-device-tool-evdev.c
+++ b/clutter/clutter/evdev/clutter-input-device-tool-evdev.c
@@ -26,6 +26,7 @@
 #endif
 
 #include "clutter-input-device-tool-evdev.h"
+#include "clutter-evdev.h"
 
 G_DEFINE_TYPE (ClutterInputDeviceToolEvdev, clutter_input_device_tool_evdev,
                CLUTTER_TYPE_INPUT_DEVICE_TOOL)
@@ -35,6 +36,7 @@ clutter_input_device_tool_evdev_finalize (GObject *object)
 {
   ClutterInputDeviceToolEvdev *tool = CLUTTER_INPUT_DEVICE_TOOL_EVDEV (object);
 
+  g_hash_table_unref (tool->button_map);
   libinput_tablet_tool_unref (tool->tool);
 
   G_OBJECT_CLASS (clutter_input_device_tool_evdev_parent_class)->finalize (object);
@@ -51,6 +53,7 @@ clutter_input_device_tool_evdev_class_init (ClutterInputDeviceToolEvdevClass *kl
 static void
 clutter_input_device_tool_evdev_init (ClutterInputDeviceToolEvdev *tool)
 {
+  tool->button_map = g_hash_table_new (NULL, NULL);
 }
 
 ClutterInputDeviceTool *
@@ -70,3 +73,96 @@ clutter_input_device_tool_evdev_new (struct libinput_tablet_tool *tool,
 
   return CLUTTER_INPUT_DEVICE_TOOL (evdev_tool);
 }
+
+void
+clutter_evdev_input_device_tool_set_pressure_curve (ClutterInputDeviceTool *tool,
+                                                    gdouble                 curve[4])
+{
+  ClutterInputDeviceToolEvdev *evdev_tool;
+
+  g_return_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL_EVDEV (tool));
+  g_return_if_fail (curve[0] >= 0 && curve[0] <= 1 &&
+                    curve[1] >= 0 && curve[1] <= 1 &&
+                    curve[2] >= 0 && curve[2] <= 1 &&
+                    curve[3] >= 0 && curve[3] <= 1);
+
+  evdev_tool = CLUTTER_INPUT_DEVICE_TOOL_EVDEV (tool);
+  evdev_tool->pressure_curve[0] = curve[0];
+  evdev_tool->pressure_curve[1] = curve[1];
+  evdev_tool->pressure_curve[2] = curve[2];
+  evdev_tool->pressure_curve[3] = curve[3];
+}
+
+void
+clutter_evdev_input_device_tool_set_button_code (ClutterInputDeviceTool *tool,
+                                                 guint                   button,
+                                                 guint                   evcode)
+{
+  ClutterInputDeviceToolEvdev *evdev_tool;
+
+  g_return_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL_EVDEV (tool));
+
+  evdev_tool = CLUTTER_INPUT_DEVICE_TOOL_EVDEV (tool);
+
+  if (evcode == 0)
+    {
+      g_hash_table_remove (evdev_tool->button_map, GUINT_TO_POINTER (button));
+    }
+  else
+    {
+      g_hash_table_insert (evdev_tool->button_map, GUINT_TO_POINTER (button),
+                           GUINT_TO_POINTER (evcode));
+    }
+}
+
+static gdouble
+calculate_bezier_position (gdouble pos,
+                           gdouble x1,
+                           gdouble y1,
+                           gdouble x2,
+                           gdouble y2)
+{
+  gdouble int1_y, int2_y;
+
+  pos = CLAMP (pos, 0, 1);
+
+  /* Intersection between 0,0 and x1,y1 */
+  int1_y = pos * y1;
+
+  /* Intersection between x2,y2 and 1,1 */
+  int2_y = (pos * (1 - y2)) + y2;
+
+  /* Find the new position in the line traced by the previous points */
+  return (pos * (int2_y - int1_y)) + int1_y;
+}
+
+gdouble
+clutter_input_device_tool_evdev_translate_pressure (ClutterInputDeviceTool *tool,
+                                                    gdouble                 pressure)
+{
+  ClutterInputDeviceToolEvdev *evdev_tool;
+
+  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL (tool), pressure);
+
+  evdev_tool = CLUTTER_INPUT_DEVICE_TOOL_EVDEV (tool);
+
+  return calculate_bezier_position (CLAMP (pressure, 0, 1),
+                                    evdev_tool->pressure_curve[0],
+                                    evdev_tool->pressure_curve[1],
+                                    evdev_tool->pressure_curve[2],
+                                    evdev_tool->pressure_curve[3]);
+}
+
+guint
+clutter_input_device_tool_evdev_get_button_code (ClutterInputDeviceTool *tool,
+                                                 guint                   button)
+{
+  ClutterInputDeviceToolEvdev *evdev_tool;
+
+  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL (tool), 0);
+
+  evdev_tool = CLUTTER_INPUT_DEVICE_TOOL_EVDEV (tool);
+
+  return GPOINTER_TO_UINT (g_hash_table_lookup (evdev_tool->button_map,
+                                                GUINT_TO_POINTER (button)));
+}
diff --git a/clutter/clutter/evdev/clutter-input-device-tool-evdev.h 
b/clutter/clutter/evdev/clutter-input-device-tool-evdev.h
index c92a2ca..91eaf8e 100644
--- a/clutter/clutter/evdev/clutter-input-device-tool-evdev.h
+++ b/clutter/clutter/evdev/clutter-input-device-tool-evdev.h
@@ -59,6 +59,8 @@ struct _ClutterInputDeviceToolEvdev
 {
   ClutterInputDeviceTool parent_instance;
   struct libinput_tablet_tool *tool;
+  GHashTable *button_map;
+  gdouble pressure_curve[4];
 };
 
 struct _ClutterInputDeviceToolEvdevClass
@@ -72,6 +74,11 @@ ClutterInputDeviceTool * clutter_input_device_tool_evdev_new      (struct libinp
                                                                    guint64                      serial,
                                                                    ClutterInputDeviceToolType   type);
 
+gdouble                  clutter_input_device_tool_evdev_translate_pressure (ClutterInputDeviceTool *tool,
+                                                                             gdouble                 
pressure);
+guint                    clutter_input_device_tool_evdev_get_button_code    (ClutterInputDeviceTool *tool,
+                                                                             guint                   button);
+
 G_END_DECLS
 
 #endif /* __CLUTTER_INPUT_DEVICE_EVDEV_TOOL_H__ */
diff --git a/clutter/clutter/evdev/clutter-seat-evdev.c b/clutter/clutter/evdev/clutter-seat-evdev.c
index f5ae1dd..b803286 100644
--- a/clutter/clutter/evdev/clutter-seat-evdev.c
+++ b/clutter/clutter/evdev/clutter-seat-evdev.c
@@ -32,6 +32,7 @@
 
 #include "clutter-event-private.h"
 #include "clutter-input-device-evdev.h"
+#include "clutter-input-device-tool-evdev.h"
 #include "clutter-main.h"
 
 /* Try to keep the pointer inside the stage. Hopefully no one is using
@@ -433,6 +434,7 @@ clutter_seat_evdev_notify_button (ClutterSeatEvdev   *seat,
                                   uint32_t            button,
                                   uint32_t            state)
 {
+  ClutterInputDeviceEvdev *device_evdev = (ClutterInputDeviceEvdev *) input_device;
   ClutterStage *stage;
   ClutterEvent *event = NULL;
   gint button_nr;
@@ -528,13 +530,21 @@ clutter_seat_evdev_notify_button (ClutterSeatEvdev   *seat,
   clutter_event_set_device (event, seat->core_pointer);
   clutter_event_set_source_device (event, input_device);
 
+  if (device_evdev->last_tool)
+    {
+      /* Apply the button event code as per the tool mapping */
+      guint mapped_button;
+
+      mapped_button = clutter_input_device_tool_evdev_get_button_code (device_evdev->last_tool,
+                                                                       button_nr);
+      if (mapped_button != 0)
+        button = mapped_button;
+    }
+
   _clutter_evdev_event_set_event_code (event, button);
 
   if (clutter_input_device_get_device_type (input_device) == CLUTTER_TABLET_DEVICE)
     {
-      ClutterInputDeviceEvdev *device_evdev =
-        CLUTTER_INPUT_DEVICE_EVDEV (input_device);
-
       clutter_event_set_device_tool (event, device_evdev->last_tool);
       clutter_event_set_device (event, input_device);
     }
diff --git a/src/backends/meta-input-settings-private.h b/src/backends/meta-input-settings-private.h
index 6e5f97b..06f215c 100644
--- a/src/backends/meta-input-settings-private.h
+++ b/src/backends/meta-input-settings-private.h
@@ -107,6 +107,16 @@ struct _MetaInputSettingsClass
   void (* set_trackball_accel_profile) (MetaInputSettings          *settings,
                                         ClutterInputDevice         *device,
                                         GDesktopPointerAccelProfile profile);
+
+  void (* set_stylus_pressure) (MetaInputSettings            *settings,
+                                ClutterInputDevice           *device,
+                                ClutterInputDeviceTool       *tool,
+                                const gint32                  curve[4]);
+  void (* set_stylus_button_map) (MetaInputSettings          *settings,
+                                  ClutterInputDevice         *device,
+                                  ClutterInputDeviceTool     *tool,
+                                  GDesktopStylusButtonAction  primary,
+                                  GDesktopStylusButtonAction  secondary);
 };
 
 GType meta_input_settings_get_type (void) G_GNUC_CONST;
@@ -121,15 +131,6 @@ MetaMonitorInfo *     meta_input_settings_get_tablet_monitor_info (MetaInputSett
 GDesktopTabletMapping meta_input_settings_get_tablet_mapping (MetaInputSettings  *settings,
                                                               ClutterInputDevice *device);
 
-GDesktopStylusButtonAction meta_input_settings_get_stylus_button_action (MetaInputSettings      *settings,
-                                                                         ClutterInputDeviceTool *tool,
-                                                                         ClutterInputDevice     
*current_device,
-                                                                         guint                   button);
-gdouble                    meta_input_settings_translate_tablet_tool_pressure (MetaInputSettings      
*input_settings,
-                                                                               ClutterInputDeviceTool *tool,
-                                                                               ClutterInputDevice     
*current_tablet,
-                                                                               gdouble                 
pressure);
-
 gboolean                   meta_input_settings_is_pad_button_grabbed     (MetaInputSettings  *input_settings,
                                                                           ClutterInputDevice *pad,
                                                                           guint               button);
diff --git a/src/backends/meta-input-settings.c b/src/backends/meta-input-settings.c
index a9bb4bf..7a19d4a 100644
--- a/src/backends/meta-input-settings.c
+++ b/src/backends/meta-input-settings.c
@@ -1276,6 +1276,77 @@ apply_device_settings (MetaInputSettings  *input_settings,
 }
 
 static void
+update_stylus_pressure (MetaInputSettings      *input_settings,
+                        ClutterInputDevice     *device,
+                        ClutterInputDeviceTool *tool)
+{
+  MetaInputSettingsClass *input_settings_class;
+  ToolSettings *tool_settings;
+  const gint32 *curve;
+  GVariant *variant;
+  gsize n_elems;
+
+  if (clutter_input_device_get_device_type (device) != CLUTTER_TABLET_DEVICE &&
+      clutter_input_device_get_device_type (device) != CLUTTER_PEN_DEVICE &&
+      clutter_input_device_get_device_type (device) != CLUTTER_ERASER_DEVICE)
+    return;
+
+  if (!tool)
+    return;
+
+  tool_settings = lookup_tool_settings (tool, device);
+
+  if (clutter_input_device_tool_get_tool_type (tool) ==
+      CLUTTER_INPUT_DEVICE_TOOL_ERASER)
+    variant = g_settings_get_value (tool_settings->settings, "eraser-pressure-curve");
+  else
+    variant = g_settings_get_value (tool_settings->settings, "pressure-curve");
+
+  curve = g_variant_get_fixed_array (variant, &n_elems, sizeof (gint32));
+  if (n_elems != 4)
+    return;
+
+  input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
+  input_settings_class->set_stylus_pressure (input_settings, device, tool, curve);
+}
+
+static void
+update_stylus_buttonmap (MetaInputSettings      *input_settings,
+                         ClutterInputDevice     *device,
+                         ClutterInputDeviceTool *tool)
+{
+  MetaInputSettingsClass *input_settings_class;
+  GDesktopStylusButtonAction primary, secondary;
+  ToolSettings *tool_settings;
+
+  if (clutter_input_device_get_device_type (device) != CLUTTER_TABLET_DEVICE &&
+      clutter_input_device_get_device_type (device) != CLUTTER_PEN_DEVICE &&
+      clutter_input_device_get_device_type (device) != CLUTTER_ERASER_DEVICE)
+    return;
+
+  if (!tool)
+    return;
+
+  tool_settings = lookup_tool_settings (tool, device);
+
+  primary = g_settings_get_enum (tool_settings->settings, "button-action");
+  secondary = g_settings_get_enum (tool_settings->settings, "secondary-button-action");
+
+  input_settings_class = META_INPUT_SETTINGS_GET_CLASS (input_settings);
+  input_settings_class->set_stylus_button_map (input_settings, device, tool,
+                                               primary, secondary);
+}
+
+static void
+apply_stylus_settings (MetaInputSettings      *input_settings,
+                       ClutterInputDevice     *device,
+                       ClutterInputDeviceTool *tool)
+{
+  update_stylus_pressure (input_settings, device, tool);
+  update_stylus_buttonmap (input_settings, device, tool);
+}
+
+static void
 meta_input_settings_device_added (ClutterDeviceManager *device_manager,
                                   ClutterInputDevice   *device,
                                   MetaInputSettings    *input_settings)
@@ -1299,6 +1370,18 @@ meta_input_settings_device_removed (ClutterDeviceManager *device_manager,
 }
 
 static void
+meta_input_settings_tool_changed (ClutterDeviceManager   *device_manager,
+                                  ClutterInputDevice     *device,
+                                  ClutterInputDeviceTool *tool,
+                                  MetaInputSettings      *input_settings)
+{
+  if (!tool)
+    return;
+
+  apply_stylus_settings (input_settings, device, tool);
+}
+
+static void
 check_mappable_devices (MetaInputSettings *input_settings)
 {
   MetaInputSettingsPrivate *priv;
@@ -1351,6 +1434,8 @@ meta_input_settings_init (MetaInputSettings *settings)
                     G_CALLBACK (meta_input_settings_device_added), settings);
   g_signal_connect (priv->device_manager, "device-removed",
                     G_CALLBACK (meta_input_settings_device_removed), settings);
+  g_signal_connect (priv->device_manager, "tool-changed",
+                    G_CALLBACK (meta_input_settings_tool_changed), settings);
 
   priv->mouse_settings = g_settings_new ("org.gnome.desktop.peripherals.mouse");
   g_signal_connect (priv->mouse_settings, "changed",
@@ -1461,29 +1546,6 @@ meta_input_settings_get_tablet_mapping (MetaInputSettings  *settings,
   return g_settings_get_enum (info->settings, "mapping");
 }
 
-GDesktopStylusButtonAction
-meta_input_settings_get_stylus_button_action (MetaInputSettings      *input_settings,
-                                              ClutterInputDeviceTool *tool,
-                                              ClutterInputDevice     *current_tablet,
-                                              guint                   button)
-{
-  ToolSettings *tool_settings;
-
-  g_return_val_if_fail (META_IS_INPUT_SETTINGS (input_settings),
-                        G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT);
-  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL (tool),
-                        G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT);
-
-  tool_settings = lookup_tool_settings (tool, current_tablet);
-
-  if (button == 2)
-    return tool_settings->button_action;
-  else if (button == 3)
-    return tool_settings->secondary_button_action;
-  else
-    return G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT;
-}
-
 static GDesktopPadButtonAction
 meta_input_settings_get_pad_button_action (MetaInputSettings   *input_settings,
                                            ClutterInputDevice  *pad,
@@ -1672,50 +1734,6 @@ meta_input_settings_emulate_keybinding (MetaInputSettings  *input_settings,
     emulate_modifiers (priv->virtual_pad_keyboard, mods, state);
 }
 
-static gdouble
-calculate_bezier_position (gdouble pos,
-                           gdouble x1,
-                           gdouble y1,
-                           gdouble x2,
-                           gdouble y2)
-{
-  gdouble int1_y, int2_y;
-
-  pos = CLAMP (pos, 0, 1);
-
-  /* Intersection between 0,0 and x1,y1 */
-  int1_y = pos * y1;
-
-  /* Intersection between x2,y2 and 1,1 */
-  int2_y = (pos * (1 - y2)) + y2;
-
-  /* Find the new position in the line traced by the previous points */
-  return (pos * (int2_y - int1_y)) + int1_y;
-}
-
-gdouble
-meta_input_settings_translate_tablet_tool_pressure (MetaInputSettings      *input_settings,
-                                                    ClutterInputDeviceTool *tool,
-                                                    ClutterInputDevice     *current_tablet,
-                                                    gdouble                 pressure)
-{
-  ToolSettings *tool_settings;
-
-  pressure = CLAMP (pressure, 0, 1);
-
-  g_return_val_if_fail (META_IS_INPUT_SETTINGS (input_settings), pressure);
-  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE_TOOL (tool), pressure);
-  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (current_tablet), pressure);
-
-  tool_settings = lookup_tool_settings (tool, current_tablet);
-  pressure = calculate_bezier_position (pressure,
-                                        tool_settings->curve[0],
-                                        tool_settings->curve[1],
-                                        tool_settings->curve[2],
-                                        tool_settings->curve[3]);
-  return pressure;
-}
-
 gboolean
 meta_input_settings_is_pad_button_grabbed (MetaInputSettings  *input_settings,
                                            ClutterInputDevice *pad,
diff --git a/src/backends/native/meta-input-settings-native.c 
b/src/backends/native/meta-input-settings-native.c
index 266d224..1701bdd 100644
--- a/src/backends/native/meta-input-settings-native.c
+++ b/src/backends/native/meta-input-settings-native.c
@@ -24,6 +24,7 @@
 #include "config.h"
 
 #include <clutter/evdev/clutter-evdev.h>
+#include <linux/input-event-codes.h>
 #include <libinput.h>
 
 #include "meta-input-settings-native.h"
@@ -396,6 +397,54 @@ meta_input_settings_native_set_tablet_area (MetaInputSettings  *settings,
 }
 
 static void
+meta_input_settings_native_set_stylus_pressure (MetaInputSettings      *settings,
+                                                ClutterInputDevice     *device,
+                                                ClutterInputDeviceTool *tool,
+                                                const gint              curve[4])
+{
+  gdouble pressure_curve[4];
+
+  pressure_curve[0] = (gdouble) curve[0] / 100;
+  pressure_curve[1] = (gdouble) curve[1] / 100;
+  pressure_curve[2] = (gdouble) curve[2] / 100;
+  pressure_curve[3] = (gdouble) curve[3] / 100;
+
+  clutter_evdev_input_device_tool_set_pressure_curve (tool, pressure_curve);
+}
+
+static guint
+action_to_evcode (GDesktopStylusButtonAction action)
+{
+  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:
+      return 0;
+    }
+}
+
+static void
+meta_input_settings_native_set_stylus_button_map (MetaInputSettings          *settings,
+                                                  ClutterInputDevice         *device,
+                                                  ClutterInputDeviceTool     *tool,
+                                                  GDesktopStylusButtonAction  primary,
+                                                  GDesktopStylusButtonAction  secondary)
+{
+  clutter_evdev_input_device_tool_set_button_code (tool, CLUTTER_BUTTON_MIDDLE,
+                                                   action_to_evcode (primary));
+  clutter_evdev_input_device_tool_set_button_code (tool, CLUTTER_BUTTON_SECONDARY,
+                                                   action_to_evcode (secondary));
+}
+
+static void
 meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass)
 {
   MetaInputSettingsClass *input_settings_class = META_INPUT_SETTINGS_CLASS (klass);
@@ -418,6 +467,9 @@ meta_input_settings_native_class_init (MetaInputSettingsNativeClass *klass)
 
   input_settings_class->set_mouse_accel_profile = meta_input_settings_native_set_mouse_accel_profile;
   input_settings_class->set_trackball_accel_profile = meta_input_settings_native_set_trackball_accel_profile;
+
+  input_settings_class->set_stylus_pressure = meta_input_settings_native_set_stylus_pressure;
+  input_settings_class->set_stylus_button_map = meta_input_settings_native_set_stylus_button_map;
 }
 
 static void
diff --git a/src/wayland/meta-wayland-tablet-tool.c b/src/wayland/meta-wayland-tablet-tool.c
index c3df2d9..dcf7d1e 100644
--- a/src/wayland/meta-wayland-tablet-tool.c
+++ b/src/wayland/meta-wayland-tablet-tool.c
@@ -654,71 +654,28 @@ broadcast_up (MetaWaylandTabletTool *tool,
     }
 }
 
-static guint32
-translate_button_action (MetaWaylandTabletTool *tool,
-                         const ClutterEvent    *event)
+static void
+broadcast_button (MetaWaylandTabletTool *tool,
+                  const ClutterEvent    *event)
 {
-  MetaInputSettings *input_settings;
-  GDesktopStylusButtonAction action;
-  MetaBackend *backend;
-
-  backend = meta_get_backend ();
-  input_settings = meta_backend_get_input_settings (backend);
+  struct wl_resource *resource;
+  guint32 button;
 
-  if (input_settings)
+#ifdef HAVE_NATIVE_BACKEND
+  MetaBackend *backend = meta_get_backend ();
+  if (META_IS_BACKEND_NATIVE (backend))
     {
-      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);
+      button = clutter_evdev_event_get_event_code (event);
     }
   else
+#endif
     {
-      action = G_DESKTOP_STYLUS_BUTTON_ACTION_DEFAULT;
+      /* We can't do much better here, there's several
+       * different BTN_ ranges to cover.
+       */
+      button = event->button.button;
     }
 
-  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)
-{
-  struct wl_resource *resource;
-  guint32 button;
-
-  button = translate_button_action (tool, event);
   tool->button_serial = wl_display_next_serial (tool->seat->manager->wl_display);
 
   wl_resource_for_each (resource, &tool->focus_resource_list)
@@ -745,24 +702,6 @@ broadcast_axis (MetaWaylandTabletTool *tool,
   if (!clutter_input_device_get_axis_value (source, event->motion.axes, axis, &val))
     return;
 
-  if (axis == CLUTTER_INPUT_AXIS_PRESSURE)
-    {
-      MetaInputSettings *input_settings;
-      ClutterInputDevice *device;
-      MetaBackend *backend;
-
-      backend = meta_get_backend ();
-      input_settings = meta_backend_get_input_settings (backend);
-      device = clutter_event_get_source_device (event);
-
-      if (input_settings)
-        {
-          val = meta_input_settings_translate_tablet_tool_pressure (input_settings,
-                                                                    tool->device_tool,
-                                                                    device, val);
-        }
-    }
-
   value = val * TABLET_AXIS_MAX;
 
   wl_resource_for_each (resource, &tool->focus_resource_list)


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