[gtk/font-chooser-search] fontchooser: Fix type-to-search
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/font-chooser-search] fontchooser: Fix type-to-search
- Date: Sat, 27 Apr 2019 16:02:34 +0000 (UTC)
commit 6277f2fccc3b7da589a34a410a3699000404aa05
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Apr 27 15:59:45 2019 +0000
fontchooser: Fix type-to-search
The key capture was interfering with other
entries in the dialog, so be smarter about
when we want to capture keys and when we
don't.
Closes: https://gitlab.gnome.org/GNOME/gtk/issues/1842
gtk/gtkfontchooserwidget.c | 64 +++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 61 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c
index 4f9954fd64..b5cc584c77 100644
--- a/gtk/gtkfontchooserwidget.c
+++ b/gtk/gtkfontchooserwidget.c
@@ -55,6 +55,7 @@
#include "gtkcombobox.h"
#include "gtkgesturemultipress.h"
#include "gtkeventcontrollerscroll.h"
+#include "gtkroot.h"
#if defined(HAVE_HARFBUZZ) && defined(HAVE_PANGOFT)
#include <pango/pangofc-font.h>
@@ -617,6 +618,35 @@ rows_changed_cb (GtkFontChooserWidget *fontchooser)
gtk_stack_set_visible_child_name (GTK_STACK (priv->list_stack), page);
}
+static void
+update_key_capture (GtkWidget *chooser)
+{
+ GtkFontChooserWidgetPrivate *priv;
+ GtkWidget *capture_widget;
+
+ priv = gtk_font_chooser_widget_get_instance_private (GTK_FONT_CHOOSER_WIDGET (chooser));
+
+ if (gtk_widget_get_mapped (chooser) &&
+ g_str_equal (gtk_stack_get_visible_child_name (GTK_STACK (priv->stack)), "list"))
+ {
+ GtkWidget *toplevel;
+ GtkWidget *focus;
+
+ toplevel = gtk_widget_get_toplevel (chooser);
+ focus = gtk_root_get_focus (GTK_ROOT (toplevel));
+
+ if (GTK_IS_EDITABLE (focus) && focus != priv->search_entry)
+ capture_widget = NULL;
+ else
+ capture_widget = chooser;
+ }
+ else
+ capture_widget = NULL;
+
+ gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (priv->search_entry),
+ capture_widget);
+}
+
static void
gtk_font_chooser_widget_map (GtkWidget *widget)
{
@@ -628,6 +658,34 @@ gtk_font_chooser_widget_map (GtkWidget *widget)
g_simple_action_set_state (G_SIMPLE_ACTION (priv->tweak_action), g_variant_new_boolean (FALSE));
GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->map (widget);
+
+ update_key_capture (widget);
+}
+
+static void
+gtk_font_chooser_widget_unmap (GtkWidget *widget)
+{
+ update_key_capture (widget);
+
+ GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->unmap (widget);
+}
+
+static void
+gtk_font_chooser_widget_root (GtkWidget *widget)
+{
+ GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->root (widget);
+
+ g_signal_connect_swapped (gtk_widget_get_root (widget), "notify::focus-widget",
+ G_CALLBACK (update_key_capture), widget);
+ }
+
+static void
+gtk_font_chooser_widget_unroot (GtkWidget *widget)
+{
+ g_signal_handlers_disconnect_by_func (gtk_widget_get_root (widget),
+ update_key_capture, widget);
+
+ GTK_WIDGET_CLASS (gtk_font_chooser_widget_parent_class)->unroot (widget);
}
static void
@@ -688,7 +746,10 @@ gtk_font_chooser_widget_class_init (GtkFontChooserWidgetClass *klass)
widget_class->display_changed = gtk_font_chooser_widget_display_changed;
widget_class->measure = gtk_font_chooser_widget_measure;
widget_class->size_allocate = gtk_font_chooser_widget_size_allocate;
+ widget_class->root = gtk_font_chooser_widget_root;
+ widget_class->unroot = gtk_font_chooser_widget_unroot;
widget_class->map = gtk_font_chooser_widget_map;
+ widget_class->unmap = gtk_font_chooser_widget_unmap;
gobject_class->finalize = gtk_font_chooser_widget_finalize;
gobject_class->dispose = gtk_font_chooser_widget_dispose;
@@ -876,9 +937,6 @@ gtk_font_chooser_widget_init (GtkFontChooserWidget *fontchooser)
gtk_font_chooser_widget_set_cell_size (fontchooser);
gtk_font_chooser_widget_take_font_desc (fontchooser, NULL);
-
- gtk_search_entry_set_key_capture_widget (GTK_SEARCH_ENTRY (priv->search_entry),
- GTK_WIDGET (fontchooser));
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]