From 2e62e2def6100f9022bbcf9af23948850f08d4aa Mon Sep 17 00:00:00 2001 From: Ernestas Kulik Date: Tue, 22 May 2018 12:37:36 +0300 Subject: [PATCH] window: Use GdkEvent accessors --- src/nautilus-window-slot.c | 18 ++++++++++++++---- src/nautilus-window-slot.h | 2 +- src/nautilus-window.c | 26 ++++++++++++++++---------- 3 files changed, 31 insertions(+), 15 deletions(-) diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c index 6cbc0cf11..f9a15620c 100644 --- a/src/nautilus-window-slot.c +++ b/src/nautilus-window-slot.c @@ -610,18 +610,29 @@ nautilus_window_slot_search (NautilusWindowSlot *self, gboolean nautilus_window_slot_handle_event (NautilusWindowSlot *self, - GdkEventKey *event) + GdkEvent *event) { NautilusWindowSlotPrivate *priv; gboolean retval; GAction *action; + guint keyval; priv = nautilus_window_slot_get_instance_private (self); retval = FALSE; action = g_action_map_lookup_action (G_ACTION_MAP (priv->slot_action_group), "search-visible"); - if (event->keyval == GDK_KEY_Escape) + if (gdk_event_get_event_type (event) != GDK_KEY_PRESS) + { + return GDK_EVENT_PROPAGATE; + } + + if (G_UNLIKELY (!gdk_event_get_keyval (event, &keyval))) + { + g_return_val_if_reached (GDK_EVENT_PROPAGATE); + } + + if (keyval == GDK_KEY_Escape) { g_autoptr (GVariant) state = NULL; @@ -636,8 +647,7 @@ nautilus_window_slot_handle_event (NautilusWindowSlot *self, /* If the action is not enabled, don't try to handle search */ if (g_action_get_enabled (action)) { - retval = nautilus_query_editor_handle_event (priv->query_editor, - (GdkEvent *) event); + retval = nautilus_query_editor_handle_event (priv->query_editor, event); } if (retval) diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h index 6f1813062..883da5762 100644 --- a/src/nautilus-window-slot.h +++ b/src/nautilus-window-slot.h @@ -92,7 +92,7 @@ const gchar *nautilus_window_slot_get_title (NautilusWindowSlot * void nautilus_window_slot_update_title (NautilusWindowSlot *slot); gboolean nautilus_window_slot_handle_event (NautilusWindowSlot *slot, - GdkEventKey *event); + GdkEvent *event); void nautilus_window_slot_queue_reload (NautilusWindowSlot *slot); diff --git a/src/nautilus-window.c b/src/nautilus-window.c index 28e6b0314..d655769d2 100644 --- a/src/nautilus-window.c +++ b/src/nautilus-window.c @@ -2458,26 +2458,32 @@ nautilus_window_key_press_event (GtkWidget *widget, GdkEventKey *event) { NautilusWindow *window; + guint keyval; GtkWidget *focus_widget; - int i; window = NAUTILUS_WINDOW (widget); + if (G_UNLIKELY (!gdk_event_get_keyval ((GdkEvent *) event, &keyval))) + { + g_return_val_if_reached (GDK_EVENT_PROPAGATE); + } + focus_widget = gtk_window_get_focus (GTK_WINDOW (window)); if (focus_widget != NULL && GTK_IS_EDITABLE (focus_widget)) { /* if we have input focus on a GtkEditable (e.g. a GtkEntry), forward * the event to it before activating accelerator bindings too. */ - if (gtk_window_propagate_key_event (GTK_WINDOW (window), event)) + if (gtk_window_propagate_key_event (GTK_WINDOW (window), + (GdkEventKey *) event)) { - return TRUE; + return GDK_EVENT_STOP; } } - for (i = 0; i < G_N_ELEMENTS (extra_window_keybindings); i++) + for (int i = 0; i < G_N_ELEMENTS (extra_window_keybindings); i++) { - if (extra_window_keybindings[i].keyval == event->keyval) + if (extra_window_keybindings[i].keyval == keyval) { GAction *action; @@ -2487,7 +2493,7 @@ nautilus_window_key_press_event (GtkWidget *widget, if (g_action_get_enabled (action)) { g_action_activate (action, NULL); - return TRUE; + return GDK_EVENT_STOP; } break; @@ -2496,15 +2502,15 @@ nautilus_window_key_press_event (GtkWidget *widget, if (GTK_WIDGET_CLASS (nautilus_window_parent_class)->key_press_event (widget, event)) { - return TRUE; + return GDK_EVENT_STOP; } - if (nautilus_window_slot_handle_event (window->active_slot, event)) + if (nautilus_window_slot_handle_event (window->active_slot, (GdkEvent *) event)) { - return TRUE; + return GDK_EVENT_STOP; } - return FALSE; + return GDK_EVENT_PROPAGATE; } void