From a5246a6856e136b48c6b2d0bb8b1a3ca35aa1bcc Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 2 Feb 2023 18:06:52 +0100 Subject: gdk/wayland: Split GdkDevicePad wayland implementation This now lives in its own C file. --- gdk/wayland/gdkdevice-wayland-private.h | 6 + gdk/wayland/gdkdevicepad-wayland.c | 266 ++++++++++++++++++++++++++++++++ gdk/wayland/gdkseat-wayland.c | 227 +-------------------------- gdk/wayland/meson.build | 1 + 4 files changed, 274 insertions(+), 226 deletions(-) create mode 100644 gdk/wayland/gdkdevicepad-wayland.c diff --git a/gdk/wayland/gdkdevice-wayland-private.h b/gdk/wayland/gdkdevice-wayland-private.h index e9c0f9517c..5f43cd1fda 100644 --- a/gdk/wayland/gdkdevice-wayland-private.h +++ b/gdk/wayland/gdkdevice-wayland-private.h @@ -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 index 0000000000..060e18c143 --- /dev/null +++ b/gdk/wayland/gdkdevicepad-wayland.c @@ -0,0 +1,266 @@ +/* GDK - The GIMP Drawing Kit + * Copyright (C) 2009 Carlos Garnacho + * + * 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 . + */ + +#include "config.h" + +#include "gdkwaylanddevice.h" +#include "gdkdevice-wayland-private.h" + +#include "tablet-unstable-v2-client-protocol.h" + +#include + +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; +} + +/* + * 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); + } +} diff --git a/gdk/wayland/gdkseat-wayland.c b/gdk/wayland/gdkseat-wayland.c index 8c8f25534e..a5e1ca95f6 100644 --- a/gdk/wayland/gdkseat-wayland.c +++ b/gdk/wayland/gdkseat-wayland.c @@ -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; } - -/* - * 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); - } -} diff --git a/gdk/wayland/meson.build b/gdk/wayland/meson.build index 76a069975f..79a770c1f1 100644 --- a/gdk/wayland/meson.build +++ b/gdk/wayland/meson.build @@ -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', -- cgit v1.2.1