From 65233726f840adb97caff13f131a803ea3cd31e7 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 May 2019 19:11:30 +0000 Subject: [PATCH 1/5] event controller: Don't deliver events to insensitive widgets This is another way to avoid delivering events to insensitive widgets. --- gtk/gtkeventcontroller.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/gtk/gtkeventcontroller.c b/gtk/gtkeventcontroller.c index aed43c3d5e..4cfb498f2f 100644 --- a/gtk/gtkeventcontroller.c +++ b/gtk/gtkeventcontroller.c @@ -63,6 +63,7 @@ gtk_event_controller_set_widget (GtkEventController *self, GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (self); priv->widget = widget; + priv->responsive = gtk_widget_get_sensitive (widget); } static void @@ -73,6 +74,18 @@ gtk_event_controller_unset_widget (GtkEventController *self) priv->widget = NULL; } +static gboolean +gtk_event_controller_filter_event_default (GtkEventController *self, + const GdkEvent *event) +{ + GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (self); + + if (priv->widget) + return !gtk_widget_get_sensitive (priv->widget); + + return FALSE; +} + static gboolean gtk_event_controller_handle_event_default (GtkEventController *self, const GdkEvent *event) @@ -128,7 +141,7 @@ gtk_event_controller_class_init (GtkEventControllerClass *klass) klass->set_widget = gtk_event_controller_set_widget; klass->unset_widget = gtk_event_controller_unset_widget; - klass->filter_event = gtk_event_controller_handle_event_default; + klass->filter_event = gtk_event_controller_filter_event_default; klass->handle_event = gtk_event_controller_handle_event_default; object_class->set_property = gtk_event_controller_set_property; From 522bbc182d88141a79dfc9ea23bc088b7a438b7f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 May 2019 19:10:49 +0000 Subject: [PATCH 2/5] gesture: Chain up in filter_event This is the right thing to do. We want to exclude more events. --- gtk/gtkgesture.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/gtk/gtkgesture.c b/gtk/gtkgesture.c index 7276a3043d..e4e0791d59 100644 --- a/gtk/gtkgesture.c +++ b/gtk/gtkgesture.c @@ -628,7 +628,10 @@ gtk_gesture_filter_event (GtkEventController *controller, * subclasses which punch the holes in for the events * they can possibly handle. */ - return EVENT_IS_TOUCHPAD_GESTURE (event); + if (EVENT_IS_TOUCHPAD_GESTURE (event)) + return FALSE; + + return GTK_EVENT_CONTROLLER_CLASS (gtk_gesture_parent_class)->filter_event (controller, event); } static gboolean From af2207bc0b456313b747b868e9660bb565d54642 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 May 2019 19:12:29 +0000 Subject: [PATCH 3/5] widget: Reset controllers when going numb Reset event controllers when their widget is going insensitive. This is the expected behavior. --- gtk/gtkwidget.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index 3ae53fdb09..af0b48c8c6 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -6363,6 +6363,7 @@ gtk_widget_set_sensitive (GtkWidget *widget, gboolean sensitive) { GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget); + GList *l; g_return_if_fail (GTK_IS_WIDGET (widget)); @@ -6373,6 +6374,13 @@ gtk_widget_set_sensitive (GtkWidget *widget, priv->sensitive = sensitive; + for (l = priv->event_controllers; l; l = l->next) + { + GtkEventController *controller = l->data; + + gtk_event_controller_reset (controller); + } + if (priv->parent == NULL || gtk_widget_is_sensitive (priv->parent)) { From b1d90cc17125a21c93bbf7fdb656742d77bdbca5 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 May 2019 19:09:17 +0000 Subject: [PATCH 4/5] spin button: Listen for ::cancel on gestures Otherwise, we keep spinning when we should stop. Closes: https://gitlab.gnome.org/GNOME/gtk/issues/1861 --- gtk/gtkspinbutton.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c index b273b2e30d..b038feb444 100644 --- a/gtk/gtkspinbutton.c +++ b/gtk/gtkspinbutton.c @@ -809,6 +809,14 @@ button_released_cb (GtkGestureMultiPress *gesture, } } +static void +button_cancel_cb (GtkGesture *gesture, + GdkEventSequence *sequence, + GtkSpinButton *spin_button) +{ + gtk_spin_button_stop_spinning (spin_button); +} + static void key_controller_key_released (GtkEventControllerKey *key, guint keyval, @@ -886,6 +894,7 @@ gtk_spin_button_init (GtkSpinButton *spin_button) GTK_PHASE_CAPTURE); g_signal_connect (gesture, "pressed", G_CALLBACK (button_pressed_cb), spin_button); g_signal_connect (gesture, "released", G_CALLBACK (button_released_cb), spin_button); + g_signal_connect (gesture, "cancel", G_CALLBACK (button_cancel_cb), spin_button); gtk_widget_add_controller (GTK_WIDGET (priv->down_button), GTK_EVENT_CONTROLLER (gesture)); priv->up_button = gtk_button_new (); @@ -902,6 +911,7 @@ gtk_spin_button_init (GtkSpinButton *spin_button) GTK_PHASE_CAPTURE); g_signal_connect (gesture, "pressed", G_CALLBACK (button_pressed_cb), spin_button); g_signal_connect (gesture, "released", G_CALLBACK (button_released_cb), spin_button); + g_signal_connect (gesture, "cancel", G_CALLBACK (button_cancel_cb), spin_button); gtk_widget_add_controller (GTK_WIDGET (priv->up_button), GTK_EVENT_CONTROLLER (gesture)); gtk_spin_button_set_adjustment (spin_button, NULL); From 299422994ac5304ea20e66e4b5d46333ecf11f51 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Thu, 2 May 2019 20:20:20 +0000 Subject: [PATCH 5/5] fixup! event controller: Don't deliver events to insensitive widgets --- gtk/gtkeventcontroller.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/gtk/gtkeventcontroller.c b/gtk/gtkeventcontroller.c index 4cfb498f2f..d085cd5899 100644 --- a/gtk/gtkeventcontroller.c +++ b/gtk/gtkeventcontroller.c @@ -63,7 +63,6 @@ gtk_event_controller_set_widget (GtkEventController *self, GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (self); priv->widget = widget; - priv->responsive = gtk_widget_get_sensitive (widget); } static void @@ -81,7 +80,7 @@ gtk_event_controller_filter_event_default (GtkEventController *self, GtkEventControllerPrivate *priv = gtk_event_controller_get_instance_private (self); if (priv->widget) - return !gtk_widget_get_sensitive (priv->widget); + return !gtk_widget_is_sensitive (priv->widget); return FALSE; }