From 9abeb0f8ca2bf129eef03a0b72966484d0dbdddf Mon Sep 17 00:00:00 2001 From: DarkTrick Date: Tue, 12 May 2020 12:31:57 +0900 Subject: [PATCH] [PATCH] Fix: Bug 4537 and Bug 13680 Details: Key events are now handled bottom-up, if the currently focused widget is GTK_IS_EDITABLE. - g_signal_connect is used, to reduce complexity of calling parent class method - key-press/-release are both used to remain consistent event order at widgets --- thunar/thunar-window.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/thunar/thunar-window.c b/thunar/thunar-window.c index 1d52e11e..31b6a79a 100644 --- a/thunar/thunar-window.c +++ b/thunar/thunar-window.c @@ -189,6 +189,9 @@ static void thunar_window_action_contents (ThunarWindow static void thunar_window_action_about (ThunarWindow *window); static void thunar_window_action_show_hidden (ThunarWindow *window); static void thunar_window_action_open_file_menu (ThunarWindow *window); +static gboolean thunar_window_propagate_key_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_menu_item_selected (ThunarWindow *window, @@ -613,6 +616,10 @@ thunar_window_init (ThunarWindow *window) window->icon_factory = thunar_icon_factory_get_default (); + /* Catch key events before accelerators get processed */ + g_signal_connect (window, "key-press-event", G_CALLBACK (thunar_window_propagate_key_event), NULL); + g_signal_connect (window, "key-release-event", G_CALLBACK (thunar_window_propagate_key_event), NULL); + window->select_files_closure = g_cclosure_new_swap (G_CALLBACK (thunar_window_select_files), window, NULL); g_closure_ref (window->select_files_closure); g_closure_sink (window->select_files_closure); @@ -3110,6 +3117,31 @@ thunar_window_action_open_network (ThunarWindow *window) +static gboolean +thunar_window_propagate_key_event (GtkWidget *widget, + GdkEvent *key_event, + gpointer user_data) +{ + GtkWindow* window; + GtkWidget* focused_widget; + + window = GTK_WINDOW (widget); + focused_widget = gtk_window_get_focus (window); + + /* I think we should turn the accelerator priority around globally, + * so that the focused widget always gets the accels first. But im- + * plementing this cleanly while maintaining some wanted accels + * (like Ctrl+N and exo accels) is a lot of work. So we resort to + * only priorize GtkEditable, because that is the easiest way to + * fix the right-ahead problem. */ + 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