diff --git a/src/keypad.c b/src/keypad.c index 1f0a546e198d23948a36c553cca562206d2f0527..75017e8b80d7df21b35b3333635c6ef40f23ce9e 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); }