Blame SOURCES/0001-backends-x11-Observe-multiple-pad-mode-switch-button.patch

657d8e
From a8f12e7afdb35ebda581cee6a32b295cb6e643ec Mon Sep 17 00:00:00 2001
657d8e
From: Carlos Garnacho <carlosg@gnome.org>
657d8e
Date: Fri, 13 Dec 2019 14:22:12 +0100
657d8e
Subject: [PATCH] backends/x11: Observe multiple pad mode switch buttons in a
657d8e
 group
657d8e
657d8e
Some tablets like the Cintiq 24HDT have several mode switch buttons
657d8e
per group. Those are meant to jump straight to a given mode, however
657d8e
we just handle cycling across modes (as most other tablets have a
657d8e
single mode switch button per group).
657d8e
657d8e
So spice up the mode switch handling so we handle multiple mode
657d8e
switch buttons, assigning each of them a mode. If the device only
657d8e
has one mode switch button, we do the old-fashioned cycling.
657d8e
657d8e
https://gitlab.gnome.org/GNOME/mutter/merge_requests/970
657d8e
---
657d8e
 .../clutter/x11/clutter-input-device-xi2.c    | 71 ++++++++++++++++---
657d8e
 1 file changed, 60 insertions(+), 11 deletions(-)
657d8e
657d8e
diff --git a/clutter/clutter/x11/clutter-input-device-xi2.c b/clutter/clutter/x11/clutter-input-device-xi2.c
657d8e
index 1254aca3a..c33adffc2 100644
657d8e
--- a/clutter/clutter/x11/clutter-input-device-xi2.c
657d8e
+++ b/clutter/clutter/x11/clutter-input-device-xi2.c
657d8e
@@ -318,6 +318,57 @@ clutter_input_device_xi2_get_pad_group_mode (ClutterInputDevice *device,
657d8e
   return g_array_index (device_xi2->group_modes, guint, group);
657d8e
 }
657d8e
 
657d8e
+static gboolean
657d8e
+pad_switch_mode (ClutterInputDevice *device,
657d8e
+                 uint32_t            button,
657d8e
+                 uint32_t            group,
657d8e
+                 uint32_t           *mode)
657d8e
+{
657d8e
+  ClutterInputDeviceXI2 *device_x11 = CLUTTER_INPUT_DEVICE_XI2 (device);
657d8e
+  uint32_t n_buttons, n_modes, button_group, next_mode, i;
657d8e
+  GList *switch_buttons = NULL;
657d8e
+
657d8e
+  n_buttons = libwacom_get_num_buttons (device_x11->wacom_device);
657d8e
+
657d8e
+  for (i = 0; i < n_buttons; i++)
657d8e
+    {
657d8e
+      button_group = clutter_input_device_xi2_get_button_group (device, i);
657d8e
+      if (button_group == group)
657d8e
+        switch_buttons = g_list_prepend (switch_buttons, GINT_TO_POINTER (i));
657d8e
+    }
657d8e
+
657d8e
+  switch_buttons = g_list_reverse (switch_buttons);
657d8e
+  n_modes = clutter_input_device_get_group_n_modes (device, group);
657d8e
+
657d8e
+  if (g_list_length (switch_buttons) > 1)
657d8e
+    {
657d8e
+      /* If there's multiple switch buttons, we don't toggle but assign a mode
657d8e
+       * to each of those buttons.
657d8e
+       */
657d8e
+      next_mode = g_list_index (switch_buttons, GINT_TO_POINTER (button));
657d8e
+    }
657d8e
+  else if (switch_buttons)
657d8e
+    {
657d8e
+      uint32_t cur_mode;
657d8e
+
657d8e
+      /* If there is a single button, have it toggle across modes */
657d8e
+      cur_mode = g_array_index (device_x11->group_modes, uint32_t, group);
657d8e
+      next_mode = (cur_mode + 1) % n_modes;
657d8e
+    }
657d8e
+  else
657d8e
+    {
657d8e
+      return FALSE;
657d8e
+    }
657d8e
+
657d8e
+  g_list_free (switch_buttons);
657d8e
+
657d8e
+  if (next_mode < 0 || next_mode > n_modes)
657d8e
+    return FALSE;
657d8e
+
657d8e
+  *mode = next_mode;
657d8e
+  return TRUE;
657d8e
+}
657d8e
+
657d8e
 void
657d8e
 clutter_input_device_xi2_update_pad_state (ClutterInputDevice *device,
657d8e
                                            guint               button,
657d8e
@@ -330,23 +381,21 @@ clutter_input_device_xi2_update_pad_state (ClutterInputDevice *device,
657d8e
   gboolean is_mode_switch = FALSE;
657d8e
 
657d8e
   button_group = clutter_input_device_xi2_get_button_group (device, button);
657d8e
-  is_mode_switch = button_group >= 0;
657d8e
 
657d8e
-  /* Assign all non-mode-switch buttons to group 0 so far */
657d8e
-  button_group = MAX (0, button_group);
657d8e
-
657d8e
-  if (button_group >= device_xi2->group_modes->len)
657d8e
-    return;
657d8e
+  if (button_group < 0 || button_group >= device_xi2->group_modes->len)
657d8e
+    {
657d8e
+      *group = *mode = 0;
657d8e
+      return;
657d8e
+    }
657d8e
 
657d8e
   group_mode = &g_array_index (device_xi2->group_modes, guint, button_group);
657d8e
 
657d8e
-  if (is_mode_switch && state)
657d8e
+  if (state)
657d8e
     {
657d8e
-      guint next, n_modes;
657d8e
+      uint32_t next_mode;
657d8e
 
657d8e
-      n_modes = clutter_input_device_get_group_n_modes (device, button_group);
657d8e
-      next = (*group_mode + 1) % n_modes;
657d8e
-      *group_mode = next;
657d8e
+      if (pad_switch_mode (device, button, button_group, &next_mode))
657d8e
+        *group_mode = next_mode;
657d8e
     }
657d8e
 
657d8e
   if (group)
657d8e
-- 
657d8e
2.23.0
657d8e