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

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