[gnome-builder] libide: add synthesize key helper for keyval
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide: add synthesize key helper for keyval
- Date: Thu, 15 Oct 2015 20:03:39 +0000 (UTC)
commit 312ea45f8ad749000cb534e70f6b66a3ffa16483
Author: Christian Hergert <chergert redhat com>
Date: Thu Oct 15 12:58:54 2015 -0700
libide: add synthesize key helper for keyval
I'm going to need this for some prototyping, so might as well be proactive
and push it forward now. It's not great that we do this sort of
synthesis, but it is what it is.
It is certainly useful for unit tests.
libide/util/ide-gdk.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++
libide/util/ide-gdk.h | 6 +++-
2 files changed, 57 insertions(+), 2 deletions(-)
---
diff --git a/libide/util/ide-gdk.c b/libide/util/ide-gdk.c
index dfd6f0f..373b729 100644
--- a/libide/util/ide-gdk.c
+++ b/libide/util/ide-gdk.c
@@ -88,3 +88,56 @@ ide_gdk_synthesize_event_key (GdkWindow *window,
return &ev->key;
}
+
+GdkEventKey *
+ide_gdk_synthesize_event_keyval (GdkWindow *window,
+ guint keyval)
+{
+ GdkDisplay *display;
+ GdkDeviceManager *device_manager;
+ GdkDevice *client_pointer;
+ GdkEvent *ev;
+ GdkKeymapKey *keys = NULL;
+ gint n_keys = 0;
+ gchar str[8] = { 0 };
+ gunichar ch;
+
+ g_assert (window != NULL);
+ g_assert (GDK_IS_WINDOW (window));
+
+ ch = gdk_keyval_to_unicode (keyval);
+ g_unichar_to_utf8 (ch, str);
+
+ ev = gdk_event_new (GDK_KEY_PRESS);
+ ev->key.window = g_object_ref (window);
+ ev->key.send_event = TRUE;
+ ev->key.time = gtk_get_current_event_time ();
+ ev->key.state = 0;
+ ev->key.hardware_keycode = 0;
+ ev->key.group = 0;
+ ev->key.is_modifier = 0;
+ ev->key.keyval = keyval;
+ ev->key.string = g_strdup (str);
+ ev->key.length = strlen (str);
+
+ gdk_keymap_get_entries_for_keyval (gdk_keymap_get_default (),
+ ev->key.keyval,
+ &keys,
+ &n_keys);
+
+ if (n_keys > 0)
+ {
+ ev->key.hardware_keycode = keys [0].keycode;
+ ev->key.group = keys [0].group;
+ if (keys [0].level == 1)
+ ev->key.state |= GDK_SHIFT_MASK;
+ g_free (keys);
+ }
+
+ display = gdk_window_get_display (ev->any.window);
+ device_manager = gdk_display_get_device_manager (display);
+ client_pointer = gdk_device_manager_get_client_pointer (device_manager);
+ gdk_event_set_device (ev, gdk_device_get_associated_device (client_pointer));
+
+ return &ev->key;
+}
diff --git a/libide/util/ide-gdk.h b/libide/util/ide-gdk.h
index d20868a..b540bc4 100644
--- a/libide/util/ide-gdk.h
+++ b/libide/util/ide-gdk.h
@@ -23,8 +23,10 @@
G_BEGIN_DECLS
-GdkEventKey *ide_gdk_synthesize_event_key (GdkWindow *window,
- gunichar ch);
+GdkEventKey *ide_gdk_synthesize_event_key (GdkWindow *window,
+ gunichar ch);
+GdkEventKey *ide_gdk_synthesize_event_keyval (GdkWindow *window,
+ guint keyval);
G_END_DECLS
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]