From 872534e763a85dde41fcc6a44d1634114cb32bfc Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Fri, 23 Sep 2022 13:45:46 +0200 Subject: [PATCH] gtkgesture: Do not update gestures with mismatching n-points on touchpad Check that the touchpad gesture event has a matching number of fingers before updating the GtkGesture point tracking, instead of afterwards. Avoids pointless tracking of these touchpad events when we know beforehand that the gesture will never be activated by the touchpad events. Related: https://gitlab.gnome.org/GNOME/gtk/-/issues/5199 --- gtk/gtkgesture.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/gtk/gtkgesture.c b/gtk/gtkgesture.c index 705a4ba593..c9da02950b 100644 --- a/gtk/gtkgesture.c +++ b/gtk/gtkgesture.c @@ -640,9 +640,9 @@ gtk_gesture_handle_event (GtkEventController *controller, if (event_type == GDK_BUTTON_PRESS || event_type == GDK_TOUCH_BEGIN || - (event_type == GDK_TOUCHPAD_SWIPE && phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN) || - (event_type == GDK_TOUCHPAD_PINCH && phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN) || - (event_type == GDK_TOUCHPAD_HOLD && phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN)) + (EVENT_IS_TOUCHPAD_GESTURE (event) && + phase == GDK_TOUCHPAD_GESTURE_PHASE_BEGIN && + gdk_touchpad_event_get_n_fingers (event) == priv->n_points)) { if (_gtk_gesture_update_point (gesture, event, target, x, y, TRUE)) { @@ -673,9 +673,9 @@ gtk_gesture_handle_event (GtkEventController *controller, } else if (event_type == GDK_BUTTON_RELEASE || event_type == GDK_TOUCH_END || - (event_type == GDK_TOUCHPAD_SWIPE && phase == GDK_TOUCHPAD_GESTURE_PHASE_END) || - (event_type == GDK_TOUCHPAD_PINCH && phase == GDK_TOUCHPAD_GESTURE_PHASE_END) || - (event_type == GDK_TOUCHPAD_HOLD && phase == GDK_TOUCHPAD_GESTURE_PHASE_END)) + (EVENT_IS_TOUCHPAD_GESTURE (event) && + phase == GDK_TOUCHPAD_GESTURE_PHASE_END && + gdk_touchpad_event_get_n_fingers (event) == priv->n_points)) { gboolean was_claimed = FALSE; @@ -695,8 +695,9 @@ gtk_gesture_handle_event (GtkEventController *controller, } else if (event_type == GDK_MOTION_NOTIFY || event_type == GDK_TOUCH_UPDATE || - (event_type == GDK_TOUCHPAD_SWIPE && phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE) || - (event_type == GDK_TOUCHPAD_PINCH && phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE)) + (EVENT_IS_TOUCHPAD_GESTURE (event) && + phase == GDK_TOUCHPAD_GESTURE_PHASE_UPDATE && + gdk_touchpad_event_get_n_fingers (event) == priv->n_points)) { if (event_type == GDK_MOTION_NOTIFY) { @@ -713,9 +714,9 @@ gtk_gesture_handle_event (GtkEventController *controller, if (!priv->touchpad) _gtk_gesture_cancel_sequence (gesture, sequence); } - else if ((event_type == GDK_TOUCHPAD_SWIPE && phase == GDK_TOUCHPAD_GESTURE_PHASE_CANCEL) || - (event_type == GDK_TOUCHPAD_PINCH && phase == GDK_TOUCHPAD_GESTURE_PHASE_CANCEL) || - (event_type == GDK_TOUCHPAD_HOLD && phase == GDK_TOUCHPAD_GESTURE_PHASE_CANCEL)) + else if (EVENT_IS_TOUCHPAD_GESTURE (event) && + phase == GDK_TOUCHPAD_GESTURE_PHASE_CANCEL && + gdk_touchpad_event_get_n_fingers (event) == priv->n_points) { if (priv->touchpad) _gtk_gesture_cancel_sequence (gesture, sequence);