From 7b76be53606fe909160d853e49bb1c41bfa93e71 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sat, 18 Jul 2020 12:51:18 -0400 Subject: [PATCH] button: Add explicit key bindings for activation We should not rely on GtkWindow to have global "activate-default" key bindings that happen to fall back to activating the focus widget. This is unreliable, since the bubbling up from the button to the toplevel may run across other widgets that may want to use Enter for their own purpose, and then the button loses out. By adding our own key bindings, the button gets to handle it before its ancestors. This fixes check buttons in the inspector property list not reacting to Enter despite having focus. --- gtk/gtkbutton.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gtk/gtkbutton.c b/gtk/gtkbutton.c index 8a0c084b52..2cb79cc483 100644 --- a/gtk/gtkbutton.c +++ b/gtk/gtkbutton.c @@ -294,6 +294,17 @@ gtk_button_class_init (GtkButtonClass *klass) gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT); gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_BUTTON_ACCESSIBLE); gtk_widget_class_set_css_name (widget_class, I_("button")); + + gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_space, 0, + "activate", NULL); + gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Space, 0, + "activate", NULL); + gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_Return, 0, + "activate", NULL); + gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_ISO_Enter, 0, + "activate", NULL); + gtk_widget_class_add_binding_signal (widget_class, GDK_KEY_KP_Enter, 0, + "activate", NULL); } static void