From 6eb848f0e00ff7bf1cbf4f21bed082f837d7aeb4 Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 17 Mar 2020 17:24:09 -0400 Subject: [PATCH] popover: Add keynav keybindings The shortcut controllers are limited to same-native, so we need to duplicate the Tab and arrow key bindings for focus handling, as well as the Enter bindings for activation. --- gtk/gtkpopover.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/gtk/gtkpopover.c b/gtk/gtkpopover.c index d1dfd74f34..ef7253d123 100644 --- a/gtk/gtkpopover.c +++ b/gtk/gtkpopover.c @@ -1444,12 +1444,47 @@ gtk_popover_remove (GtkContainer *container, gtk_widget_unparent (child); } +static void +add_tab_bindings (GtkBindingSet *binding_set, + GdkModifierType modifiers, + GtkDirectionType direction) +{ + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Tab, modifiers, + "move-focus", 1, + GTK_TYPE_DIRECTION_TYPE, direction); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Tab, modifiers, + "move-focus", 1, + GTK_TYPE_DIRECTION_TYPE, direction); +} + +static void +add_arrow_bindings (GtkBindingSet *binding_set, + guint keysym, + GtkDirectionType direction) +{ + guint keypad_keysym = keysym - GDK_KEY_Left + GDK_KEY_KP_Left; + + gtk_binding_entry_add_signal (binding_set, keysym, 0, + "move-focus", 1, + GTK_TYPE_DIRECTION_TYPE, direction); + gtk_binding_entry_add_signal (binding_set, keysym, GDK_CONTROL_MASK, + "move-focus", 1, + GTK_TYPE_DIRECTION_TYPE, direction); + gtk_binding_entry_add_signal (binding_set, keypad_keysym, 0, + "move-focus", 1, + GTK_TYPE_DIRECTION_TYPE, direction); + gtk_binding_entry_add_signal (binding_set, keypad_keysym, GDK_CONTROL_MASK, + "move-focus", 1, + GTK_TYPE_DIRECTION_TYPE, direction); +} + static void gtk_popover_class_init (GtkPopoverClass *klass) { GObjectClass *object_class = G_OBJECT_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass); + GtkBindingSet *binding_set; object_class->dispose = gtk_popover_dispose; object_class->finalize = gtk_popover_finalize; @@ -1528,6 +1563,25 @@ gtk_popover_class_init (GtkPopoverClass *klass) G_TYPE_NONE, 0); + binding_set = gtk_binding_set_by_class (klass); + + add_arrow_bindings (binding_set, GDK_KEY_Up, GTK_DIR_UP); + add_arrow_bindings (binding_set, GDK_KEY_Down, GTK_DIR_DOWN); + add_arrow_bindings (binding_set, GDK_KEY_Left, GTK_DIR_LEFT); + add_arrow_bindings (binding_set, GDK_KEY_Right, GTK_DIR_RIGHT); + + add_tab_bindings (binding_set, 0, GTK_DIR_TAB_FORWARD); + add_tab_bindings (binding_set, GDK_CONTROL_MASK, GTK_DIR_TAB_FORWARD); + add_tab_bindings (binding_set, GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD); + add_tab_bindings (binding_set, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_DIR_TAB_BACKWARD); + + gtk_binding_entry_add_signal (binding_set, GDK_KEY_Return, 0, + "activate-default", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_ISO_Enter, 0, + "activate-default", 0); + gtk_binding_entry_add_signal (binding_set, GDK_KEY_KP_Enter, 0, + "activate-default", 0); + gtk_widget_class_set_css_name (widget_class, "popover"); }