Add private accessor for GdkKeyEvent.translated

Avoid accessing the event structure directly, even from within GTK.
This commit is contained in:
Emmanuele Bassi 2020-05-22 12:35:58 +01:00
parent be8fc8f26b
commit 0cf5b66e7b
2 changed files with 29 additions and 0 deletions

View File

@ -1466,6 +1466,32 @@ gdk_key_event_new (GdkEventType type,
return event;
}
/*< private >
* gdk_key_event_get_translated_key:
* @event: (type GdkKeyEvent): a key event
* @no_lock: whether the translated key should take the event
* state into account
*
* Extracts the translated key from a key event.
*
* Returns: (transfer none): the translated key
*/
GdkTranslatedKey *
gdk_key_event_get_translated_key (GdkEvent *event,
gboolean no_lock)
{
GdkKeyEvent *self = (GdkKeyEvent *) event;
g_return_val_if_fail (GDK_IS_EVENT (event), NULL);
g_return_val_if_fail (GDK_IS_EVENT_TYPE (event, GDK_KEY_PRESS) ||
GDK_IS_EVENT_TYPE (event, GDK_KEY_RELEASE), NULL);
if (no_lock)
return &(self->translated[1]);
return &(self->translated[0]);
}
/**
* gdk_key_event_get_keyval:
* @event: (type GdkKeyEvent): a key event

View File

@ -612,6 +612,9 @@ GdkEvent * gdk_grab_broken_event_new (GdkSurface *surface,
GdkSurface *grab_surface,
gboolean implicit);
GdkTranslatedKey * gdk_key_event_get_translated_key (GdkEvent *event,
gboolean no_lock);
G_END_DECLS
#endif /* __GDK_EVENTS_PRIVATE_H__ */