[mutter/wip/carlosg/cancel-pointer-gestures-on-unfocus: 1/4] wayland: Refactor pointer gesture .end emission event




commit 128b5d258ea42d1996c0faad0b8b3addbb8184c1
Author: Carlos Garnacho <carlosg gnome org>
Date:   Fri Sep 23 15:52:20 2022 +0200

    wayland: Refactor pointer gesture .end emission event
    
    We will want to trigger this from multiple places for cancellation.

 src/wayland/meta-wayland-pointer-gesture-hold.c  | 30 +++++++++++++++++-------
 src/wayland/meta-wayland-pointer-gesture-pinch.c | 30 +++++++++++++++++-------
 src/wayland/meta-wayland-pointer-gesture-swipe.c | 30 +++++++++++++++++-------
 3 files changed, 63 insertions(+), 27 deletions(-)
---
diff --git a/src/wayland/meta-wayland-pointer-gesture-hold.c b/src/wayland/meta-wayland-pointer-gesture-hold.c
index 904b0654b1..4d24f73162 100644
--- a/src/wayland/meta-wayland-pointer-gesture-hold.c
+++ b/src/wayland/meta-wayland-pointer-gesture-hold.c
@@ -52,29 +52,41 @@ handle_hold_begin (MetaWaylandPointer *pointer,
     }
 }
 
+static void
+broadcast_end (MetaWaylandPointer *pointer,
+               uint32_t            serial,
+               uint32_t            time,
+               gboolean            cancelled)
+{
+  MetaWaylandPointerClient *pointer_client;
+  struct wl_resource *resource;
+
+  pointer_client = pointer->focus_client;
+
+  wl_resource_for_each (resource, &pointer_client->hold_gesture_resources)
+    {
+      zwp_pointer_gesture_hold_v1_send_end (resource, serial,
+                                            time, cancelled);
+    }
+}
+
 static void
 handle_hold_end (MetaWaylandPointer *pointer,
                  const ClutterEvent *event)
 {
-  MetaWaylandPointerClient *pointer_client;
   MetaWaylandSeat *seat;
-  struct wl_resource *resource;
   gboolean cancelled = FALSE;
   uint32_t serial;
 
-  pointer_client = pointer->focus_client;
   seat = meta_wayland_pointer_get_seat (pointer);
   serial = wl_display_next_serial (seat->wl_display);
 
   if (event->touchpad_hold.phase == CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL)
     cancelled = TRUE;
 
-  wl_resource_for_each (resource, &pointer_client->hold_gesture_resources)
-    {
-      zwp_pointer_gesture_hold_v1_send_end (resource, serial,
-                                            clutter_event_get_time (event),
-                                            cancelled);
-    }
+  broadcast_end (pointer, serial,
+                 clutter_event_get_time (event),
+                 cancelled);
 }
 
 gboolean
diff --git a/src/wayland/meta-wayland-pointer-gesture-pinch.c 
b/src/wayland/meta-wayland-pointer-gesture-pinch.c
index f7b37ff277..89d1ba634e 100644
--- a/src/wayland/meta-wayland-pointer-gesture-pinch.c
+++ b/src/wayland/meta-wayland-pointer-gesture-pinch.c
@@ -80,29 +80,41 @@ handle_pinch_update (MetaWaylandPointer *pointer,
     }
 }
 
+static void
+broadcast_end (MetaWaylandPointer *pointer,
+               uint32_t            serial,
+               uint32_t            time,
+               gboolean            cancelled)
+{
+  MetaWaylandPointerClient *pointer_client;
+  struct wl_resource *resource;
+
+  pointer_client = pointer->focus_client;
+
+  wl_resource_for_each (resource, &pointer_client->pinch_gesture_resources)
+    {
+      zwp_pointer_gesture_pinch_v1_send_end (resource, serial,
+                                             time, cancelled);
+    }
+}
+
 static void
 handle_pinch_end (MetaWaylandPointer *pointer,
                   const ClutterEvent *event)
 {
-  MetaWaylandPointerClient *pointer_client;
   MetaWaylandSeat *seat;
-  struct wl_resource *resource;
   gboolean cancelled = FALSE;
   uint32_t serial;
 
-  pointer_client = pointer->focus_client;
   seat = meta_wayland_pointer_get_seat (pointer);
   serial = wl_display_next_serial (seat->wl_display);
 
   if (event->touchpad_pinch.phase == CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL)
     cancelled = TRUE;
 
-  wl_resource_for_each (resource, &pointer_client->pinch_gesture_resources)
-    {
-      zwp_pointer_gesture_pinch_v1_send_end (resource, serial,
-                                             clutter_event_get_time (event),
-                                             cancelled);
-    }
+  broadcast_end (pointer, serial,
+                 clutter_event_get_time (event),
+                 cancelled);
 }
 
 gboolean
diff --git a/src/wayland/meta-wayland-pointer-gesture-swipe.c 
b/src/wayland/meta-wayland-pointer-gesture-swipe.c
index d95e84941a..1e34c4908c 100644
--- a/src/wayland/meta-wayland-pointer-gesture-swipe.c
+++ b/src/wayland/meta-wayland-pointer-gesture-swipe.c
@@ -76,29 +76,41 @@ handle_swipe_update (MetaWaylandPointer *pointer,
     }
 }
 
+static void
+broadcast_end (MetaWaylandPointer *pointer,
+               uint32_t            serial,
+               uint32_t            time,
+               gboolean            cancelled)
+{
+  MetaWaylandPointerClient *pointer_client;
+  struct wl_resource *resource;
+
+  pointer_client = pointer->focus_client;
+
+  wl_resource_for_each (resource, &pointer_client->swipe_gesture_resources)
+    {
+      zwp_pointer_gesture_swipe_v1_send_end (resource, serial,
+                                             time, cancelled);
+    }
+}
+
 static void
 handle_swipe_end (MetaWaylandPointer *pointer,
                   const ClutterEvent *event)
 {
-  MetaWaylandPointerClient *pointer_client;
   MetaWaylandSeat *seat;
-  struct wl_resource *resource;
   gboolean cancelled = FALSE;
   uint32_t serial;
 
-  pointer_client = pointer->focus_client;
   seat = meta_wayland_pointer_get_seat (pointer);
   serial = wl_display_next_serial (seat->wl_display);
 
   if (event->touchpad_swipe.phase == CLUTTER_TOUCHPAD_GESTURE_PHASE_CANCEL)
     cancelled = TRUE;
 
-  wl_resource_for_each (resource, &pointer_client->swipe_gesture_resources)
-    {
-      zwp_pointer_gesture_swipe_v1_send_end (resource, serial,
-                                             clutter_event_get_time (event),
-                                             cancelled);
-    }
+  broadcast_end (pointer, serial,
+                 clutter_event_get_time (event),
+                 cancelled);
 }
 
 gboolean


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