From 557b56bd8faaaa7ac25b248bdd72f7a49e48ddbf Mon Sep 17 00:00:00 2001 From: williamvds Date: Sun, 26 Nov 2023 17:21:02 +0000 Subject: [PATCH] Inhibit dragging on the keypad To prevent users accidentally swiping back to the lockscreen while entering their PIN. This prevents swiping on the buttons, but not swiping on the gaps in between the buttons. --- src/keypad.c | 44 +++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 43 insertions(+), 1 deletion(-) diff --git a/src/keypad.c b/src/keypad.c index 1f0a546e1..75017e8b8 100644 --- a/src/keypad.c +++ b/src/keypad.c @@ -42,6 +42,8 @@ typedef struct _PhoshKeypad { GtkWidget *buttons[10]; gboolean shuffle; + + GtkGesture *drag; } PhoshKeypad; G_DEFINE_TYPE (PhoshKeypad, phosh_keypad, GTK_TYPE_GRID) @@ -87,6 +89,26 @@ on_button_clicked (PhoshKeypad *self, } +static void +on_drag_start (GtkGestureDrag *gesture, + gdouble dx, + gdouble dy, + PhoshKeypad *self) +{ + gtk_grab_add (GTK_WIDGET (self)); +} + + +static void +on_drag_end (GtkGestureDrag *gesture, + gdouble dx, + gdouble dy, + PhoshKeypad *self) +{ + gtk_grab_remove (GTK_WIDGET (self)); +} + + static void phosh_keypad_set_property (GObject *object, guint property_id, @@ -182,7 +204,7 @@ distribute_buttons (PhoshKeypad *self, gboolean shuffle) GtkWidget *old; int c = btn_pos[i][0]; int r = btn_pos[i][1]; - + old = gtk_grid_get_child_at (GTK_GRID (self), c, r); gtk_container_remove (GTK_CONTAINER (self), old); } @@ -205,6 +227,10 @@ phosh_keypad_dispose (GObject *object) for (int i = 0; i < NUM_DIGITS; i++) g_clear_object (&self->buttons[i]); + gtk_grab_remove (GTK_WIDGET (self)); + + g_clear_object (&self->drag); + G_OBJECT_CLASS (phosh_keypad_parent_class)->dispose (object); } @@ -298,6 +324,22 @@ phosh_keypad_init (PhoshKeypad *self) g_object_ref (self->buttons[i]); } distribute_buttons (self, self->shuffle); + + gtk_widget_add_events (GTK_WIDGET (self), + GDK_BUTTON_PRESS_MASK | + GDK_BUTTON_RELEASE_MASK | + GDK_TOUCH_MASK); + + /* Handle dragging to prevent accidentally swiping back to the lockscreen + * while entering a PIN code */ + self->drag = g_object_new (GTK_TYPE_GESTURE_DRAG, + "widget", self, + "propagation-phase", GTK_PHASE_CAPTURE, + "touch-only", 0, + NULL); + + g_signal_connect_object (self->drag, "drag-end", G_CALLBACK (on_drag_end), self, G_CONNECT_AFTER); + g_signal_connect_object (self->drag, "drag-begin", G_CALLBACK (on_drag_start), self, G_CONNECT_AFTER); } -- GitLab