[gtk: 4/15] wayland/pointer-gestures: Receive hold gesture
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk: 4/15] wayland/pointer-gestures: Receive hold gesture
- Date: Wed, 26 Jan 2022 23:37:29 +0000 (UTC)
commit 299caaa383963fbe16323229209a5cd6e69cd64b
Author: José Expósito <jose exposito89 gmail com>
Date: Sun Jun 27 11:49:56 2021 +0200
wayland/pointer-gestures: Receive hold gesture
Add the glue code to receive hold gesture events from the compositor,
transform them into GdkEvents and finally enqueue them.
Part-of: <!3454>
gdk/wayland/gdkdevice-wayland.c | 92 ++++++++++++++++++++++++++++++++++++++++
gdk/wayland/gdkdisplay-wayland.c | 3 ++
gdk/wayland/gdkdisplay-wayland.h | 3 +-
3 files changed, 97 insertions(+), 1 deletion(-)
---
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index d82db04fb2..9c21a6a989 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -227,6 +227,7 @@ struct _GdkWaylandSeat
struct wl_touch *wl_touch;
struct zwp_pointer_gesture_swipe_v1 *wp_pointer_gesture_swipe;
struct zwp_pointer_gesture_pinch_v1 *wp_pointer_gesture_pinch;
+ struct zwp_pointer_gesture_hold_v1 *wp_pointer_gesture_hold;
struct zwp_tablet_seat_v2 *wp_tablet_seat;
GdkDisplay *display;
@@ -2856,6 +2857,81 @@ gesture_pinch_end (void *data,
0, 0, 1, 0);
}
+static void
+emit_gesture_hold_event (GdkWaylandSeat *seat,
+ GdkTouchpadGesturePhase phase,
+ guint32 _time,
+ guint32 n_fingers)
+{
+ GdkEvent *event;
+
+ if (!seat->pointer_info.focus)
+ return;
+
+ seat->pointer_info.time = _time;
+
+ event = gdk_touchpad_event_new_hold (seat->pointer_info.focus,
+ seat->logical_pointer,
+ _time,
+ device_get_modifiers (seat->logical_pointer),
+ phase,
+ seat->pointer_info.surface_x,
+ seat->pointer_info.surface_y,
+ n_fingers);
+
+ if (GDK_DISPLAY_DEBUG_CHECK (gdk_seat_get_display (GDK_SEAT (seat)), EVENTS))
+ {
+ double x, y;
+ gdk_event_get_position (event, &x, &y);
+ g_message ("hold event %d, coords: %f %f, seat %p state %d",
+ gdk_event_get_event_type (event),
+ x, y, seat,
+ gdk_event_get_modifier_state (event));
+ }
+
+ _gdk_wayland_display_deliver_event (seat->display, event);
+}
+
+static void
+gesture_hold_begin (void *data,
+ struct zwp_pointer_gesture_hold_v1 *hold,
+ uint32_t serial,
+ uint32_t time,
+ struct wl_surface *surface,
+ uint32_t fingers)
+{
+ GdkWaylandSeat *seat = data;
+ GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display);
+
+ _gdk_wayland_display_update_serial (display, serial);
+
+ emit_gesture_hold_event (seat,
+ GDK_TOUCHPAD_GESTURE_PHASE_BEGIN,
+ time, fingers);
+ seat->gesture_n_fingers = fingers;
+}
+
+static void
+gesture_hold_end (void *data,
+ struct zwp_pointer_gesture_hold_v1 *hold,
+ uint32_t serial,
+ uint32_t time,
+ int32_t cancelled)
+{
+ GdkWaylandSeat *seat = data;
+ GdkWaylandDisplay *display = GDK_WAYLAND_DISPLAY (seat->display);
+ GdkTouchpadGesturePhase phase;
+
+ _gdk_wayland_display_update_serial (display, serial);
+
+ phase = (cancelled) ?
+ GDK_TOUCHPAD_GESTURE_PHASE_CANCEL :
+ GDK_TOUCHPAD_GESTURE_PHASE_END;
+
+ emit_gesture_hold_event (seat, phase, time,
+ seat->gesture_n_fingers);
+}
+
static void
_gdk_wayland_seat_remove_tool (GdkWaylandSeat *seat,
GdkWaylandTabletToolData *tool)
@@ -3065,6 +3141,11 @@ static const struct zwp_pointer_gesture_pinch_v1_listener gesture_pinch_listener
gesture_pinch_end
};
+static const struct zwp_pointer_gesture_hold_v1_listener gesture_hold_listener = {
+ gesture_hold_begin,
+ gesture_hold_end
+};
+
static const struct zwp_tablet_v2_listener tablet_listener = {
tablet_handle_name,
tablet_handle_id,
@@ -3120,6 +3201,17 @@ seat_handle_capabilities (void *data,
seat);
zwp_pointer_gesture_pinch_v1_add_listener (seat->wp_pointer_gesture_pinch,
&gesture_pinch_listener, seat);
+
+ if (display_wayland->pointer_gestures_version >=
ZWP_POINTER_GESTURES_V1_GET_HOLD_GESTURE_SINCE_VERSION)
+ {
+ seat->wp_pointer_gesture_hold =
+ zwp_pointer_gestures_v1_get_hold_gesture (display_wayland->pointer_gestures,
+ seat->wl_pointer);
+ zwp_pointer_gesture_hold_v1_set_user_data (seat->wp_pointer_gesture_hold,
+ seat);
+ zwp_pointer_gesture_hold_v1_add_listener (seat->wp_pointer_gesture_hold,
+ &gesture_hold_listener, seat);
+ }
}
}
else if (!(caps & WL_SEAT_CAPABILITY_POINTER) && seat->wl_pointer)
diff --git a/gdk/wayland/gdkdisplay-wayland.c b/gdk/wayland/gdkdisplay-wayland.c
index 1401d91415..ea64041aa7 100644
--- a/gdk/wayland/gdkdisplay-wayland.c
+++ b/gdk/wayland/gdkdisplay-wayland.c
@@ -431,6 +431,9 @@ gdk_registry_handle_global (void *data,
}
else if (strcmp (interface, "zwp_pointer_gestures_v1") == 0)
{
+ display_wayland->pointer_gestures_version =
+ MIN (version, GDK_ZWP_POINTER_GESTURES_V1_VERSION);
+
display_wayland->pointer_gestures =
wl_registry_bind (display_wayland->wl_registry,
id, &zwp_pointer_gestures_v1_interface,
diff --git a/gdk/wayland/gdkdisplay-wayland.h b/gdk/wayland/gdkdisplay-wayland.h
index e4924fb6f9..b9ab698c19 100644
--- a/gdk/wayland/gdkdisplay-wayland.h
+++ b/gdk/wayland/gdkdisplay-wayland.h
@@ -52,7 +52,7 @@
G_BEGIN_DECLS
-#define GDK_ZWP_POINTER_GESTURES_V1_VERSION 1
+#define GDK_ZWP_POINTER_GESTURES_V1_VERSION 3
typedef struct _GdkWaylandSelection GdkWaylandSelection;
@@ -140,6 +140,7 @@ struct _GdkWaylandDisplay
int data_device_manager_version;
int gtk_shell_version;
int xdg_output_manager_version;
+ int pointer_gestures_version;
int xdg_activation_version;
uint32_t server_decoration_mode;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]