[gtk/wip/exalm/searchbar] searchbar: Don't activate type-to-search when focusing entries
- From: Alexander Mikhaylenko <alexm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/exalm/searchbar] searchbar: Don't activate type-to-search when focusing entries
- Date: Wed, 20 Jan 2021 12:26:25 +0000 (UTC)
commit 7a966ec60eb8411c252805240cfb2d0e905faab8
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Wed Jan 20 17:13:59 2021 +0500
searchbar: Don't activate type-to-search when focusing entries
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
gtk/gtksearchbar.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
---
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.");
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]