gtkeventcontrollerkey: Add ::focus-in/out signals

And handle GDK_FOCUS_CHANGE events in order to emit those.
This commit is contained in:
Carlos Garnacho 2018-03-22 18:32:19 +01:00
parent 5a34d0f816
commit 3361fe1e62

View File

@ -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