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



commit d47a60b3bcf54dedda62dbbd2435a62313ad7aff
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 |  2 ++
 2 files changed, 23 insertions(+), 4 deletions(-)
---
diff --git a/gtk/gtksearchentry.c b/gtk/gtksearchentry.c
index a73e32963d..f11f248545 100644
--- a/gtk/gtksearchentry.c
+++ b/gtk/gtksearchentry.c
@@ -556,6 +556,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
@@ -614,9 +630,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;
@@ -624,7 +638,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 46b5d9f5b9..63a381dc0f 100644
--- a/gtk/gtksearchentryprivate.h
+++ b/gtk/gtksearchentryprivate.h
@@ -31,6 +31,8 @@ G_BEGIN_DECLS
 
 gboolean gtk_search_entry_is_keynav (guint           keyval,
                                      GdkModifierType state);
+gboolean gtk_search_entry_should_trigger (guint           keyval,
+                                          GdkModifierType state);
 
 GtkEventController * gtk_search_entry_get_key_controller (GtkSearchEntry *entry);
 


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