From 3eb1b226511f682b6a47e4fe969b0d423c870732 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 7 Jun 2018 00:49:04 +0200 Subject: [PATCH] gtkfontchooser: Use GtkEventControllerKey Use an event controller on GtkFontChooserDialog, a nice side effect is that we can use gtk_event_controller_key_forward() and gtk_search_entry_set_key_capture_widget() instead of passing events around for dialog search. --- gtk/gtkfontchooserdialog.c | 23 +++++++++-------------- gtk/gtkfontchooserwidget.c | 14 +++----------- gtk/gtkfontchooserwidgetprivate.h | 3 --- gtk/ui/gtkfontchooserdialog.ui | 6 ++++++ 4 files changed, 18 insertions(+), 28 deletions(-) diff --git a/gtk/gtkfontchooserdialog.c b/gtk/gtkfontchooserdialog.c index 0208040ef7..2604b03dc0 100644 --- a/gtk/gtkfontchooserdialog.c +++ b/gtk/gtkfontchooserdialog.c @@ -39,6 +39,7 @@ #include "gtktogglebutton.h" #include "gtkheaderbar.h" #include "gtkactionable.h" +#include "gtkeventcontrollerkey.h" struct _GtkFontChooserDialogPrivate { @@ -124,21 +125,15 @@ font_activated_cb (GtkFontChooser *fontchooser, } static gboolean -gtk_font_chooser_dialog_event (GtkWidget *dialog, - GdkEvent *event) +dialog_forward_key (GtkEventControllerKey *controller, + guint keyval, + guint keycode, + GdkModifierType modifiers, + GtkWidget *widget) { - GtkFontChooserDialog *fdialog = GTK_FONT_CHOOSER_DIALOG (dialog); - gboolean handled = FALSE; + GtkFontChooserDialog *fdialog = GTK_FONT_CHOOSER_DIALOG (widget); - if (gdk_event_get_event_type (event) != GDK_KEY_PRESS) - return GDK_EVENT_PROPAGATE; - - handled = GTK_WIDGET_CLASS (gtk_font_chooser_dialog_parent_class)->event (dialog, event); - - if (!handled) - handled = gtk_font_chooser_widget_handle_event (fdialog->priv->fontchooser, (GdkEventKey *)event); - - return handled; + return gtk_event_controller_key_forward (controller, fdialog->priv->fontchooser); } static void @@ -208,7 +203,6 @@ gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass) gobject_class->get_property = gtk_font_chooser_dialog_get_property; gobject_class->set_property = gtk_font_chooser_dialog_set_property; - widget_class->event = gtk_font_chooser_dialog_event; widget_class->map = gtk_font_chooser_dialog_map; _gtk_font_chooser_install_properties (gobject_class); @@ -222,6 +216,7 @@ gtk_font_chooser_dialog_class_init (GtkFontChooserDialogClass *klass) gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserDialog, select_button); gtk_widget_class_bind_template_child_private (widget_class, GtkFontChooserDialog, cancel_button); gtk_widget_class_bind_template_callback (widget_class, font_activated_cb); + gtk_widget_class_bind_template_callback (widget_class, dialog_forward_key); } static void diff --git a/gtk/gtkfontchooserwidget.c b/gtk/gtkfontchooserwidget.c index 6b161f084c..442bc81540 100644 --- a/gtk/gtkfontchooserwidget.c +++ b/gtk/gtkfontchooserwidget.c @@ -881,6 +881,9 @@ 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)); } /** @@ -2520,17 +2523,6 @@ gtk_font_chooser_widget_iface_init (GtkFontChooserIface *iface) iface->get_font_map = gtk_font_chooser_widget_get_font_map; } -gboolean -gtk_font_chooser_widget_handle_event (GtkWidget *widget, - GdkEventKey *key_event) -{ - GtkFontChooserWidget *fontchooser = GTK_FONT_CHOOSER_WIDGET (widget); - GtkFontChooserWidgetPrivate *priv = fontchooser->priv; - GdkEvent *event = (GdkEvent *)key_event; - - return gtk_search_entry_handle_event (GTK_SEARCH_ENTRY (priv->search_entry), event); -} - GAction * gtk_font_chooser_widget_get_tweak_action (GtkWidget *widget) { diff --git a/gtk/gtkfontchooserwidgetprivate.h b/gtk/gtkfontchooserwidgetprivate.h index 5abdc5e47b..1a7dd743ec 100644 --- a/gtk/gtkfontchooserwidgetprivate.h +++ b/gtk/gtkfontchooserwidgetprivate.h @@ -22,9 +22,6 @@ G_BEGIN_DECLS -gboolean gtk_font_chooser_widget_handle_event (GtkWidget *widget, - GdkEventKey *event); - GAction *gtk_font_chooser_widget_get_tweak_action (GtkWidget *fontchooser); G_END_DECLS diff --git a/gtk/ui/gtkfontchooserdialog.ui b/gtk/ui/gtkfontchooserdialog.ui index c3b2882be3..e6fb4ec3a6 100644 --- a/gtk/ui/gtkfontchooserdialog.ui +++ b/gtk/ui/gtkfontchooserdialog.ui @@ -33,6 +33,12 @@ 1 + + + + + + cancel_button select_button