From 3361fe1e6273d101be6d13dd58e662f43d433e88 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Date: Thu, 22 Mar 2018 18:32:19 +0100 Subject: [PATCH] gtkeventcontrollerkey: Add ::focus-in/out signals And handle GDK_FOCUS_CHANGE events in order to emit those. --- gtk/gtkeventcontrollerkey.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/gtk/gtkeventcontrollerkey.c b/gtk/gtkeventcontrollerkey.c index d1c4f52bc9..3b2700a5e4 100644 --- a/gtk/gtkeventcontrollerkey.c +++ b/gtk/gtkeventcontrollerkey.c @@ -47,6 +47,8 @@ enum { KEY_RELEASED, MODIFIERS, IM_UPDATE, + FOCUS_IN, + FOCUS_OUT, N_SIGNALS }; @@ -77,6 +79,18 @@ gtk_event_controller_key_handle_event (GtkEventController *controller, guint16 keycode; guint keyval; + if (event_type == GDK_FOCUS_CHANGE) + { + gboolean focus_in; + + if (gdk_event_get_focus_in (event, &focus_in) && focus_in) + g_signal_emit (controller, signals[FOCUS_IN], 0); + else + g_signal_emit (controller, signals[FOCUS_OUT], 0); + + return FALSE; + } + if (event_type != GDK_KEY_PRESS && event_type != GDK_KEY_RELEASE) return FALSE; @@ -168,6 +182,20 @@ gtk_event_controller_key_class_init (GtkEventControllerKeyClass *klass) 0, NULL, NULL, g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, 0); + signals[FOCUS_IN] = + g_signal_new (I_("focus-in"), + GTK_TYPE_EVENT_CONTROLLER_KEY, + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); + signals[FOCUS_OUT] = + g_signal_new (I_("focus-out"), + GTK_TYPE_EVENT_CONTROLLER_KEY, + G_SIGNAL_RUN_LAST, + 0, NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); } static void