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

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