[gtk/wip/carlosg/fix-search-entry: 1/4] gtksearchentry: Separate checks about whether a key press would show search



commit 7cb9511bd748147b0e67a116036adffd125a06a3
Author: Carlos Garnacho <carlosg gnome org>
Date:   Mon Feb 18 19:59:45 2019 +0100

    gtksearchentry: Separate checks about whether a key press would show search
    
    Since delivering events to unmapped children is forbidden, we need to
    disociate the entry being shown from the entry handling events. Add an
    explicit check that may be done beforehand.

 gtk/gtksearchentry.c        | 25 +++++++++++++++++++++----
 gtk/gtksearchentryprivate.h |  3 +++
 2 files changed, 24 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtksearchentry.c b/gtk/gtksearchentry.c
index b2368c308a..ab6a3910b6 100644
--- a/gtk/gtksearchentry.c
+++ b/gtk/gtksearchentry.c
@@ -406,6 +406,22 @@ gtk_search_entry_is_keynav (guint           keyval,
   return FALSE;
 }
 
+gboolean
+gtk_search_entry_should_trigger (guint           keyval,
+                                 GdkModifierType state)
+{
+  if (gtk_search_entry_is_keynav (keyval, state) ||
+      keyval == GDK_KEY_space ||
+      keyval == GDK_KEY_Menu)
+    return FALSE;
+
+  if ((state & (GDK_CONTROL_MASK | GDK_MOD1_MASK |
+                GDK_SUPER_MASK | GDK_HYPER_MASK)) != 0)
+    return FALSE;
+
+  return g_unichar_isprint (gdk_keyval_to_unicode (keyval));
+}
+
 /**
  * gtk_search_entry_handle_event:
  * @entry: a #GtkSearchEntry
@@ -464,9 +480,7 @@ capture_widget_key_handled (GtkEventControllerKey *controller,
   GtkSearchEntryPrivate *priv = gtk_search_entry_get_instance_private (GTK_SEARCH_ENTRY (entry));
   gboolean handled;
 
-  if (gtk_search_entry_is_keynav (keyval, state) ||
-      keyval == GDK_KEY_space ||
-      keyval == GDK_KEY_Menu)
+  if (!gtk_search_entry_should_trigger (keyval, state))
     return FALSE;
 
   priv->content_changed = FALSE;
@@ -474,7 +488,10 @@ capture_widget_key_handled (GtkEventControllerKey *controller,
 
   handled = gtk_event_controller_key_forward (controller, entry);
 
-  return handled && priv->content_changed && !priv->search_stopped ? GDK_EVENT_STOP : GDK_EVENT_PROPAGATE;
+  if (priv->search_stopped)
+    return GDK_EVENT_PROPAGATE;
+
+  return handled;
 }
 
 /**
diff --git a/gtk/gtksearchentryprivate.h b/gtk/gtksearchentryprivate.h
index 1b0706d412..5dce5485ac 100644
--- a/gtk/gtksearchentryprivate.h
+++ b/gtk/gtksearchentryprivate.h
@@ -32,6 +32,9 @@ G_BEGIN_DECLS
 gboolean gtk_search_entry_is_keynav (guint           keyval,
                                      GdkModifierType state);
 
+gboolean gtk_search_entry_should_trigger (guint           keyval,
+                                          GdkModifierType state);
+
 G_END_DECLS
 
 #endif /* __GTK_SEARCH_ENTRY_PRIVATE_H__ */


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