[mutter/wip/carlosg/input-thread: 125/130] clutter: Add vmethod to find out group for pad features




commit bb40a1408e952eeee7a33f419bf658ee9a124459
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Nov 19 18:51:58 2020 +0100

    clutter: Add vmethod to find out group for pad features
    
    Do it so the wayland bits don't have to access native input devices
    internals. The data is still readonly, idempotent, etc.

 clutter/clutter/clutter-enums.h                |  7 +++
 clutter/clutter/clutter-input-device.c         | 46 +++++++++++++++++
 clutter/clutter/clutter-input-device.h         | 12 +++++
 src/backends/native/meta-input-device-native.c | 52 +++++++++++++++++---
 src/wayland/meta-wayland-tablet-pad-group.c    | 30 +++---------
 src/wayland/meta-wayland-tablet-pad.c          | 68 ++++----------------------
 6 files changed, 127 insertions(+), 88 deletions(-)
---
diff --git a/clutter/clutter/clutter-enums.h b/clutter/clutter/clutter-enums.h
index bcc848b383..9b0c29fa0c 100644
--- a/clutter/clutter/clutter-enums.h
+++ b/clutter/clutter/clutter-enums.h
@@ -1611,6 +1611,13 @@ typedef enum
   CLUTTER_INPUT_DEVICE_PAD_SOURCE_FINGER,
 } ClutterInputDevicePadSource;
 
+typedef enum
+{
+  CLUTTER_PAD_FEATURE_BUTTON,
+  CLUTTER_PAD_FEATURE_RING,
+  CLUTTER_PAD_FEATURE_STRIP,
+} ClutterInputDevicePadFeature;
+
 typedef enum
 {
   CLUTTER_INPUT_CONTENT_HINT_COMPLETION          = 1 << 0,
diff --git a/clutter/clutter/clutter-input-device.c b/clutter/clutter/clutter-input-device.c
index 87c8a6820e..a6df006438 100644
--- a/clutter/clutter/clutter-input-device.c
+++ b/clutter/clutter/clutter-input-device.c
@@ -67,6 +67,7 @@ enum
   PROP_N_STRIPS,
   PROP_N_RINGS,
   PROP_N_MODE_GROUPS,
+  PROP_N_BUTTONS,
   PROP_DEVICE_NODE,
 
   PROP_LAST
@@ -100,6 +101,7 @@ struct _ClutterInputDevicePrivate
   int n_rings;
   int n_strips;
   int n_mode_groups;
+  int n_buttons;
 
   gboolean has_cursor;
 };
@@ -216,6 +218,10 @@ clutter_input_device_set_property (GObject      *gobject,
       priv->n_mode_groups = g_value_get_int (value);
       break;
 
+    case PROP_N_BUTTONS:
+      priv->n_buttons = g_value_get_int (value);
+      break;
+
     case PROP_DEVICE_NODE:
       priv->node_path = g_value_dup_string (value);
       break;
@@ -282,6 +288,10 @@ clutter_input_device_get_property (GObject    *gobject,
       g_value_set_int (value, priv->n_mode_groups);
       break;
 
+    case PROP_N_BUTTONS:
+      g_value_set_int (value, priv->n_buttons);
+      break;
+
     case PROP_DEVICE_NODE:
       g_value_set_string (value, priv->node_path);
       break;
@@ -432,6 +442,13 @@ clutter_input_device_class_init (ClutterInputDeviceClass *klass)
                       0, G_MAXINT, 0,
                       CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
 
+  obj_props[PROP_N_BUTTONS] =
+    g_param_spec_int ("n-buttons",
+                      P_("Number of buttons"),
+                      P_("Number of buttons"),
+                      0, G_MAXINT, 0,
+                      CLUTTER_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY);
+
   obj_props[PROP_DEVICE_NODE] =
     g_param_spec_string ("device-node",
                          P_("Device node path"),
@@ -1236,6 +1253,19 @@ clutter_input_device_get_n_mode_groups (ClutterInputDevice *device)
   return priv->n_mode_groups;
 }
 
+gint
+clutter_input_device_get_n_buttons (ClutterInputDevice *device)
+{
+  ClutterInputDevicePrivate *priv =
+    clutter_input_device_get_instance_private (device);
+
+  g_return_val_if_fail (CLUTTER_IS_INPUT_DEVICE (device), 0);
+  g_return_val_if_fail (clutter_input_device_get_device_type (device) ==
+                        CLUTTER_PAD_DEVICE, 0);
+
+  return priv->n_buttons;
+}
+
 gint
 clutter_input_device_get_group_n_modes (ClutterInputDevice *device,
                                         gint                group)
@@ -1295,6 +1325,22 @@ clutter_input_device_get_mode_switch_button_group (ClutterInputDevice *device,
   return -1;
 }
 
+int
+clutter_input_device_get_pad_feature_group (ClutterInputDevice           *device,
+                                            ClutterInputDevicePadFeature  feature,
+                                            int                           n_feature)
+{
+  ClutterInputDeviceClass *device_class;
+
+  device_class = CLUTTER_INPUT_DEVICE_GET_CLASS (device);
+  if (!device_class->get_pad_feature_group)
+    return 0;
+
+  return CLUTTER_INPUT_DEVICE_GET_CLASS (device)->get_pad_feature_group (device,
+                                                                         feature,
+                                                                         n_feature);
+}
+
 const gchar *
 clutter_input_device_get_device_node (ClutterInputDevice *device)
 {
diff --git a/clutter/clutter/clutter-input-device.h b/clutter/clutter/clutter-input-device.h
index c2a2521cee..28ab0443b3 100644
--- a/clutter/clutter/clutter-input-device.h
+++ b/clutter/clutter/clutter-input-device.h
@@ -50,6 +50,10 @@ struct _ClutterInputDeviceClass
   gboolean (* is_grouped) (ClutterInputDevice *device,
                            ClutterInputDevice *other_device);
 
+  int (* get_pad_feature_group) (ClutterInputDevice           *device,
+                                 ClutterInputDevicePadFeature  feature,
+                                 int                           n_feature);
+
   /* Keyboard accessbility */
   void (* process_kbd_a11y_event) (ClutterEvent               *event,
                                    ClutterInputDevice         *device,
@@ -128,6 +132,9 @@ CLUTTER_EXPORT
 gint                    clutter_input_device_get_n_strips       (ClutterInputDevice *device);
 CLUTTER_EXPORT
 gint                    clutter_input_device_get_n_mode_groups  (ClutterInputDevice *device);
+CLUTTER_EXPORT
+int                     clutter_input_device_get_n_buttons (ClutterInputDevice *device);
+
 
 CLUTTER_EXPORT
 gint                    clutter_input_device_get_group_n_modes  (ClutterInputDevice *device,
@@ -150,6 +157,11 @@ gboolean                  clutter_input_device_is_grouped       (ClutterInputDev
 CLUTTER_EXPORT
 ClutterSeat *             clutter_input_device_get_seat         (ClutterInputDevice *device);
 
+CLUTTER_EXPORT
+int clutter_input_device_get_pad_feature_group (ClutterInputDevice           *device,
+                                                ClutterInputDevicePadFeature  feature,
+                                                int                           n_feature);
+
 G_END_DECLS
 
 #endif /* __CLUTTER_INPUT_DEVICE_H__ */
diff --git a/src/backends/native/meta-input-device-native.c b/src/backends/native/meta-input-device-native.c
index ec571cff01..d7e7299a18 100644
--- a/src/backends/native/meta-input-device-native.c
+++ b/src/backends/native/meta-input-device-native.c
@@ -160,6 +160,43 @@ meta_input_device_native_is_grouped (ClutterInputDevice *device,
     libinput_device_get_device_group (other_libinput_device);
 }
 
+static int
+meta_input_device_native_get_pad_feature_group (ClutterInputDevice           *device,
+                                                ClutterInputDevicePadFeature  feature,
+                                                int                           n_feature)
+{
+  struct libinput_device *libinput_device;
+  struct libinput_tablet_pad_mode_group *mode_group;
+  int n_groups, i;
+
+  libinput_device = meta_input_device_native_get_libinput_device (device);
+  n_groups = libinput_device_tablet_pad_get_num_mode_groups (libinput_device);
+
+  for (i = 0; i < n_groups; i++)
+    {
+      mode_group =
+        libinput_device_tablet_pad_get_mode_group (libinput_device, i);
+
+      switch (feature)
+        {
+        case CLUTTER_PAD_FEATURE_BUTTON:
+          if (libinput_tablet_pad_mode_group_has_button (mode_group, n_feature))
+            return i;
+          break;
+        case CLUTTER_PAD_FEATURE_RING:
+          if (libinput_tablet_pad_mode_group_has_ring (mode_group, n_feature))
+            return i;
+          break;
+        case CLUTTER_PAD_FEATURE_STRIP:
+          if (libinput_tablet_pad_mode_group_has_strip (mode_group, n_feature))
+            return i;
+          break;
+        }
+    }
+
+  return -1;
+}
+
 static void
 meta_input_device_native_bell_notify (MetaInputDeviceNative *device)
 {
@@ -1183,17 +1220,18 @@ meta_input_device_native_a11y_maybe_notify_toggle_keys (MetaInputDeviceNative *d
 static void
 meta_input_device_native_class_init (MetaInputDeviceNativeClass *klass)
 {
-  ClutterInputDeviceClass *device_manager_class = CLUTTER_INPUT_DEVICE_CLASS (klass);
+  ClutterInputDeviceClass *device_class = CLUTTER_INPUT_DEVICE_CLASS (klass);
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
   object_class->finalize = meta_input_device_native_finalize;
   object_class->set_property = meta_input_device_native_set_property;
   object_class->get_property = meta_input_device_native_get_property;
 
-  device_manager_class->is_mode_switch_button = meta_input_device_native_is_mode_switch_button;
-  device_manager_class->get_group_n_modes = meta_input_device_native_get_group_n_modes;
-  device_manager_class->is_grouped = meta_input_device_native_is_grouped;
-  device_manager_class->process_kbd_a11y_event = meta_input_device_native_process_kbd_a11y_event;
+  device_class->is_mode_switch_button = meta_input_device_native_is_mode_switch_button;
+  device_class->get_group_n_modes = meta_input_device_native_get_group_n_modes;
+  device_class->is_grouped = meta_input_device_native_is_grouped;
+  device_class->get_pad_feature_group = meta_input_device_native_get_pad_feature_group;
+  device_class->process_kbd_a11y_event = meta_input_device_native_process_kbd_a11y_event;
 
   obj_props[PROP_DEVICE_MATRIX] =
     g_param_spec_boxed ("device-matrix",
@@ -1235,7 +1273,7 @@ meta_input_device_native_new (MetaSeatImpl           *seat_impl,
   MetaInputDeviceNative *device;
   ClutterInputDeviceType type;
   char *vendor, *product;
-  int n_rings = 0, n_strips = 0, n_groups = 1;
+  int n_rings = 0, n_strips = 0, n_groups = 1, n_buttons = 0;
   char *node_path;
   double width, height;
 
@@ -1250,6 +1288,7 @@ meta_input_device_native_new (MetaSeatImpl           *seat_impl,
       n_rings = libinput_device_tablet_pad_get_num_rings (libinput_device);
       n_strips = libinput_device_tablet_pad_get_num_strips (libinput_device);
       n_groups = libinput_device_tablet_pad_get_num_mode_groups (libinput_device);
+      n_buttons = libinput_device_tablet_pad_get_num_buttons (libinput_device);
     }
 
   device = g_object_new (META_TYPE_INPUT_DEVICE_NATIVE,
@@ -1261,6 +1300,7 @@ meta_input_device_native_new (MetaSeatImpl           *seat_impl,
                          "n-rings", n_rings,
                          "n-strips", n_strips,
                          "n-mode-groups", n_groups,
+                         "n-buttons", n_buttons,
                          "device-node", node_path,
                          "seat", seat_impl->seat_native,
                          NULL);
diff --git a/src/wayland/meta-wayland-tablet-pad-group.c b/src/wayland/meta-wayland-tablet-pad-group.c
index 4229f834a7..46d3d21fc5 100644
--- a/src/wayland/meta-wayland-tablet-pad-group.c
+++ b/src/wayland/meta-wayland-tablet-pad-group.c
@@ -32,12 +32,6 @@
 #include "wayland/meta-wayland-tablet-pad.h"
 #include "wayland/meta-wayland-tablet-seat.h"
 
-#ifdef HAVE_NATIVE_BACKEND
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-event-native.h"
-#include "backends/native/meta-input-device-native.h"
-#endif
-
 #include "tablet-unstable-v2-server-protocol.h"
 
 static void
@@ -123,26 +117,14 @@ gboolean
 meta_wayland_tablet_pad_group_has_button (MetaWaylandTabletPadGroup *group,
                                           guint                      button)
 {
-#ifdef HAVE_NATIVE_BACKEND
-  MetaBackend *backend = meta_get_backend ();
-
-  if (META_IS_BACKEND_NATIVE (backend))
-    {
-      struct libinput_device *libinput_device;
-      struct libinput_tablet_pad_mode_group *mode_group;
-      guint n_group;
+  int n_group = g_list_index (group->pad->groups, group);
 
-      libinput_device = meta_input_device_native_get_libinput_device (group->pad->device);
-      n_group = g_list_index (group->pad->groups, group);
-      mode_group = libinput_device_tablet_pad_get_mode_group (libinput_device, n_group);
+  if (clutter_input_device_get_pad_feature_group (group->pad->device,
+                                                  CLUTTER_PAD_FEATURE_BUTTON,
+                                                  button) == n_group)
+    return TRUE;
 
-      return libinput_tablet_pad_mode_group_has_button (mode_group, button);
-    }
-  else
-#endif
-    {
-      return g_list_length (group->pad->groups) == 1;
-    }
+  return FALSE;
 }
 
 static void
diff --git a/src/wayland/meta-wayland-tablet-pad.c b/src/wayland/meta-wayland-tablet-pad.c
index d96bdfed45..22704aee73 100644
--- a/src/wayland/meta-wayland-tablet-pad.c
+++ b/src/wayland/meta-wayland-tablet-pad.c
@@ -38,12 +38,6 @@
 #include "wayland/meta-wayland-tablet-seat.h"
 #include "wayland/meta-wayland-tablet.h"
 
-#ifdef HAVE_NATIVE_BACKEND
-#include <libinput.h>
-#include "backends/native/meta-backend-native.h"
-#include "backends/native/meta-input-device-native.h"
-#endif
-
 #include "tablet-unstable-v2-server-protocol.h"
 
 static void
@@ -66,41 +60,20 @@ group_rings_strips (MetaWaylandTabletPad *pad)
 {
   gint n_group, n_elem;
   GList *g, *l;
-#ifdef HAVE_NATIVE_BACKEND
-  MetaBackend *backend = meta_get_backend ();
-  struct libinput_device *libinput_device = NULL;
-
-  if (META_IS_BACKEND_NATIVE (backend))
-    libinput_device = meta_input_device_native_get_libinput_device (pad->device);
-#endif
 
   for (n_group = 0, g = pad->groups; g; g = g->next)
     {
       MetaWaylandTabletPadGroup *group = g->data;
-#ifdef HAVE_NATIVE_BACKEND
-      struct libinput_tablet_pad_mode_group *mode_group = NULL;
-
-      if (libinput_device)
-        mode_group = libinput_device_tablet_pad_get_mode_group (libinput_device, n_group);
-#endif
 
       for (n_elem = 0, l = pad->rings; l; l = l->next)
         {
           MetaWaylandTabletPadRing *ring = l->data;
 
-#ifdef HAVE_NATIVE_BACKEND
-          if (mode_group)
-            {
-              if (libinput_tablet_pad_mode_group_has_ring (mode_group, n_elem))
-                meta_wayland_tablet_pad_ring_set_group (ring, group);
-            }
-          else
-#endif
-            {
-              /* Assign everything to the first group */
-              if (n_group == 0)
-                meta_wayland_tablet_pad_ring_set_group (ring, group);
-            }
+          if (clutter_input_device_get_pad_feature_group (pad->device,
+                                                          CLUTTER_PAD_FEATURE_RING,
+                                                          n_elem) == n_group)
+            meta_wayland_tablet_pad_ring_set_group (ring, group);
+
           n_elem++;
         }
 
@@ -108,19 +81,10 @@ group_rings_strips (MetaWaylandTabletPad *pad)
         {
           MetaWaylandTabletPadStrip *strip = l->data;
 
-#ifdef HAVE_NATIVE_BACKEND
-          if (mode_group)
-            {
-              if (libinput_tablet_pad_mode_group_has_strip (mode_group, n_elem))
-                meta_wayland_tablet_pad_strip_set_group (strip, group);
-            }
-          else
-#endif
-            {
-              /* Assign everything to the first group */
-              if (n_group == 0)
-                meta_wayland_tablet_pad_strip_set_group (strip, group);
-            }
+          if (clutter_input_device_get_pad_feature_group (pad->device,
+                                                          CLUTTER_PAD_FEATURE_STRIP,
+                                                          n_elem) == n_group)
+            meta_wayland_tablet_pad_strip_set_group (strip, group);
 
           n_elem++;
         }
@@ -133,9 +97,6 @@ MetaWaylandTabletPad *
 meta_wayland_tablet_pad_new (ClutterInputDevice    *device,
                              MetaWaylandTabletSeat *tablet_seat)
 {
-#ifdef HAVE_NATIVE_BACKEND
-  MetaBackend *backend = meta_get_backend ();
-#endif
   MetaWaylandTabletPad *pad;
   guint n_elems, i;
 
@@ -149,16 +110,7 @@ meta_wayland_tablet_pad_new (ClutterInputDevice    *device,
   pad->feedback = g_hash_table_new_full (NULL, NULL, NULL,
                                          (GDestroyNotify) g_free);
 
-#ifdef HAVE_NATIVE_BACKEND
-  /* Buttons, only can be honored this with the native backend */
-  if (META_IS_BACKEND_NATIVE (backend))
-    {
-      struct libinput_device *libinput_device;
-
-      libinput_device = meta_input_device_native_get_libinput_device (device);
-      pad->n_buttons = libinput_device_tablet_pad_get_num_buttons (libinput_device);
-    }
-#endif
+  pad->n_buttons = clutter_input_device_get_n_buttons (device);
 
   n_elems = clutter_input_device_get_n_mode_groups (pad->device);
 


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