target/ppc: convert to DisasContextBase
[qemu/ar7.git] / ui / x_keymap.c
blob22e0e77c4d6930c38721517a01d43e0972dc53c9
1 /*
2 * QEMU X11 keymaps
4 * Copyright (C) 2009-2010 Daniel P. Berrange <dan@berrange.com>
5 * Copyright (C) 2017 Red Hat, Inc
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License version 2 as
9 * published by the Free Software Foundation.
12 #include "qemu/osdep.h"
14 #include "x_keymap.h"
15 #include "trace.h"
16 #include "qemu/notify.h"
17 #include "ui/input.h"
19 #include <X11/XKBlib.h>
21 static gboolean check_for_xwin(Display *dpy)
23 const char *vendor = ServerVendor(dpy);
25 trace_xkeymap_vendor(vendor);
27 if (strstr(vendor, "Cygwin/X")) {
28 return TRUE;
31 return FALSE;
34 static gboolean check_for_xquartz(Display *dpy)
36 int nextensions;
37 int i;
38 gboolean match = FALSE;
39 char **extensions = XListExtensions(dpy, &nextensions);
40 for (i = 0 ; extensions != NULL && i < nextensions ; i++) {
41 trace_xkeymap_extension(extensions[i]);
42 if (strcmp(extensions[i], "Apple-WM") == 0 ||
43 strcmp(extensions[i], "Apple-DRI") == 0) {
44 match = TRUE;
47 if (extensions) {
48 XFreeExtensionList(extensions);
51 return match;
54 const guint16 *qemu_xkeymap_mapping_table(Display *dpy, size_t *maplen)
56 XkbDescPtr desc;
57 const gchar *keycodes = NULL;
59 /* There is no easy way to determine what X11 server
60 * and platform & keyboard driver is in use. Thus we
61 * do best guess heuristics.
63 * This will need more work for people with other
64 * X servers..... patches welcomed.
67 desc = XkbGetMap(dpy,
68 XkbGBN_AllComponentsMask,
69 XkbUseCoreKbd);
70 if (desc) {
71 if (XkbGetNames(dpy, XkbKeycodesNameMask, desc) == Success) {
72 keycodes = XGetAtomName (dpy, desc->names->keycodes);
73 if (!keycodes) {
74 g_warning("could not lookup keycode name");
75 } else {
76 trace_xkeymap_keycodes(keycodes);
79 XkbFreeKeyboard(desc, XkbGBN_AllComponentsMask, True);
82 if (check_for_xwin(dpy)) {
83 trace_xkeymap_keymap("xwin");
84 *maplen = qemu_input_map_xorgxwin_to_qcode_len;
85 return qemu_input_map_xorgxwin_to_qcode;
86 } else if (check_for_xquartz(dpy)) {
87 trace_xkeymap_keymap("xquartz");
88 *maplen = qemu_input_map_xorgxquartz_to_qcode_len;
89 return qemu_input_map_xorgxquartz_to_qcode;
90 } else if (keycodes && g_str_has_prefix(keycodes, "evdev")) {
91 trace_xkeymap_keymap("evdev");
92 *maplen = qemu_input_map_xorgevdev_to_qcode_len;
93 return qemu_input_map_xorgevdev_to_qcode;
94 } else if (keycodes && g_str_has_prefix(keycodes, "xfree86")) {
95 trace_xkeymap_keymap("kbd");
96 *maplen = qemu_input_map_xorgkbd_to_qcode_len;
97 return qemu_input_map_xorgkbd_to_qcode;
98 } else {
99 trace_xkeymap_keymap("NULL");
100 g_warning("Unknown X11 keycode mapping '%s'.\n"
101 "Please report to qemu-devel@nongnu.org\n"
102 "including the following information:\n"
103 "\n"
104 " - Operating system\n"
105 " - X11 Server\n"
106 " - xprop -root\n"
107 " - xdpyinfo\n",
108 keycodes ? keycodes : "<null>");
109 return NULL;