diff options
author | Alexander Mikhaylenko <alexm@gnome.org> | 2021-01-20 17:13:59 +0500 |
---|---|---|
committer | Alexander Mikhaylenko <alexm@gnome.org> | 2021-01-20 17:19:05 +0500 |
commit | 7a966ec60eb8411c252805240cfb2d0e905faab8 (patch) | |
tree | 27746e7fd2fe4392e307fd149a084dcab81c8a76 | |
parent | d7050c63aec46b0c265b21911bcc44331b3aa92c (diff) | |
download | gtk+-wip/exalm/searchbar.tar.gz |
searchbar: Don't activate type-to-search when focusing entrieswip/exalm/searchbar
Currently using GtkSearchBar:key-capture-widget steals focus from unrelated
entries within the key capture widget, which is a common case when the key
capture widget is the window containing the search bar.
In theory it can be fixed by switching the propagation phase to bubble, but
there's a good chance that keypresses will then be intercepted by some
other widget when not wanted.
So, instead do a hack and check the type of the focused widget, skipping
if it's a GtkEditable or GtkTextView, and additionally has the `editable`
property set to TRUE.
Fixes https://gitlab.gnome.org/GNOME/gtk/-/issues/3606
-rw-r--r-- | gtk/gtksearchbar.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/gtk/gtksearchbar.c b/gtk/gtksearchbar.c index c1a23bf304..026bd769be 100644 --- a/gtk/gtksearchbar.c +++ b/gtk/gtksearchbar.c @@ -40,6 +40,7 @@ #include "gtkrevealer.h" #include "gtksearchentryprivate.h" #include "gtksnapshot.h" +#include "gtktextview.h" #include "gtkwidgetprivate.h" /** @@ -520,6 +521,7 @@ capture_widget_key_handled (GtkEventControllerKey *controller, GtkSearchBar *bar) { gboolean handled; + GtkWidget *focus; if (!gtk_widget_get_mapped (GTK_WIDGET (bar))) return GDK_EVENT_PROPAGATE; @@ -527,6 +529,19 @@ capture_widget_key_handled (GtkEventControllerKey *controller, if (bar->reveal_child) return GDK_EVENT_PROPAGATE; + focus = gtk_root_get_focus (gtk_widget_get_root (GTK_WIDGET (bar->capture_widget))); + + /* Make sure type-to-search does not interfere with entries or text views */ + if (GTK_IS_EDITABLE (focus) || GTK_IS_TEXT_VIEW (focus)) { + gboolean editable; + + /* Take a shortcut as both GtkEditable and GtkTextView have this property */ + g_object_get (focus, "editable", &editable, NULL); + + if (editable) + return GDK_EVENT_PROPAGATE; + } + if (bar->entry == NULL) { g_warning ("The search bar does not have an entry connected to it. Call gtk_search_bar_connect_entry() to connect one."); |