[mutter/wip/carlosg/fix-issue-48: 2/2] clutter/x11: Communicate proper group/mode on pad events.



commit adb5170c7efd5474db6c51138749179fbd6c3d27
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Feb 22 17:50:42 2018 +0100

    clutter/x11: Communicate proper group/mode on pad events.
    
    So we can trigger actions for the right mode.
    
    https://gitlab.gnome.org/GNOME/mutter/issues/48
    
    Closes: #48

 clutter/clutter/x11/clutter-device-manager-xi2.c | 15 ++++++-
 clutter/clutter/x11/clutter-input-device-xi2.c   | 50 ++++++++++++++++++++++++
 clutter/clutter/x11/clutter-input-device-xi2.h   |  9 +++++
 3 files changed, 73 insertions(+), 1 deletion(-)
---
diff --git a/clutter/clutter/x11/clutter-device-manager-xi2.c 
b/clutter/clutter/x11/clutter-device-manager-xi2.c
index dee26042f..d269a38c1 100644
--- a/clutter/clutter/x11/clutter-device-manager-xi2.c
+++ b/clutter/clutter/x11/clutter-device-manager-xi2.c
@@ -1133,7 +1133,7 @@ translate_pad_event (ClutterEvent       *event,
                      ClutterInputDevice *device)
 {
   gdouble value;
-  guint number;
+  guint number, mode = 0;
 
   if (!translate_pad_axis (device, &xev->valuators,
                            &event->any.type,
@@ -1147,15 +1147,21 @@ translate_pad_event (ClutterEvent       *event,
   if (xev->evtype == XI_Motion)
     value = -1;
 
+#ifdef HAVE_LIBWACOM
+  mode = clutter_input_device_xi2_get_pad_group_mode (device, number);
+#endif
+
   if (event->any.type == CLUTTER_PAD_RING)
     {
       event->pad_ring.ring_number = number;
       event->pad_ring.angle = value;
+      event->pad_ring.mode = mode;
     }
   else
     {
       event->pad_strip.strip_number = number;
       event->pad_strip.value = value;
+      event->pad_strip.mode = mode;
     }
 
   event->any.time = xev->time;
@@ -1382,6 +1388,13 @@ clutter_device_manager_xi2_translate_event (ClutterEventTranslator *translator,
 
             /* Pad buttons are 0-indexed */
             event->pad_button.button = xev->detail - 1;
+#ifdef HAVE_LIBWACOM
+            clutter_input_device_xi2_update_pad_state (device,
+                                                       event->pad_button.button,
+                                                       (xi_event->evtype == XI_ButtonPress),
+                                                       &event->pad_button.group,
+                                                       &event->pad_button.mode);
+#endif
             clutter_event_set_device (event, device);
             clutter_event_set_source_device (event, source_device);
 
diff --git a/clutter/clutter/x11/clutter-input-device-xi2.c b/clutter/clutter/x11/clutter-input-device-xi2.c
index 2d9b6d238..695194dfd 100644
--- a/clutter/clutter/x11/clutter-input-device-xi2.c
+++ b/clutter/clutter/x11/clutter-input-device-xi2.c
@@ -49,6 +49,7 @@ struct _ClutterInputDeviceXI2
 #ifdef HAVE_LIBWACOM
   WacomDevice *wacom_device;
 #endif
+  GArray *group_modes;
 };
 
 #define N_BUTTONS       5
@@ -68,6 +69,13 @@ clutter_input_device_xi2_constructed (GObject *gobject)
 
   if (G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->constructed)
     G_OBJECT_CLASS (clutter_input_device_xi2_parent_class)->constructed (gobject);
+
+  if (clutter_input_device_get_device_type (CLUTTER_INPUT_DEVICE (gobject)) == CLUTTER_PAD_DEVICE)
+    {
+      device_xi2->group_modes = g_array_new (FALSE, TRUE, sizeof (guint));
+      g_array_set_size (device_xi2->group_modes,
+                        clutter_input_device_get_n_mode_groups (CLUTTER_INPUT_DEVICE (gobject)));
+    }
 }
 
 static gboolean
@@ -292,4 +300,46 @@ clutter_input_device_xi2_ensure_wacom_info (ClutterInputDevice  *device,
   device_xi2->wacom_device = libwacom_new_from_path (wacom_db, node_path,
                                                      WFALLBACK_NONE, NULL);
 }
+
+guint
+clutter_input_device_xi2_get_pad_group_mode (ClutterInputDevice *device,
+                                             guint               group)
+{
+  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
+
+  if (group >= clutter_input_device_get_n_mode_groups (device))
+    return 0;
+
+  return g_array_index (device_xi2->group_modes, guint, group);
+}
+
+void
+clutter_input_device_xi2_update_pad_state (ClutterInputDevice *device,
+                                           guint               button,
+                                           guint               state,
+                                           guint              *group,
+                                           guint              *mode)
+{
+  ClutterInputDeviceXI2 *device_xi2 = CLUTTER_INPUT_DEVICE_XI2 (device);
+  guint button_group, *group_mode, n_modes;
+  gboolean is_mode_switch = FALSE;
+
+  button_group = clutter_input_device_xi2_get_button_group (device, button);
+  is_mode_switch = button_group >= 0;
+
+  button_group = CLAMP (button_group, 0, n_modes);
+  n_modes = clutter_input_device_get_group_n_modes (device, button_group);
+  group_mode = &g_array_index (device_xi2->group_modes, guint, button_group);
+
+  if (is_mode_switch && state)
+    {
+      guint next = (*group_mode + 1) % n_modes;
+      *group_mode = next;
+    }
+
+  if (group)
+    *group = button_group;
+  if (mode)
+    *mode = *group_mode;
+}
 #endif
diff --git a/clutter/clutter/x11/clutter-input-device-xi2.h b/clutter/clutter/x11/clutter-input-device-xi2.h
index e30fb4d18..2194e1ba2 100644
--- a/clutter/clutter/x11/clutter-input-device-xi2.h
+++ b/clutter/clutter/x11/clutter-input-device-xi2.h
@@ -53,6 +53,15 @@ ClutterInputDeviceTool * clutter_input_device_xi2_get_current_tool (ClutterInput
 void clutter_input_device_xi2_ensure_wacom_info (ClutterInputDevice  *device,
                                                  WacomDeviceDatabase *wacom_db);
 
+guint clutter_input_device_xi2_get_pad_group_mode (ClutterInputDevice *device,
+                                                   guint               group);
+
+void clutter_input_device_xi2_update_pad_state (ClutterInputDevice *device,
+                                                guint               button,
+                                                guint               state,
+                                                guint              *group,
+                                                guint              *mode);
+
 #endif
 
 G_END_DECLS


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