From 55d32745607ed5d42a0e0031c0bde726c47627e2 Mon Sep 17 00:00:00 2001 From: DarkTrick Date: Wed, 6 May 2020 14:52:34 +0900 Subject: [PATCH] With this change key events are handled bottom-up, if the currently focused widget is GTK_IS_EDITABLE. That means, accelerators only get executed, if the focused widget (or it's parent) did not consume the accelerator. This solves the bug below: https://bugzilla.xfce.org/show_bug.cgi?id=4537 This mitigates the bug below: https://bugzilla.xfce.org/show_bug.cgi?id=13680 --- thunar/thunar-window.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index f4dc6847..25e00e64 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -221,6 +221,9 @@ static void thunar_window_action_about (GtkAction ThunarWindow *window); static void thunar_window_action_show_hidden (GtkToggleAction *action, ThunarWindow *window); +static gboolean thunar_window_key_press_event (GtkWidget *widget, + GdkEvent *key_event, + gpointer user_data); static void thunar_window_current_directory_changed (ThunarFile *current_directory, ThunarWindow *window); static void thunar_window_connect_proxy (GtkUIManager *manager, @@ -772,6 +775,10 @@ thunar_window_init (ThunarWindow *window) g_closure_sink (window->menu_item_deselected_closure); window->icon_factory = thunar_icon_factory_get_default (); + /* Make key events propagate from the focused widget up */ + g_signal_connect(window, "key-press-event", G_CALLBACK(thunar_window_key_press_event), NULL); + g_signal_connect(window, "key-release-event", G_CALLBACK(thunar_window_key_press_event), NULL); + G_GNUC_BEGIN_IGNORE_DEPRECATIONS /* setup the action group for this window */ window->action_group = gtk_action_group_new ("ThunarWindow"); @@ -3350,6 +3357,29 @@ G_GNUC_END_IGNORE_DEPRECATIONS +static gboolean +thunar_window_key_press_event (GtkWidget *widget, + GdkEvent *key_event, + gpointer user_data) +{ + GtkWindow* window; + GtkWidget* focused_widget; + + /* Check, if GTK_IS_EDITABLE, because if it's not, we don't want accelerators + of other widgets to be priorized over global accelerators. (E.g. Ctrl+N + is implemented as "next element" within the `list view`)*/ + window = GTK_WINDOW(widget); + focused_widget = gtk_window_get_focus (window); + + if (focused_widget != NULL && GTK_IS_EDITABLE (focused_widget)) + { + return gtk_window_propagate_key_event(window,(GdkEventKey *)key_event); + } + return GDK_EVENT_PROPAGATE; +} + + + static void thunar_window_poke_location_finish (ThunarBrowser *browser, GFile *location, -- 2.20.1