[mutter/wip/tablet-protocol-v2: 143/149] wayland: Move strips/rings management back to MetaWaylandTabletPad



commit edda88a7dddce5284ac344cb3bf69f3cd18d67ab
Author: Carlos Garnacho <carlosg gnome org>
Date:   Thu Jun 30 18:42:08 2016 +0200

    wayland: Move strips/rings management back to MetaWaylandTabletPad
    
    This is best for 2 reasons:
    - It's feels cleaner doing first creation of rings/strips and then
      the group assignment. The other option is making groups iterate
      other all rings/strips and selectively skip those not meant for
      it, which sounds somewhat redundant.
    - Some minimal accounting of rings/strips without group restrictions
      is needed for meta_wayland_tablet_pad_get_label().
    
    The rings/strips memory is now owned by MetaWaylandTabletPad instead
    of groups, which is sort of meaningless since all are meant to go
    at the same time.

 src/wayland/meta-wayland-tablet-pad-group.c |   23 ------
 src/wayland/meta-wayland-tablet-pad.c       |  103 ++++++++++++++++++++++++++-
 src/wayland/meta-wayland-tablet-pad.h       |    2 +
 3 files changed, 102 insertions(+), 26 deletions(-)
---
diff --git a/src/wayland/meta-wayland-tablet-pad-group.c b/src/wayland/meta-wayland-tablet-pad-group.c
index b8314c9..61b36c7 100644
--- a/src/wayland/meta-wayland-tablet-pad-group.c
+++ b/src/wayland/meta-wayland-tablet-pad-group.c
@@ -50,29 +50,12 @@ MetaWaylandTabletPadGroup *
 meta_wayland_tablet_pad_group_new (MetaWaylandTabletPad *pad)
 {
   MetaWaylandTabletPadGroup *group;
-  guint n_elems, i;
 
   group = g_slice_new0 (MetaWaylandTabletPadGroup);
   wl_list_init (&group->resource_list);
   wl_list_init (&group->focus_resource_list);
   group->pad = pad;
 
-  n_elems = clutter_input_device_get_n_rings (pad->device);
-
-  for (i = 0; i < n_elems; i++)
-    {
-      group->rings = g_list_prepend (group->rings,
-                                     meta_wayland_tablet_pad_ring_new (pad));
-    }
-
-  n_elems = clutter_input_device_get_n_strips (pad->device);
-
-  for (i = 0; i < n_elems; i++)
-    {
-      group->strips = g_list_prepend (group->strips,
-                                      meta_wayland_tablet_pad_strip_new (pad));
-    }
-
   return group;
 }
 
@@ -80,7 +63,6 @@ void
 meta_wayland_tablet_pad_group_free (MetaWaylandTabletPadGroup *group)
 {
   struct wl_resource *resource, *next;
-  GList *l;
 
   wl_resource_for_each_safe (resource, next, &group->resource_list)
     {
@@ -88,11 +70,6 @@ meta_wayland_tablet_pad_group_free (MetaWaylandTabletPadGroup *group)
       wl_list_init (wl_resource_get_link (resource));
     }
 
-  for (l = group->rings; l; l = l->next)
-    meta_wayland_tablet_pad_ring_free (l->data);
-  for (l = group->strips; l; l = l->next)
-    meta_wayland_tablet_pad_strip_free (l->data);
-
   g_list_free (group->rings);
   g_list_free (group->strips);
 
diff --git a/src/wayland/meta-wayland-tablet-pad.c b/src/wayland/meta-wayland-tablet-pad.c
index b597d28..0e1bace 100644
--- a/src/wayland/meta-wayland-tablet-pad.c
+++ b/src/wayland/meta-wayland-tablet-pad.c
@@ -61,13 +61,82 @@ pad_handle_focus_surface_destroy (struct wl_listener *listener,
   meta_wayland_tablet_pad_set_focus (pad, NULL);
 }
 
+static void
+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 = clutter_evdev_input_device_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
+#else
+            {
+              /* Assign everything to the first group */
+              if (n_group == 0)
+                meta_wayland_tablet_pad_ring_set_group (ring, group);
+            }
+#endif
+          n_elem++;
+        }
+
+      for (n_elem = 0, l = pad->strips; l; l = l->next)
+        {
+          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
+#else
+            {
+              /* Assign everything to the first group */
+              if (n_group == 0)
+                meta_wayland_tablet_pad_strip_set_group (strip, group);
+            }
+#endif
+          n_elem++;
+        }
+
+      n_group++;
+    }
+}
+
 MetaWaylandTabletPad *
 meta_wayland_tablet_pad_new (ClutterInputDevice    *device,
                              MetaWaylandTabletSeat *tablet_seat)
 {
   MetaBackend *backend = meta_get_backend ();
   MetaWaylandTabletPad *pad;
-  guint n_mode_groups, i;
+  guint n_elems, i;
 
   pad = g_slice_new0 (MetaWaylandTabletPad);
   wl_list_init (&pad->resource_list);
@@ -90,14 +159,36 @@ meta_wayland_tablet_pad_new (ClutterInputDevice    *device,
     }
 #endif
 
-  n_mode_groups = clutter_input_device_get_n_mode_groups (pad->device);
+  n_elems = clutter_input_device_get_n_mode_groups (pad->device);
 
-  for (i = 0; i < n_mode_groups; i++)
+  for (i = 0; i < n_elems; i++)
     {
       pad->groups = g_list_prepend (pad->groups,
                                     meta_wayland_tablet_pad_group_new (pad));
     }
 
+  n_elems = clutter_input_device_get_n_rings (pad->device);
+
+  for (i = 0; i < n_elems; i++)
+    {
+      MetaWaylandTabletPadRing *ring;
+
+      ring = meta_wayland_tablet_pad_ring_new (pad);
+      pad->rings = g_list_prepend (pad->rings, ring);
+    }
+
+  n_elems = clutter_input_device_get_n_strips (pad->device);
+
+  for (i = 0; i < n_elems; i++)
+    {
+      MetaWaylandTabletPadStrip *strip;
+
+      strip = meta_wayland_tablet_pad_strip_new (pad);
+      pad->strips = g_list_prepend (pad->strips, strip);
+    }
+
+  group_rings_strips (pad);
+
   return pad;
 }
 
@@ -118,8 +209,14 @@ meta_wayland_tablet_pad_free (MetaWaylandTabletPad *pad)
 
   for (l = pad->groups; l; l = l->next)
     meta_wayland_tablet_pad_group_free (l->data);
+  for (l = pad->rings; l; l = l->next)
+    meta_wayland_tablet_pad_ring_free (l->data);
+  for (l = pad->strips; l; l = l->next)
+    meta_wayland_tablet_pad_strip_free (l->data);
 
   g_list_free (pad->groups);
+  g_list_free (pad->rings);
+  g_list_free (pad->strips);
   g_hash_table_destroy (pad->feedback);
 
   g_slice_free (MetaWaylandTabletPad, pad);
diff --git a/src/wayland/meta-wayland-tablet-pad.h b/src/wayland/meta-wayland-tablet-pad.h
index 72a66ec..b78335a 100644
--- a/src/wayland/meta-wayland-tablet-pad.h
+++ b/src/wayland/meta-wayland-tablet-pad.h
@@ -43,6 +43,8 @@ struct _MetaWaylandTabletPad
 
   uint32_t n_buttons;
   GList *groups;
+  GList *rings;
+  GList *strips;
 
   GHashTable *feedback;
 


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