Patchwork gtk: Add handling for the xfree86 keycodes

login
register
mail settings
Submitter Bruce Rogers
Date May 1, 2014, 2:29 a.m.
Message ID <1398911382-23291-1-git-send-email-brogers@suse.com>
Download mbox | patch
Permalink /patch/344393/
State New
Headers show

Comments

Bruce Rogers - May 1, 2014, 2:29 a.m.
Currently only evdev keycodes are handled by the gtk-ui. SDL has
code to handle both. This patch adds similar processing so that
both keycode types will be handled via the gtk-ui.

Signed-off-by: Bruce Rogers <brogers@suse.com>
---
 ui/gtk.c | 36 +++++++++++++++++++++++++++++++++++-
 1 file changed, 35 insertions(+), 1 deletion(-)

Patch

diff --git a/ui/gtk.c b/ui/gtk.c
index 00fbbcc..461c65e 100644
--- a/ui/gtk.c
+++ b/ui/gtk.c
@@ -67,6 +67,10 @@ 
 #include "x_keymap.h"
 #include "keymaps.h"
 #include "sysemu/char.h"
+#ifndef _WIN32
+#include <gdk/gdkx.h>
+#include <X11/XKBlib.h>
+#endif
 
 #define MAX_VCS 10
 
@@ -173,6 +177,7 @@  typedef struct GtkDisplayState
     bool external_pause_update;
 
     bool modifier_pressed[ARRAY_SIZE(modifier_keycode)];
+    bool has_evdev;
 } GtkDisplayState;
 
 static GtkDisplayState *global_state;
@@ -757,7 +762,11 @@  static gboolean gd_key_event(GtkWidget *widget, GdkEventKey *key, void *opaque)
     } else if (gdk_keycode < 97) {
         qemu_keycode = gdk_keycode - 8;
     } else if (gdk_keycode < 158) {
-        qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
+        if (s->has_evdev) {
+            qemu_keycode = translate_evdev_keycode(gdk_keycode - 97);
+        } else {
+            qemu_keycode = translate_xfree86_keycode(gdk_keycode - 97);
+        }
     } else if (gdk_keycode == 208) { /* Hiragana_Katakana */
         qemu_keycode = 0x70;
     } else if (gdk_keycode == 211) { /* backslash */
@@ -1487,6 +1496,29 @@  static void gd_create_menus(GtkDisplayState *s)
     s->accel_group = accel_group;
 }
 
+static void gd_set_keycode_type(GtkDisplayState *s)
+{
+#ifndef _WIN32
+    char *keycodes = NULL;
+    GdkDisplay *display = gtk_widget_get_display(s->drawing_area);
+    Display *x11_display = gdk_x11_display_get_xdisplay(display);
+    XkbDescPtr desc = XkbGetKeyboard(x11_display, XkbGBN_AllComponentsMask,
+                                     XkbUseCoreKbd);
+
+    if (desc && desc->names) {
+        keycodes = XGetAtomName(x11_display, desc->names->keycodes);
+    }
+    if (keycodes == NULL) {
+        fprintf(stderr, "could not lookup keycode name\n");
+    } else if (strstart(keycodes, "evdev", NULL)) {
+        s->has_evdev = true;
+    } else if (!strstart(keycodes, "xfree86", NULL)) {
+        fprintf(stderr, "unknown keycodes `%s', please report to "
+                "qemu-devel@nongnu.org\n", keycodes);
+    }
+#endif
+}
+
 static const DisplayChangeListenerOps dcl_ops = {
     .dpy_name          = "gtk",
     .dpy_gfx_update    = gd_update,
@@ -1581,5 +1613,7 @@  void gtk_display_init(DisplayState *ds, bool full_screen, bool grab_on_hover)
 
     register_displaychangelistener(&s->dcl);
 
+    gd_set_keycode_type(s);
+
     global_state = s;
 }