gdk/wayland: Split GdkDevicePad wayland implementation
authorCarlos Garnacho <carlosg@gnome.org>
Thu, 2 Feb 2023 17:06:52 +0000 (18:06 +0100)
committerCarlos Garnacho <carlosg@gnome.org>
Fri, 3 Feb 2023 15:08:07 +0000 (16:08 +0100)
This now lives in its own C file.

gdk/wayland/gdkdevice-wayland-private.h
gdk/wayland/gdkdevicepad-wayland.c [new file with mode: 0644]
gdk/wayland/gdkseat-wayland.c
gdk/wayland/meson.build

index e9c0f9517c1c1ba3a6b76a4ac9dbbd4482713005..5f43cd1fda50212c370e4903c80c1efe667db5e9 100644 (file)
@@ -217,6 +217,9 @@ struct _GdkWaylandSeat
   GdkCursor *grab_cursor;
 };
 
+#define GDK_TYPE_WAYLAND_DEVICE_PAD (gdk_wayland_device_pad_get_type ())
+GType gdk_wayland_device_pad_get_type (void);
+
 void gdk_wayland_device_query_state (GdkDevice        *device,
                                      GdkSurface       *surface,
                                      double           *win_x,
@@ -228,4 +231,7 @@ void gdk_wayland_device_pad_set_feedback (GdkDevice           *device,
                                           guint                feature_idx,
                                           const char          *label);
 
+GdkWaylandTabletPadData * gdk_wayland_seat_find_pad (GdkWaylandSeat *seat,
+                                                     GdkDevice      *device);
+
 #endif
diff --git a/gdk/wayland/gdkdevicepad-wayland.c b/gdk/wayland/gdkdevicepad-wayland.c
new file mode 100644 (file)
index 0000000..060e18c
--- /dev/null
@@ -0,0 +1,266 @@
+/* GDK - The GIMP Drawing Kit
+ * Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "config.h"
+
+#include "gdkwaylanddevice.h"
+#include "gdkdevice-wayland-private.h"
+
+#include "tablet-unstable-v2-client-protocol.h"
+
+#include <gdk/gdkdevicepadprivate.h>
+
+typedef struct _GdkWaylandDevicePad GdkWaylandDevicePad;
+typedef struct _GdkWaylandDevicePadClass GdkWaylandDevicePadClass;
+
+struct _GdkWaylandDevicePad
+{
+  GdkWaylandDevice parent_instance;
+};
+
+struct _GdkWaylandDevicePadClass
+{
+  GdkWaylandDeviceClass parent_class;
+};
+
+static void gdk_wayland_device_pad_iface_init (GdkDevicePadInterface *iface);
+
+G_DEFINE_TYPE_WITH_CODE (GdkWaylandDevicePad, gdk_wayland_device_pad,
+                         GDK_TYPE_WAYLAND_DEVICE,
+                         G_IMPLEMENT_INTERFACE (GDK_TYPE_DEVICE_PAD,
+                                                gdk_wayland_device_pad_iface_init))
+
+static int
+gdk_wayland_device_pad_get_n_groups (GdkDevicePad *pad)
+{
+  GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad));
+  GdkWaylandTabletPadData *data;
+
+  data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
+                                    GDK_DEVICE (pad));
+#ifdef G_DISABLE_ASSERT
+  if (data == NULL)
+    return 0;
+#else
+  g_assert (data != NULL);
+#endif
+
+  return g_list_length (data->mode_groups);
+}
+
+static int
+gdk_wayland_device_pad_get_group_n_modes (GdkDevicePad *pad,
+                                          int           n_group)
+{
+  GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad));
+  GdkWaylandTabletPadGroupData *group;
+  GdkWaylandTabletPadData *data;
+
+  data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
+                                    GDK_DEVICE (pad));
+#ifdef G_DISABLE_ASSERT
+  if (data == NULL)
+    return 0;
+#else
+  g_assert (data != NULL);
+#endif
+
+  group = g_list_nth_data (data->mode_groups, n_group);
+  if (!group)
+    return -1;
+
+  return group->n_modes;
+}
+
+static int
+gdk_wayland_device_pad_get_n_features (GdkDevicePad        *pad,
+                                       GdkDevicePadFeature  feature)
+{
+  GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad));
+  GdkWaylandTabletPadData *data;
+
+  data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
+                                    GDK_DEVICE (pad));
+  g_assert (data != NULL);
+
+  switch (feature)
+    {
+    case GDK_DEVICE_PAD_FEATURE_BUTTON:
+      return data->n_buttons;
+    case GDK_DEVICE_PAD_FEATURE_RING:
+      return g_list_length (data->rings);
+    case GDK_DEVICE_PAD_FEATURE_STRIP:
+      return g_list_length (data->strips);
+    default:
+      return -1;
+    }
+}
+
+static int
+gdk_wayland_device_pad_get_feature_group (GdkDevicePad        *pad,
+                                          GdkDevicePadFeature  feature,
+                                          int                  idx)
+{
+  GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad));
+  GdkWaylandTabletPadGroupData *group;
+  GdkWaylandTabletPadData *data;
+  GList *l;
+  int i;
+
+  data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
+                                    GDK_DEVICE (pad));
+#ifdef G_DISABLE_ASSERT
+  if (data == NULL)
+    return -1;
+#else
+  g_assert (data != NULL);
+#endif
+
+  for (l = data->mode_groups, i = 0; l; l = l->next, i++)
+    {
+      group = l->data;
+
+      switch (feature)
+        {
+        case GDK_DEVICE_PAD_FEATURE_BUTTON:
+          if (g_list_find (group->buttons, GINT_TO_POINTER (idx)))
+            return i;
+          break;
+        case GDK_DEVICE_PAD_FEATURE_RING:
+          {
+            gpointer ring;
+
+            ring = g_list_nth_data (data->rings, idx);
+            if (ring && g_list_find (group->rings, ring))
+              return i;
+            break;
+          }
+        case GDK_DEVICE_PAD_FEATURE_STRIP:
+          {
+            gpointer strip;
+            strip = g_list_nth_data (data->strips, idx);
+            if (strip && g_list_find (group->strips, strip))
+              return i;
+            break;
+          }
+        default:
+          break;
+        }
+    }
+
+  return -1;
+}
+
+static void
+gdk_wayland_device_pad_iface_init (GdkDevicePadInterface *iface)
+{
+  iface->get_n_groups = gdk_wayland_device_pad_get_n_groups;
+  iface->get_group_n_modes = gdk_wayland_device_pad_get_group_n_modes;
+  iface->get_n_features = gdk_wayland_device_pad_get_n_features;
+  iface->get_feature_group = gdk_wayland_device_pad_get_feature_group;
+}
+
+static void
+gdk_wayland_device_pad_class_init (GdkWaylandDevicePadClass *klass)
+{
+}
+
+static void
+gdk_wayland_device_pad_init (GdkWaylandDevicePad *pad)
+{
+}
+
+static GdkWaylandTabletPadGroupData *
+tablet_pad_lookup_button_group (GdkWaylandTabletPadData *pad,
+                                uint32_t                 button)
+{
+  GdkWaylandTabletPadGroupData *group;
+  GList *l;
+
+  for (l = pad->mode_groups; l; l = l->next)
+    {
+      group = l->data;
+
+      if (g_list_find (group->buttons, GUINT_TO_POINTER (button)))
+        return group;
+    }
+
+  return NULL;
+}
+
+/*<private>
+ * gdk_wayland_device_pad_set_feedback:
+ * @device: (type GdkWaylandDevice): a %GDK_SOURCE_TABLET_PAD device
+ * @feature: Feature to set the feedback label for
+ * @feature_idx: 0-indexed index of the feature to set the feedback label for
+ * @label: Feedback label
+ *
+ * Sets the feedback label for the given feature/index.
+ *
+ * This may be used by the compositor to provide user feedback
+ * of the actions available/performed.
+ */
+void
+gdk_wayland_device_pad_set_feedback (GdkDevice           *device,
+                                     GdkDevicePadFeature  feature,
+                                     guint                feature_idx,
+                                     const char          *label)
+{
+  GdkWaylandTabletPadData *pad;
+  GdkWaylandTabletPadGroupData *group;
+  GdkSeat *seat;
+
+  seat = gdk_device_get_seat (device);
+  pad = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat), device);
+  if (!pad)
+    return;
+
+  if (feature == GDK_DEVICE_PAD_FEATURE_BUTTON)
+    {
+      group = tablet_pad_lookup_button_group (pad, feature_idx);
+      if (!group)
+        return;
+
+      zwp_tablet_pad_v2_set_feedback (pad->wp_tablet_pad, feature_idx, label,
+                                      group->mode_switch_serial);
+    }
+  else if (feature == GDK_DEVICE_PAD_FEATURE_RING)
+    {
+      struct zwp_tablet_pad_ring_v2 *wp_pad_ring;
+
+      wp_pad_ring = g_list_nth_data (pad->rings, feature_idx);
+      if (!wp_pad_ring)
+        return;
+
+      group = zwp_tablet_pad_ring_v2_get_user_data (wp_pad_ring);
+      zwp_tablet_pad_ring_v2_set_feedback (wp_pad_ring, label,
+                                           group->mode_switch_serial);
+
+    }
+  else if (feature == GDK_DEVICE_PAD_FEATURE_STRIP)
+    {
+      struct zwp_tablet_pad_strip_v2 *wp_pad_strip;
+
+      wp_pad_strip = g_list_nth_data (pad->strips, feature_idx);
+      if (!wp_pad_strip)
+        return;
+
+      group = zwp_tablet_pad_strip_v2_get_user_data (wp_pad_strip);
+      zwp_tablet_pad_strip_v2_set_feedback (wp_pad_strip, label,
+                                            group->mode_switch_serial);
+    }
+}
index 8c8f25534e87f11436cc0c7cb3b4ec3f0e2e2557..a5e1ca95f6c1da3ea2b242aa486c9d7975380287 100644 (file)
@@ -89,9 +89,6 @@
 
 #define GDK_SEAT_DEBUG(seat,type,...) GDK_DISPLAY_DEBUG(gdk_seat_get_display (GDK_SEAT (seat)),type,__VA_ARGS__)
 
-typedef struct _GdkWaylandDevicePad GdkWaylandDevicePad;
-typedef struct _GdkWaylandDevicePadClass GdkWaylandDevicePadClass;
-
 G_DEFINE_TYPE (GdkWaylandSeat, gdk_wayland_seat, GDK_TYPE_SEAT)
 
 typedef struct
@@ -102,30 +99,11 @@ typedef struct
 
 G_DEFINE_TYPE_WITH_PRIVATE (GdkWaylandDevice, gdk_wayland_device, GDK_TYPE_DEVICE)
 
-struct _GdkWaylandDevicePad
-{
-  GdkWaylandDevice parent_instance;
-};
-
-struct _GdkWaylandDevicePadClass
-{
-  GdkWaylandDeviceClass parent_class;
-};
-
-static void gdk_wayland_device_pad_iface_init (GdkDevicePadInterface *iface);
 static void init_pointer_data (GdkWaylandPointerData *pointer_data,
                                GdkDisplay            *display_wayland,
                                GdkDevice             *logical_device);
 static void pointer_surface_update_scale (GdkDevice *device);
 
-#define GDK_TYPE_WAYLAND_DEVICE_PAD (gdk_wayland_device_pad_get_type ())
-GType gdk_wayland_device_pad_get_type (void);
-
-G_DEFINE_TYPE_WITH_CODE (GdkWaylandDevicePad, gdk_wayland_device_pad,
-                         GDK_TYPE_WAYLAND_DEVICE,
-                         G_IMPLEMENT_INTERFACE (GDK_TYPE_DEVICE_PAD,
-                                                gdk_wayland_device_pad_iface_init))
-
 #define GDK_SLOT_TO_EVENT_SEQUENCE(s) ((GdkEventSequence *) GUINT_TO_POINTER((s) + 1))
 #define GDK_EVENT_SEQUENCE_TO_SLOT(s) (GPOINTER_TO_UINT(s) - 1)
 
@@ -166,7 +144,7 @@ gdk_wayland_seat_find_tablet (GdkWaylandSeat *seat,
   return NULL;
 }
 
-static GdkWaylandTabletPadData *
+GdkWaylandTabletPadData *
 gdk_wayland_seat_find_pad (GdkWaylandSeat *seat,
                            GdkDevice      *device)
 {
@@ -695,146 +673,6 @@ gdk_wayland_device_init (GdkWaylandDevice *device_core)
   _gdk_device_add_axis (device, GDK_AXIS_Y, 0, 0, 1);
 }
 
-static int
-gdk_wayland_device_pad_get_n_groups (GdkDevicePad *pad)
-{
-  GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad));
-  GdkWaylandTabletPadData *data;
-
-  data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
-                                    GDK_DEVICE (pad));
-#ifdef G_DISABLE_ASSERT
-  if (data == NULL)
-    return 0;
-#else
-  g_assert (data != NULL);
-#endif
-
-  return g_list_length (data->mode_groups);
-}
-
-static int
-gdk_wayland_device_pad_get_group_n_modes (GdkDevicePad *pad,
-                                          int           n_group)
-{
-  GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad));
-  GdkWaylandTabletPadGroupData *group;
-  GdkWaylandTabletPadData *data;
-
-  data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
-                                    GDK_DEVICE (pad));
-#ifdef G_DISABLE_ASSERT
-  if (data == NULL)
-    return 0;
-#else
-  g_assert (data != NULL);
-#endif
-
-  group = g_list_nth_data (data->mode_groups, n_group);
-  if (!group)
-    return -1;
-
-  return group->n_modes;
-}
-
-static int
-gdk_wayland_device_pad_get_n_features (GdkDevicePad        *pad,
-                                       GdkDevicePadFeature  feature)
-{
-  GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad));
-  GdkWaylandTabletPadData *data;
-
-  data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
-                                    GDK_DEVICE (pad));
-  g_assert (data != NULL);
-
-  switch (feature)
-    {
-    case GDK_DEVICE_PAD_FEATURE_BUTTON:
-      return data->n_buttons;
-    case GDK_DEVICE_PAD_FEATURE_RING:
-      return g_list_length (data->rings);
-    case GDK_DEVICE_PAD_FEATURE_STRIP:
-      return g_list_length (data->strips);
-    default:
-      return -1;
-    }
-}
-
-static int
-gdk_wayland_device_pad_get_feature_group (GdkDevicePad        *pad,
-                                          GdkDevicePadFeature  feature,
-                                          int                  idx)
-{
-  GdkSeat *seat = gdk_device_get_seat (GDK_DEVICE (pad));
-  GdkWaylandTabletPadGroupData *group;
-  GdkWaylandTabletPadData *data;
-  GList *l;
-  int i;
-
-  data = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat),
-                                    GDK_DEVICE (pad));
-#ifdef G_DISABLE_ASSERT
-  if (data == NULL)
-    return -1;
-#else
-  g_assert (data != NULL);
-#endif
-
-  for (l = data->mode_groups, i = 0; l; l = l->next, i++)
-    {
-      group = l->data;
-
-      switch (feature)
-        {
-        case GDK_DEVICE_PAD_FEATURE_BUTTON:
-          if (g_list_find (group->buttons, GINT_TO_POINTER (idx)))
-            return i;
-          break;
-        case GDK_DEVICE_PAD_FEATURE_RING:
-          {
-            gpointer ring;
-
-            ring = g_list_nth_data (data->rings, idx);
-            if (ring && g_list_find (group->rings, ring))
-              return i;
-            break;
-          }
-        case GDK_DEVICE_PAD_FEATURE_STRIP:
-          {
-            gpointer strip;
-            strip = g_list_nth_data (data->strips, idx);
-            if (strip && g_list_find (group->strips, strip))
-              return i;
-            break;
-          }
-        default:
-          break;
-        }
-    }
-
-  return -1;
-}
-
-static void
-gdk_wayland_device_pad_iface_init (GdkDevicePadInterface *iface)
-{
-  iface->get_n_groups = gdk_wayland_device_pad_get_n_groups;
-  iface->get_group_n_modes = gdk_wayland_device_pad_get_group_n_modes;
-  iface->get_n_features = gdk_wayland_device_pad_get_n_features;
-  iface->get_feature_group = gdk_wayland_device_pad_get_feature_group;
-}
-
-static void
-gdk_wayland_device_pad_class_init (GdkWaylandDevicePadClass *klass)
-{
-}
-
-static void
-gdk_wayland_device_pad_init (GdkWaylandDevicePad *pad)
-{
-}
-
 /**
  * gdk_wayland_device_get_wl_seat: (skip)
  * @device: (type GdkWaylandDevice): a `GdkDevice`
@@ -5251,66 +5089,3 @@ gdk_wayland_device_get_node_path (GdkDevice *device)
 
   return NULL;
 }
-
-/*<private>
- * gdk_wayland_device_pad_set_feedback:
- * @device: (type GdkWaylandDevice): a %GDK_SOURCE_TABLET_PAD device
- * @feature: Feature to set the feedback label for
- * @feature_idx: 0-indexed index of the feature to set the feedback label for
- * @label: Feedback label
- *
- * Sets the feedback label for the given feature/index.
- *
- * This may be used by the compositor to provide user feedback
- * of the actions available/performed.
- */
-void
-gdk_wayland_device_pad_set_feedback (GdkDevice           *device,
-                                     GdkDevicePadFeature  feature,
-                                     guint                feature_idx,
-                                     const char          *label)
-{
-  GdkWaylandTabletPadData *pad;
-  GdkWaylandTabletPadGroupData *group;
-  GdkSeat *seat;
-
-  seat = gdk_device_get_seat (device);
-  pad = gdk_wayland_seat_find_pad (GDK_WAYLAND_SEAT (seat), device);
-  if (!pad)
-    return;
-
-  if (feature == GDK_DEVICE_PAD_FEATURE_BUTTON)
-    {
-      group = tablet_pad_lookup_button_group (pad, feature_idx);
-      if (!group)
-        return;
-
-      zwp_tablet_pad_v2_set_feedback (pad->wp_tablet_pad, feature_idx, label,
-                                      group->mode_switch_serial);
-    }
-  else if (feature == GDK_DEVICE_PAD_FEATURE_RING)
-    {
-      struct zwp_tablet_pad_ring_v2 *wp_pad_ring;
-
-      wp_pad_ring = g_list_nth_data (pad->rings, feature_idx);
-      if (!wp_pad_ring)
-        return;
-
-      group = zwp_tablet_pad_ring_v2_get_user_data (wp_pad_ring);
-      zwp_tablet_pad_ring_v2_set_feedback (wp_pad_ring, label,
-                                           group->mode_switch_serial);
-
-    }
-  else if (feature == GDK_DEVICE_PAD_FEATURE_STRIP)
-    {
-      struct zwp_tablet_pad_strip_v2 *wp_pad_strip;
-
-      wp_pad_strip = g_list_nth_data (pad->strips, feature_idx);
-      if (!wp_pad_strip)
-        return;
-
-      group = zwp_tablet_pad_strip_v2_get_user_data (wp_pad_strip);
-      zwp_tablet_pad_strip_v2_set_feedback (wp_pad_strip, label,
-                                            group->mode_switch_serial);
-    }
-}
index 76a069975f7fbd679d5b4c12202976acad34d3ea..79a770c1f1060c1e8b88ef37ac3be83cee666bcc 100644 (file)
@@ -5,6 +5,7 @@ gdk_wayland_sources = files([
   'gdkcairocontext-wayland.c',
   'gdkclipboard-wayland.c',
   'gdkcursor-wayland.c',
+  'gdkdevicepad-wayland.c',
   'gdkdisplay-wayland.c',
   'gdkdrag-wayland.c',
   'gdkdragsurface-wayland.c',