[nautilus/wip/antoniof/gtk4-preparation-step-event-controllers: 19/22] query-editor: Drop usage of gtk_search_entry_handle_event()




commit 040f9eda37b7d8dd556fe7370b6720c9795be3a2
Author: António Fernandes <antoniof gnome org>
Date:   Sun Aug 8 16:18:01 2021 +0100

    query-editor: Drop usage of gtk_search_entry_handle_event()
    
    It's going away in GTK4. Also, as we use a key event controller now,
    we can use gtk_event_controller_key_forward() instead.

 src/nautilus-query-editor.c |  8 ++++----
 src/nautilus-query-editor.h |  4 ++--
 src/nautilus-window-slot.c  | 18 ++++--------------
 src/nautilus-window-slot.h  |  5 +++--
 src/nautilus-window.c       |  4 +---
 5 files changed, 14 insertions(+), 25 deletions(-)
---
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index 1eb074927..ae0b34275 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -745,11 +745,11 @@ nautilus_query_editor_set_text (NautilusQueryEditor *self,
 }
 
 gboolean
-nautilus_query_editor_handle_event (NautilusQueryEditor *self,
-                                    GdkEvent            *event)
+nautilus_query_editor_handle_event (NautilusQueryEditor   *self,
+                                    GtkEventControllerKey *controller)
 {
     g_return_val_if_fail (NAUTILUS_IS_QUERY_EDITOR (self), GDK_EVENT_PROPAGATE);
-    g_return_val_if_fail (event != NULL, GDK_EVENT_PROPAGATE);
+    g_return_val_if_fail (controller != NULL, GDK_EVENT_PROPAGATE);
 
-    return gtk_search_entry_handle_event (GTK_SEARCH_ENTRY (self->entry), event);
+    return gtk_event_controller_key_forward (controller, GTK_WIDGET (self->entry));
 }
diff --git a/src/nautilus-query-editor.h b/src/nautilus-query-editor.h
index c09de18a0..bc1cd9495 100644
--- a/src/nautilus-query-editor.h
+++ b/src/nautilus-query-editor.h
@@ -73,5 +73,5 @@ void           nautilus_query_editor_set_text     (NautilusQueryEditor *editor,
                                                    const gchar         *text);
 
 gboolean
-nautilus_query_editor_handle_event (NautilusQueryEditor *self,
-                                    GdkEvent            *event);
+nautilus_query_editor_handle_event (NautilusQueryEditor   *self,
+                                    GtkEventControllerKey *controller);
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 8d6a4cde3..792124207 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -607,27 +607,17 @@ nautilus_window_slot_search (NautilusWindowSlot *self,
 }
 
 gboolean
-nautilus_window_slot_handle_event (NautilusWindowSlot *self,
-                                   GdkEvent           *event)
+nautilus_window_slot_handle_event (NautilusWindowSlot    *self,
+                                   GtkEventControllerKey *controller,
+                                   guint                  keyval)
 {
     gboolean retval;
     GAction *action;
-    guint keyval;
 
     retval = FALSE;
     action = g_action_map_lookup_action (G_ACTION_MAP (self->slot_action_group),
                                          "search-visible");
 
-    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;
@@ -643,7 +633,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 (self->query_editor, event);
+        retval = nautilus_query_editor_handle_event (self->query_editor, controller);
     }
 
     if (retval)
diff --git a/src/nautilus-window-slot.h b/src/nautilus-window-slot.h
index 268578789..290591e85 100644
--- a/src/nautilus-window-slot.h
+++ b/src/nautilus-window-slot.h
@@ -73,8 +73,9 @@ void     nautilus_window_slot_stop_loading                 (NautilusWindowSlot *
 const gchar *nautilus_window_slot_get_title                (NautilusWindowSlot *slot);
 void         nautilus_window_slot_update_title            (NautilusWindowSlot *slot);
 
-gboolean nautilus_window_slot_handle_event                (NautilusWindowSlot *slot,
-                                                           GdkEvent           *event);
+gboolean nautilus_window_slot_handle_event                (NautilusWindowSlot    *slot,
+                                                           GtkEventControllerKey *controller,
+                                                           guint                  keyval);
 
 void    nautilus_window_slot_queue_reload                 (NautilusWindowSlot *slot);
 
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index d1f1d5679..7af90d6a9 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -2452,15 +2452,13 @@ nautilus_window_key_bubble (GtkEventControllerKey *controller,
                             GdkModifierType        state,
                             gpointer               user_data)
 {
-    g_autoptr (GdkEvent) event = NULL;
     GtkWidget *widget;
     NautilusWindow *window;
 
-    event = gtk_get_current_event ();
     widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (controller));
     window = NAUTILUS_WINDOW (widget);
     if (window->active_slot != NULL &&
-        nautilus_window_slot_handle_event (window->active_slot, (GdkEvent *) event))
+        nautilus_window_slot_handle_event (window->active_slot, controller, keyval))
     {
         return GDK_EVENT_STOP;
     }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]