diff options
author | Benjamin Otte <otte@redhat.com> | 2018-08-12 21:32:42 +0200 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-03-25 22:36:03 -0400 |
commit | 4c7b00fd201e28e06821687b3ba4402dff94d74f (patch) | |
tree | da4cc2b5ecdef397ab9c8a4b07b6d3df597c7d3b /gtk/gtktreeview.c | |
parent | 3fba7f9dcee5916e7c01a9fc311ce9bc8567ddfe (diff) | |
download | gtk+-4c7b00fd201e28e06821687b3ba4402dff94d74f.tar.gz |
treeview: Redo event forwarding hack
Reorder the event controllers so that key forwarding to the search
entries really happens after shortcut triggering.
Diffstat (limited to 'gtk/gtktreeview.c')
-rw-r--r-- | gtk/gtktreeview.c | 54 |
1 files changed, 34 insertions, 20 deletions
diff --git a/gtk/gtktreeview.c b/gtk/gtktreeview.c index 867f385e26..51fa6d5229 100644 --- a/gtk/gtktreeview.c +++ b/gtk/gtktreeview.c @@ -22,7 +22,6 @@ #include "gtkadjustmentprivate.h" #include "gtkbox.h" -#include "gtkbindings.h" #include "gtkbuildable.h" #include "gtkbutton.h" #include "gtkcelllayout.h" @@ -54,6 +53,7 @@ #include "gtkrendericonprivate.h" #include "gtkscrollable.h" #include "gtksettingsprivate.h" +#include "gtkshortcutcontroller.h" #include "gtksnapshot.h" #include "gtkstylecontextprivate.h" #include "gtktooltip.h" @@ -657,6 +657,11 @@ static void gtk_tree_view_size_allocate (GtkWidget *widget, static void gtk_tree_view_snapshot (GtkWidget *widget, GtkSnapshot *snapshot); +static gboolean gtk_tree_view_forward_controller_key_pressed (GtkEventControllerKey *key, + guint keyval, + guint keycode, + GdkModifierType state, + GtkTreeView *tree_view); static gboolean gtk_tree_view_key_controller_key_pressed (GtkEventControllerKey *key, guint keyval, guint keycode, @@ -1699,6 +1704,7 @@ gtk_tree_view_init (GtkTreeView *tree_view) GtkCssNode *widget_node; GtkGesture *gesture; GtkEventController *controller; + GList *list, *controllers; gtk_widget_set_can_focus (GTK_WIDGET (tree_view), TRUE); gtk_widget_set_overflow (GTK_WIDGET (tree_view), GTK_OVERFLOW_HIDDEN); @@ -1760,6 +1766,24 @@ gtk_tree_view_init (GtkTreeView *tree_view) gtk_css_node_set_state (tree_view->header_node, gtk_css_node_get_state (widget_node)); g_object_unref (tree_view->header_node); + controller = gtk_event_controller_key_new (); + g_signal_connect (controller, "key-pressed", + G_CALLBACK (gtk_tree_view_forward_controller_key_pressed), tree_view); + gtk_widget_add_controller (GTK_WIDGET (tree_view), controller); + + controllers = gtk_widget_list_controllers (GTK_WIDGET (tree_view), GTK_PHASE_BUBBLE); + for (list = controllers; list; list = list->next) + { + if (GTK_IS_SHORTCUT_CONTROLLER (list->data)) + { + g_object_ref (list->data); + gtk_widget_remove_controller (GTK_WIDGET (tree_view), list->data); + gtk_widget_add_controller (GTK_WIDGET (tree_view), list->data); + break; + } + } + g_list_free (controllers); + tree_view->click_gesture = gtk_gesture_click_new (); gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (tree_view->click_gesture), 0); g_signal_connect (tree_view->click_gesture, "pressed", @@ -5286,7 +5310,6 @@ gtk_tree_view_key_controller_key_pressed (GtkEventControllerKey *key, { GtkWidget *widget = GTK_WIDGET (tree_view); GtkWidget *button; - GdkEvent *event; if (tree_view->rubber_band_status) { @@ -5406,16 +5429,16 @@ gtk_tree_view_key_controller_key_pressed (GtkEventControllerKey *key, } } - /* Handle the keybindings. */ - event = gtk_get_current_event (); - if (gtk_bindings_activate_event (G_OBJECT (widget), event)) - { - gdk_event_unref (event); - return TRUE; - } - - gdk_event_unref (event); + return FALSE; +} +static gboolean +gtk_tree_view_forward_controller_key_pressed (GtkEventControllerKey *key, + guint keyval, + guint keycode, + GdkModifierType state, + GtkTreeView *tree_view) +{ if (tree_view->search_entry_avoid_unhandled_binding) { tree_view->search_entry_avoid_unhandled_binding = FALSE; @@ -5461,15 +5484,6 @@ gtk_tree_view_key_controller_key_released (GtkEventControllerKey *key, GdkModifierType state, GtkTreeView *tree_view) { - GdkEvent *event; - - if (tree_view->rubber_band_status) - return; - - /* Handle the keybindings. */ - event = gtk_get_current_event (); - gtk_bindings_activate_event (G_OBJECT (tree_view), event); - gdk_event_unref (event); } static void |