[gtk/event-recorder: 4/6] gdk: Prepare touchpad events for sequences




commit 2772ff624f24297caa7e08871c294a68c7528fb4
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Dec 15 20:11:51 2021 -0500

    gdk: Prepare touchpad events for sequences
    
    It makes sense to connect the begin/update/end events
    for touchpad swipes and pinches in a sequence. This
    commit adds the plumbing for it, but not backends
    are setting sequences yet.

 gdk/gdkevents.c                       | 80 +++++++++++++++++++++++------------
 gdk/gdkeventsprivate.h                | 21 +++++----
 gdk/macos/gdkmacosdisplay-translate.c |  1 +
 gdk/wayland/gdkdevice-wayland.c       | 10 +++--
 gdk/x11/gdkdevicemanager-xi2.c        |  8 ++--
 gtk/gtkmain.c                         |  2 +
 6 files changed, 79 insertions(+), 43 deletions(-)
---
diff --git a/gdk/gdkevents.c b/gdk/gdkevents.c
index 71774ae50e..d0680e3696 100644
--- a/gdk/gdkevents.c
+++ b/gdk/gdkevents.c
@@ -2476,6 +2476,14 @@ gdk_touchpad_event_get_state (GdkEvent *event)
   return self->state;
 }
 
+static GdkEventSequence *
+gdk_touchpad_event_get_sequence (GdkEvent *event)
+{
+  GdkTouchpadEvent *self = (GdkTouchpadEvent *) event;
+
+  return self->sequence;
+}
+
 static gboolean
 gdk_touchpad_event_get_position (GdkEvent *event,
                                  double   *x,
@@ -2495,7 +2503,7 @@ static const GdkEventTypeInfo gdk_touchpad_event_info = {
   NULL,
   gdk_touchpad_event_get_state,
   gdk_touchpad_event_get_position,
-  NULL,
+  gdk_touchpad_event_get_sequence,
   NULL,
   NULL,
 };
@@ -2506,19 +2514,28 @@ GDK_DEFINE_EVENT_TYPE (GdkTouchpadEvent, gdk_touchpad_event,
                        GDK_EVENT_TYPE_SLOT (GDK_TOUCHPAD_PINCH))
 
 GdkEvent *
-gdk_touchpad_event_new_swipe (GdkSurface *surface,
-                              GdkDevice  *device,
-                              guint32     time,
-                              GdkModifierType state,
-                              GdkTouchpadGesturePhase phase,
-                              double      x,
-                              double      y,
-                              int         n_fingers,
-                              double      dx,
-                              double      dy)
-{
-  GdkTouchpadEvent *self = gdk_event_alloc (GDK_TOUCHPAD_SWIPE, surface, device, time);
+gdk_touchpad_event_new_swipe (GdkSurface              *surface,
+                              GdkEventSequence        *sequence,
+                              GdkDevice               *device,
+                              guint32                  time,
+                              GdkModifierType          state,
+                              GdkTouchpadGesturePhase  phase,
+                              double                   x,
+                              double                   y,
+                              int                      n_fingers,
+                              double                   dx,
+                              double                   dy)
+{
+  GdkTouchpadEvent *self;
+
+  g_return_val_if_fail (phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN ||
+                        phase == GDK_TOUCHPAD_GESTURE_PHASE_END ||
+                        phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE ||
+                        phase == GDK_TOUCHPAD_GESTURE_PHASE_CANCEL, NULL);
+
+  self = gdk_event_alloc (GDK_TOUCHPAD_SWIPE, surface, device, time);
 
+  self->sequence = sequence;
   self->state = state;
   self->phase = phase;
   self->x = x;
@@ -2531,21 +2548,30 @@ gdk_touchpad_event_new_swipe (GdkSurface *surface,
 }
 
 GdkEvent *
-gdk_touchpad_event_new_pinch (GdkSurface *surface,
-                              GdkDevice  *device,
-                              guint32     time,
-                              GdkModifierType state,
-                              GdkTouchpadGesturePhase phase,
-                              double      x,
-                              double      y,
-                              int         n_fingers,
-                              double      dx,
-                              double      dy,
-                              double      scale,
-                              double      angle_delta)
-{
-  GdkTouchpadEvent *self = gdk_event_alloc (GDK_TOUCHPAD_PINCH, surface, device, time);
+gdk_touchpad_event_new_pinch (GdkSurface              *surface,
+                              GdkEventSequence        *sequence,
+                              GdkDevice               *device,
+                              guint32                  time,
+                              GdkModifierType          state,
+                              GdkTouchpadGesturePhase  phase,
+                              double                   x,
+                              double                   y,
+                              int                      n_fingers,
+                              double                   dx,
+                              double                   dy,
+                              double                   scale,
+                              double                   angle_delta)
+{
+  GdkTouchpadEvent *self;
+
+  g_return_val_if_fail (phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN ||
+                        phase == GDK_TOUCHPAD_GESTURE_PHASE_END ||
+                        phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE ||
+                        phase == GDK_TOUCHPAD_GESTURE_PHASE_CANCEL, NULL);
+
+  self = gdk_event_alloc (GDK_TOUCHPAD_PINCH, surface, device, time);
 
+  self->sequence = sequence;
   self->state = state;
   self->phase = phase;
   self->x = x;
diff --git a/gdk/gdkeventsprivate.h b/gdk/gdkeventsprivate.h
index ab5893c22a..065cf1f3d3 100644
--- a/gdk/gdkeventsprivate.h
+++ b/gdk/gdkeventsprivate.h
@@ -402,6 +402,7 @@ struct _GdkTouchpadEvent
 {
   GdkEvent parent_instance;
 
+  GdkEventSequence *sequence;
   GdkModifierType state;
   gint8 phase;
   gint8 n_fingers;
@@ -506,18 +507,20 @@ GdkEvent * gdk_touch_event_new          (GdkEventType      type,
                                          double           *axes,
                                          gboolean          emulating);
 
-GdkEvent * gdk_touchpad_event_new_swipe (GdkSurface      *surface,
-                                         GdkDevice       *device,
-                                         guint32          time,
-                                         GdkModifierType  state,
+GdkEvent * gdk_touchpad_event_new_swipe (GdkSurface              *surface,
+                                         GdkEventSequence        *sequence,
+                                         GdkDevice               *device,
+                                         guint32                  time,
+                                         GdkModifierType          state,
                                          GdkTouchpadGesturePhase  phase,
-                                         double           x,
-                                         double           y,
-                                         int              n_fingers,
-                                         double           dx,
-                                         double           dy);
+                                         double                   x,
+                                         double                   y,
+                                         int                      n_fingers,
+                                         double                   dx,
+                                         double                   dy);
 
 GdkEvent * gdk_touchpad_event_new_pinch (GdkSurface              *surface,
+                                         GdkEventSequence        *sequence,
                                          GdkDevice               *device,
                                          guint32                  time,
                                          GdkModifierType          state,
diff --git a/gdk/macos/gdkmacosdisplay-translate.c b/gdk/macos/gdkmacosdisplay-translate.c
index 3400d0f9c3..ef73d7c866 100644
--- a/gdk/macos/gdkmacosdisplay-translate.c
+++ b/gdk/macos/gdkmacosdisplay-translate.c
@@ -537,6 +537,7 @@ fill_pinch_event (GdkMacosDisplay *display,
   seat = gdk_display_get_default_seat (GDK_DISPLAY (display));
 
   return gdk_touchpad_event_new_pinch (GDK_SURFACE (surface),
+                                       NULL, /* FIXME make up sequences */
                                        gdk_seat_get_pointer (seat),
                                        get_time_from_ns_event (nsevent),
                                        get_keyboard_modifiers_from_ns_event (nsevent),
diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c
index 8a45e911e9..24633ea7d3 100644
--- a/gdk/wayland/gdkdevice-wayland.c
+++ b/gdk/wayland/gdkdevice-wayland.c
@@ -1127,7 +1127,7 @@ data_offer_source_actions (void                 *data,
       seat->pending_source_actions = gdk_wayland_actions_to_gdk_actions (source_actions);
       return;
     }
-  
+
   if (seat->drop == NULL)
     return;
 
@@ -1152,7 +1152,7 @@ data_offer_action (void                 *data,
       seat->pending_action = gdk_wayland_actions_to_gdk_actions (action);
       return;
     }
-  
+
   if (seat->drop == NULL)
     return;
 
@@ -2164,7 +2164,7 @@ deliver_key_event (GdkWaylandSeat *seat,
                              key,
                              device_get_modifiers (seat->logical_pointer),
                              _gdk_wayland_keymap_key_is_modifier (keymap, key),
-                             &translated, 
+                             &translated,
                              &no_lock);
 
   _gdk_wayland_display_deliver_event (seat->display, event);
@@ -2668,6 +2668,7 @@ emit_gesture_swipe_event (GdkWaylandSeat          *seat,
   seat->pointer_info.time = _time;
 
   event = gdk_touchpad_event_new_swipe (seat->pointer_info.focus,
+                                        NULL,
                                         seat->logical_pointer,
                                         _time,
                                         device_get_modifiers (seat->logical_pointer),
@@ -2764,6 +2765,7 @@ emit_gesture_pinch_event (GdkWaylandSeat          *seat,
   seat->pointer_info.time = _time;
 
   event = gdk_touchpad_event_new_pinch (seat->pointer_info.focus,
+                                        NULL,
                                         seat->logical_pointer,
                                         _time,
                                         device_get_modifiers (seat->logical_pointer),
@@ -4088,7 +4090,7 @@ tablet_pad_strip_handle_frame (void                           *data,
   event = gdk_pad_event_new_strip (seat->keyboard_focus,
                                    pad->device,
                                    time,
-                                   g_list_index (pad->mode_groups, group),        
+                                   g_list_index (pad->mode_groups, group),
                                    g_list_index (pad->strips, wp_tablet_pad_strip),
                                    group->current_mode,
                                    group->axis_tmp_info.value);
diff --git a/gdk/x11/gdkdevicemanager-xi2.c b/gdk/x11/gdkdevicemanager-xi2.c
index 9eb4e9bc56..72b99a2f90 100644
--- a/gdk/x11/gdkdevicemanager-xi2.c
+++ b/gdk/x11/gdkdevicemanager-xi2.c
@@ -1665,7 +1665,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
                                                    _gdk_x11_device_xi2_translate_state (&xev->mods, 
&xev->buttons, &xev->group),
                                                    direction,
                                                    FALSE);
-                                                   
+
           }
         else
           {
@@ -1799,7 +1799,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
                                       _gdk_x11_device_xi2_translate_state (&xev->mods, &xev->buttons, 
&xev->group),
                                       x, y,
                                       axes);
-                                       
+
       }
       break;
 
@@ -1838,7 +1838,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
 
         x = (double) xev->event_x / scale;
         y = (double) xev->event_y / scale;
- 
+
         event = gdk_touch_event_new (ev->evtype == XI_TouchBegin
                                        ? GDK_TOUCH_BEGIN
                                        : GDK_TOUCH_END,
@@ -1946,6 +1946,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
         y = (double) xev->event_y / scale;
 
         event = gdk_touchpad_event_new_pinch (surface,
+                                              NULL, /* FIXME make up sequences */
                                               device,
                                               xev->time,
                                               state,
@@ -2006,6 +2007,7 @@ gdk_x11_device_manager_xi2_translate_event (GdkEventTranslator *translator,
         y = (double) xev->event_y / scale;
 
         event = gdk_touchpad_event_new_swipe (surface,
+                                              NULL, /* FIXME make up sequences */
                                               device,
                                               xev->time,
                                               state,
diff --git a/gtk/gtkmain.c b/gtk/gtkmain.c
index 0ac2b08ee7..2ab9c68fe7 100644
--- a/gtk/gtkmain.c
+++ b/gtk/gtkmain.c
@@ -951,6 +951,7 @@ rewrite_event_for_surface (GdkEvent  *event,
     case GDK_TOUCHPAD_SWIPE:
       gdk_touchpad_event_get_deltas (event, &dx, &dy);
       return gdk_touchpad_event_new_swipe (new_surface,
+                                           gdk_event_get_event_sequence (event),
                                            gdk_event_get_device (event),
                                            gdk_event_get_time (event),
                                            gdk_event_get_modifier_state (event),
@@ -961,6 +962,7 @@ rewrite_event_for_surface (GdkEvent  *event,
     case GDK_TOUCHPAD_PINCH:
       gdk_touchpad_event_get_deltas (event, &dx, &dy);
       return gdk_touchpad_event_new_pinch (new_surface,
+                                           gdk_event_get_event_sequence (event),
                                            gdk_event_get_device (event),
                                            gdk_event_get_time (event),
                                            gdk_event_get_modifier_state (event),


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