From 3beb09adca63cce125b08b177cf64fb7eaa84bd5 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Kristian=20H=C3=B8gsberg?= Date: Thu, 10 Feb 2011 10:53:31 -0500 Subject: [PATCH] wayland: Copy translate_keyboard_string() form x11 backend --- gdk/wayland/gdkdevice-wayland.c | 117 ++++++++++++++++++-------------- 1 file changed, 65 insertions(+), 52 deletions(-) diff --git a/gdk/wayland/gdkdevice-wayland.c b/gdk/wayland/gdkdevice-wayland.c index 46abf5861..c95d596cf 100644 --- a/gdk/wayland/gdkdevice-wayland.c +++ b/gdk/wayland/gdkdevice-wayland.c @@ -321,6 +321,70 @@ input_handle_button(void *data, struct wl_input_device *input_device, _gdk_wayland_display_deliver_event (device->display, event); } +static void +translate_keyboard_string (GdkEventKey *event) +{ + gunichar c = 0; + gchar buf[7]; + + /* Fill in event->string crudely, since various programs + * depend on it. + */ + event->string = NULL; + + if (event->keyval != GDK_KEY_VoidSymbol) + c = gdk_keyval_to_unicode (event->keyval); + + if (c) + { + gsize bytes_written; + gint len; + + /* Apply the control key - Taken from Xlib + */ + if (event->state & GDK_CONTROL_MASK) + { + if ((c >= '@' && c < '\177') || c == ' ') c &= 0x1F; + else if (c == '2') + { + event->string = g_memdup ("\0\0", 2); + event->length = 1; + buf[0] = '\0'; + return; + } + else if (c >= '3' && c <= '7') c -= ('3' - '\033'); + else if (c == '8') c = '\177'; + else if (c == '/') c = '_' & 0x1F; + } + + len = g_unichar_to_utf8 (c, buf); + buf[len] = '\0'; + + event->string = g_locale_from_utf8 (buf, len, + NULL, &bytes_written, + NULL); + if (event->string) + event->length = bytes_written; + } + else if (event->keyval == GDK_KEY_Escape) + { + event->length = 1; + event->string = g_strdup ("\033"); + } + else if (event->keyval == GDK_KEY_Return || + event->keyval == GDK_KEY_KP_Enter) + { + event->length = 1; + event->string = g_strdup ("\r"); + } + + if (!event->string) + { + event->length = 0; + event->string = g_strdup (""); + } +} + static void input_handle_key(void *data, struct wl_input_device *input_device, uint32_t time, uint32_t key, uint32_t state) @@ -360,59 +424,8 @@ input_handle_key(void *data, struct wl_input_device *input_device, event->key.is_modifier = modifier > 0; - if (event->key.keyval == GDK_KEY_Escape) - { - event->key.length = 1; - event->key.string = g_strdup ("\033"); - } - else if (event->key.keyval == GDK_KEY_Return || - event->key.keyval == GDK_KEY_KP_Enter) - { - event->key.length = 1; - event->key.string = g_strdup ("\r"); - } - else if (event->key.state & GDK_CONTROL_MASK) - { - gsize bytes_written; - gint len; - gchar buf[7]; - int c = event->key.keyval; - - /* Apply the control key - Taken from Xlib */ - if ((c >= XK_at && c < '\177') || c == ' ') - c &= 0x1F; - else if (c == XK_2) - { - event->key.string = g_memdup ("\0\0", 2); - event->key.length = 1; - buf[0] = '\0'; - goto out; - } - else if (c >= XK_3 && c <= XK_7) - c -= (XK_3 - '\033'); - else if (c == XK_8) - c = '\177'; - else if (c == XK_slash) - c = '_' & 0x1F; - - len = g_unichar_to_utf8 (c, buf); - buf[len] = '\0'; - - event->key.string = g_locale_from_utf8 (buf, len, - NULL, &bytes_written, - NULL); - if (event->key.string) - event->key.length = bytes_written; - } - else - { - char buffer[128]; - xkb_keysym_to_string(event->key.keyval, buffer, sizeof buffer); - event->key.string = g_strdup (buffer); - event->key.length = strlen(event->key.string); - } + translate_keyboard_string (&event->key); - out: _gdk_wayland_display_deliver_event (device->display, event); fprintf (stderr, "keyboard event, code %d, sym %d, string %s, mods 0x%x\n", -- 2.43.2