256 lines
7.6 KiB
Diff
256 lines
7.6 KiB
Diff
commit d18c74e37dc280432124ab49e85a26af8bb2a2e0
|
|
Author: Daniel P. Berrange <berrange@redhat.com>
|
|
Date: Thu Jan 13 16:16:32 2011 +0000
|
|
|
|
Refactor keymap handling to cope with multiple GDK backends
|
|
|
|
In GTK3 it is possible to have multiple GDK backends present.
|
|
The vncdisplaykeymap code needs a minor refactoring to cope
|
|
with this enhancement. The refactoring also trivially maintains
|
|
GTK2 compat
|
|
|
|
diff --git a/src/vncdisplaykeymap.c b/src/vncdisplaykeymap.c
|
|
index 4ad4732..0ab9bc1 100644
|
|
--- a/src/vncdisplaykeymap.c
|
|
+++ b/src/vncdisplaykeymap.c
|
|
@@ -54,7 +54,7 @@ static struct {
|
|
|
|
static unsigned int ref_count_for_untranslated_keys = 0;
|
|
|
|
-#if defined(GDK_WINDOWING_X11)
|
|
+#ifdef GDK_WINDOWING_X11
|
|
#include <gdk/gdkx.h>
|
|
#include <X11/XKBlib.h>
|
|
#include <stdbool.h>
|
|
@@ -69,15 +69,39 @@ static unsigned int ref_count_for_untranslated_keys = 0;
|
|
/* Xorg Cygwin aka XWin (offset + mangled XT keycodes) */
|
|
#include "vncdisplaykeymap_xorgxwin2rfb.c"
|
|
|
|
-#ifndef GDK_DISPLAY
|
|
-#define GDK_DISPLAY() GDK_DISPLAY_XDISPLAY(gdk_display_get_default())
|
|
+/* Gtk2 compat */
|
|
+#ifndef GDK_IS_X11_DISPLAY
|
|
+#define GDK_IS_X11_DISPLAY(dpy) 1
|
|
#endif
|
|
+#endif
|
|
+
|
|
+#ifdef GDK_WINDOWING_WIN32
|
|
+/* Win32 native virtual keycodes */
|
|
+#include "vncdisplaykeymap_win322rfb.c"
|
|
+
|
|
+/* Gtk2 compat */
|
|
+#ifndef GDK_IS_WIN32_DISPLAY
|
|
+#define GDK_IS_WIN32_DISPLAY(dpy) 1
|
|
+#endif
|
|
+#endif
|
|
+
|
|
+#ifdef GDK_WINDOWING_QUARTZ
|
|
+/* OS-X native keycodes */
|
|
+#include "vncdisplaykeymap_osx2rfb.c"
|
|
+
|
|
+/* Gtk2 compat */
|
|
+#ifndef GDK_IS_QUARTZ_DISPLAY
|
|
+#define GDK_IS_QUARTZ_DISPLAY(dpy) 1
|
|
+#endif
|
|
+#endif
|
|
+
|
|
+#ifdef GDK_WINDOWING_X11
|
|
|
|
#define STRPREFIX(a,b) (strncmp((a),(b),strlen((b))) == 0)
|
|
|
|
-static gboolean check_for_xwin(void)
|
|
+static gboolean check_for_xwin(GdkDisplay *dpy)
|
|
{
|
|
- char *vendor = ServerVendor(GDK_DISPLAY());
|
|
+ char *vendor = ServerVendor(gdk_x11_display_get_xdisplay(dpy));
|
|
|
|
if (strstr(vendor, "Cygwin/X"))
|
|
return TRUE;
|
|
@@ -85,12 +109,13 @@ static gboolean check_for_xwin(void)
|
|
return FALSE;
|
|
}
|
|
|
|
-static gboolean check_for_xquartz(void)
|
|
+static gboolean check_for_xquartz(GdkDisplay *dpy)
|
|
{
|
|
int nextensions;
|
|
int i;
|
|
gboolean match = FALSE;
|
|
- char **extensions = XListExtensions(GDK_DISPLAY(), &nextensions);
|
|
+ char **extensions = XListExtensions(gdk_x11_display_get_xdisplay(dpy),
|
|
+ &nextensions);
|
|
for (i = 0 ; extensions != NULL && i < nextensions ; i++) {
|
|
if (strcmp(extensions[i], "Apple-WM") == 0 ||
|
|
strcmp(extensions[i], "Apple-DRI") == 0)
|
|
@@ -101,98 +126,94 @@ static gboolean check_for_xquartz(void)
|
|
|
|
return match;
|
|
}
|
|
+#endif
|
|
|
|
const guint16 const *vnc_display_keymap_gdk2rfb_table(size_t *maplen)
|
|
{
|
|
- XkbDescPtr desc;
|
|
- const gchar *keycodes = NULL;
|
|
-
|
|
- /* There is no easy way to determine what X11 server
|
|
- * and platform & keyboard driver is in use. Thus we
|
|
- * do best guess heuristics.
|
|
- *
|
|
- * This will need more work for people with other
|
|
- * X servers..... patches welcomed.
|
|
- */
|
|
-
|
|
- desc = XkbGetKeyboard(GDK_DISPLAY(), XkbGBN_AllComponentsMask,
|
|
- XkbUseCoreKbd);
|
|
- if (desc) {
|
|
- if (desc->names) {
|
|
- keycodes = gdk_x11_get_xatom_name(desc->names->keycodes);
|
|
- if (!keycodes)
|
|
- g_warning("could not lookup keycode name");
|
|
+ GdkDisplay *dpy = gdk_display_get_default();
|
|
+
|
|
+#ifdef GDK_WINDOWING_X11
|
|
+ if (GDK_IS_X11_DISPLAY(dpy)) {
|
|
+ XkbDescPtr desc;
|
|
+ const gchar *keycodes = NULL;
|
|
+
|
|
+ /* There is no easy way to determine what X11 server
|
|
+ * and platform & keyboard driver is in use. Thus we
|
|
+ * do best guess heuristics.
|
|
+ *
|
|
+ * This will need more work for people with other
|
|
+ * X servers..... patches welcomed.
|
|
+ */
|
|
+
|
|
+ desc = XkbGetKeyboard(gdk_x11_display_get_xdisplay(dpy),
|
|
+ XkbGBN_AllComponentsMask,
|
|
+ XkbUseCoreKbd);
|
|
+ if (desc) {
|
|
+ if (desc->names) {
|
|
+ keycodes = gdk_x11_get_xatom_name(desc->names->keycodes);
|
|
+ if (!keycodes)
|
|
+ g_warning("could not lookup keycode name");
|
|
+ }
|
|
+ XkbFreeClientMap(desc, XkbGBN_AllComponentsMask, True);
|
|
}
|
|
- XkbFreeClientMap(desc, XkbGBN_AllComponentsMask, True);
|
|
- }
|
|
|
|
- if (check_for_xwin()) {
|
|
- VNC_DEBUG("Using xwin keycode mapping");
|
|
- *maplen = G_N_ELEMENTS(keymap_xorgxwin2rfb);
|
|
- return keymap_xorgxwin2rfb;
|
|
- } else if (check_for_xquartz()) {
|
|
- VNC_DEBUG("Using xquartz keycode mapping");
|
|
- *maplen = G_N_ELEMENTS(keymap_xorgxquartz2rfb);
|
|
- return keymap_xorgxquartz2rfb;
|
|
- } else if (keycodes && STRPREFIX(keycodes, "evdev_")) {
|
|
- VNC_DEBUG("Using evdev keycode mapping");
|
|
- *maplen = G_N_ELEMENTS(keymap_xorgevdev2rfb);
|
|
- return keymap_xorgevdev2rfb;
|
|
- } else if (keycodes && STRPREFIX(keycodes, "xfree86_")) {
|
|
- VNC_DEBUG("Using xfree86 keycode mapping");
|
|
- *maplen = G_N_ELEMENTS(keymap_xorgkbd2rfb);
|
|
- return keymap_xorgkbd2rfb;
|
|
- } else {
|
|
- g_warning("Unknown keycode mapping '%s'.\n"
|
|
- "Please report to gtk-vnc-list@gnome.org\n"
|
|
- "including the following information:\n"
|
|
- "\n"
|
|
- " - Operating system\n"
|
|
- " - GTK build\n"
|
|
- " - X11 Server\n"
|
|
- " - xprop -root\n"
|
|
- " - xdpyinfo\n",
|
|
- keycodes);
|
|
- return NULL;
|
|
+ if (check_for_xwin(dpy)) {
|
|
+ VNC_DEBUG("Using xwin keycode mapping");
|
|
+ *maplen = G_N_ELEMENTS(keymap_xorgxwin2rfb);
|
|
+ return keymap_xorgxwin2rfb;
|
|
+ } else if (check_for_xquartz(dpy)) {
|
|
+ VNC_DEBUG("Using xquartz keycode mapping");
|
|
+ *maplen = G_N_ELEMENTS(keymap_xorgxquartz2rfb);
|
|
+ return keymap_xorgxquartz2rfb;
|
|
+ } else if (keycodes && STRPREFIX(keycodes, "evdev_")) {
|
|
+ VNC_DEBUG("Using evdev keycode mapping");
|
|
+ *maplen = G_N_ELEMENTS(keymap_xorgevdev2rfb);
|
|
+ return keymap_xorgevdev2rfb;
|
|
+ } else if (keycodes && STRPREFIX(keycodes, "xfree86_")) {
|
|
+ VNC_DEBUG("Using xfree86 keycode mapping");
|
|
+ *maplen = G_N_ELEMENTS(keymap_xorgkbd2rfb);
|
|
+ return keymap_xorgkbd2rfb;
|
|
+ } else {
|
|
+ g_warning("Unknown keycode mapping '%s'.\n"
|
|
+ "Please report to gtk-vnc-list@gnome.org\n"
|
|
+ "including the following information:\n"
|
|
+ "\n"
|
|
+ " - Operating system\n"
|
|
+ " - GDK build\n"
|
|
+ " - X11 Server\n"
|
|
+ " - xprop -root\n"
|
|
+ " - xdpyinfo\n",
|
|
+ keycodes);
|
|
+ return NULL;
|
|
+ }
|
|
}
|
|
-}
|
|
-
|
|
-#elif defined(GDK_WINDOWING_WIN32)
|
|
-/* Win32 native virtual keycodes */
|
|
-#include "vncdisplaykeymap_win322rfb.c"
|
|
-
|
|
-const guint16 const *vnc_display_keymap_gdk2rfb_table(size_t *maplen)
|
|
-{
|
|
- VNC_DEBUG("Using Win32 virtual keycode mapping");
|
|
- *maplen = sizeof(keymap_win322rfb);
|
|
- return keymap_win322rfb;
|
|
-}
|
|
-
|
|
-#elif defined(GDK_WINDOWING_QUARTZ)
|
|
-/* OS-X native keycodes */
|
|
-#include "vncdisplaykeymap_osx2rfb.c"
|
|
-
|
|
-const guint16 const *vnc_display_keymap_gdk2rfb_table(size_t *maplen)
|
|
-{
|
|
- VNC_DEBUG("Using OS-X virtual keycode mapping");
|
|
- *maplen = sizeof(keymap_osx2rfb);
|
|
- return keymap_osx2rfb;
|
|
-}
|
|
+#endif
|
|
|
|
+#ifdef GDK_WINDOWING_WIN32
|
|
+ if (GDK_IS_WIN32_DISPLAY(dpy)) {
|
|
+ VNC_DEBUG("Using Win32 virtual keycode mapping");
|
|
+ *maplen = sizeof(keymap_win322rfb);
|
|
+ return keymap_win322rfb;
|
|
+ }
|
|
+#endif
|
|
|
|
-#else
|
|
+#ifdef GDK_WINDOWING_QUARTZ
|
|
+ if (GDK_IS_QUARTZ_DISPLAY(dpy)) {
|
|
+ VNC_DEBUG("Using OS-X virtual keycode mapping");
|
|
+ *maplen = sizeof(keymap_osx2rfb);
|
|
+ return keymap_osx2rfb;
|
|
+ }
|
|
+#endif
|
|
|
|
-const guint16 const *vnc_display_keymap_gdk2rfb_table(size_t *maplen)
|
|
-{
|
|
g_warning("Unsupported GDK Windowing platform.\n"
|
|
+ "Disabling extended keycode tables.\n"
|
|
"Please report to gtk-vnc-list@gnome.org\n"
|
|
"including the following information:\n"
|
|
"\n"
|
|
" - Operating system\n"
|
|
- " - GTK Windowing system build\n");
|
|
+ " - GDK Windowing system build\n");
|
|
return NULL;
|
|
}
|
|
-#endif
|
|
|
|
guint16 vnc_display_keymap_gdk2rfb(const guint16 const *keycode_map,
|
|
size_t keycode_maplen,
|