summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJérémie Courrèges-Anglas <jca@wxcvbn.org>2014-03-29 18:46:40 +0100
committerJérémie Courrèges-Anglas <jca@wxcvbn.org>2014-03-29 18:46:40 +0100
commitbde541308ee998fd3185500b4362bb404f51ee4c (patch)
tree5eee0a9d8e7d44df5b15dd6a1c72326013bab091
parent8204551023d9b77294947a5170f3428fb5a4a225 (diff)
downloadratpoison-bde541308ee998fd3185500b4362bb404f51ee4c.zip
Detect XKB support at build and runtime.
-rw-r--r--configure.ac19
-rw-r--r--src/input.c52
-rw-r--r--src/input.h2
-rw-r--r--src/main.c1
4 files changed, 69 insertions, 5 deletions
diff --git a/configure.ac b/configure.ac
index 36867cb..67adcb3 100644
--- a/configure.ac
+++ b/configure.ac
@@ -80,6 +80,14 @@ fi
AC_SUBST(XFT_CFLAGS)
AC_SUBST(XFT_LIBS)
+AC_ARG_WITH([xkb],
+ [AS_HELP_STRING([--disable-xkb], [Don't build XKB support for keyboard input.])],
+ [xkb=$withval],
+ [xkb=yes])
+AS_IF([test "X$xkb" = "Xyes"],
+ [AC_DEFINE([WANT_XKB], 1,
+ [Define to 1 if you want to build XKB support for keyboard input.])])
+
AC_MSG_CHECKING([manpage format])
AC_ARG_ENABLE([mdoc],
[AS_HELP_STRING([--disable-mdoc],
@@ -151,9 +159,20 @@ AC_CHECK_HEADERS([X11/extensions/Xinerama.h], [], [], [
])
CPPFLAGS="$mysavedCPPFLAGS"
+mysavedCPPFLAGS="$CPPFLAGS"
+CPPFLAGS="$CPPFLAGS $X_CFLAGS"
+AC_CHECK_HEADERS([X11/XKBlib.h], [], [], [
+#include <X11/Xlib.h>
+])
+CPPFLAGS="$mysavedCPPFLAGS"
+
AC_CHECK_LIB(Xext, XMissingExtension, [X_LIBS="-lXext $X_LIBS"],,$X_LIBS $X_EXTRA_LIBS)
AC_CHECK_LIB(Xinerama, XineramaQueryScreens, [X_LIBS="-lXinerama $X_LIBS"; AC_DEFINE(HAVE_LIBXINERAMA,1,[Xinerama])],,$X_LIBS $X_EXTRA_LIBS)
AC_CHECK_LIB(Xtst, XTestFakeButtonEvent, [X_LIBS="-lXtst $X_LIBS"; AC_DEFINE(HAVE_LIBXTST,1,[Xtst])],,$X_LIBS $X_EXTRA_LIBS)
+AC_CHECK_LIB([X11], [XkbKeycodeToKeysym],
+ [AC_DEFINE(HAVE_XKBKEYCODETOKEYSYM, 1,
+ [Define to 1 if you have the `XkbKeycodeToKeysym' function.])],
+ [], [$X_LIBS $X_EXTRA_LIBS])
AC_SUBST(X_LIBS)
AC_SUBST(X_EXTRA_LIBS)
diff --git a/src/input.c b/src/input.c
index 894b260..2bd4f14 100644
--- a/src/input.c
+++ b/src/input.c
@@ -26,10 +26,13 @@
#include <X11/Xlib.h>
#include <X11/keysym.h>
#include <X11/Xutil.h>
-#include <X11/XKBlib.h>
#include "ratpoison.h"
+#ifdef HAVE_X11_XKBLIB_H
+#include <X11/XKBlib.h>
+#endif
+
/* Convert an X11 modifier mask to the rp modifier mask equivalent, as
best it can (the X server may not have a hyper key defined, for
instance). */
@@ -74,6 +77,45 @@ rp_mask_to_x11_mask (unsigned int mask)
return result;
}
+static Bool use_xkb;
+
+void
+init_xkb (void)
+{
+#if defined (WANT_XKB) && defined (HAVE_X11_XKBLIB_H) && defined (HAVE_XKBKEYCODETOKEYSYM)
+ int error, event, major, minor, opcode;
+
+ major = XkbMajorVersion;
+ minor = XkbMajorVersion;
+
+ use_xkb = XkbLibraryVersion (&major, &minor);
+ if (!use_xkb)
+ {
+ PRINT_ERROR (("Not using XKB, compile and load time version mismatch:"));
+ PRINT_ERROR ((" (%d, %d) vs. (%d, %d)\n", XkbMajorVersion,
+ XkbMajorVersion, major, minor));
+ return;
+ }
+
+ use_xkb = XkbQueryExtension (dpy, &opcode, &event, &error, &major, &minor);
+ if (!use_xkb)
+ PRINT_DEBUG (("Not using XKB, XkbQueryExtension failed\n"));
+#else
+ PRINT_DEBUG (("Built with no XKB support."));
+ use_xkb = False;
+#endif
+}
+
+KeySym
+keycode_to_keysym(Display *dpy, KeyCode kc, int group, int level)
+{
+#if defined (WANT_XKB) && defined (HAVE_X11_XKBLIB_H) && defined (HAVE_XKBKEYCODETOKEYSYM)
+ if (use_xkb)
+ return XkbKeycodeToKeysym (dpy, kc, group, level);
+#endif
+ (void) group;
+ return XKeycodeToKeysym (dpy, kc, level);
+}
/* /\* The caller is responsible for freeing the keycodes. *\/ */
/* KeyCode * */
@@ -252,8 +294,8 @@ keysym_to_keycode_mod (KeySym keysym, KeyCode *code, unsigned int *mod)
*mod = 0;
*code = XKeysymToKeycode (dpy, keysym);
- lower = XkbKeycodeToKeysym (dpy, *code, 0, 0);
- upper = XkbKeycodeToKeysym (dpy, *code, 0, 1);
+ lower = keycode_to_keysym (dpy, *code, 0, 0);
+ upper = keycode_to_keysym (dpy, *code, 0, 1);
/* If you need to press shift to get the keysym, add the shift
mask. */
if (upper == keysym && lower != keysym)
@@ -358,8 +400,8 @@ cook_keycode (XKeyEvent *ev, KeySym *keysym, unsigned int *mod, char *keysym_nam
/* Find out if XLookupString gobbled the shift modifier */
if (ev->state & ShiftMask)
{
- lower = XkbKeycodeToKeysym (dpy, ev->keycode, 0, 0);
- upper = XkbKeycodeToKeysym (dpy, ev->keycode, 0, 1);
+ lower = keycode_to_keysym (dpy, ev->keycode, 0, 0);
+ upper = keycode_to_keysym (dpy, ev->keycode, 0, 1);
/* If the keysym isn't affected by the shift key, then keep the
shift modifier. */
if (lower == upper)
diff --git a/src/input.h b/src/input.h
index 5beb96e..7abb652 100644
--- a/src/input.h
+++ b/src/input.h
@@ -36,4 +36,6 @@ void grab_key (KeySym keysym, unsigned int modifiers, Window grab_window);
void ring_bell (void);
+void init_xkb (void);
+
#endif /* ! _RATPOISON_INPUT_H */
diff --git a/src/main.c b/src/main.c
index 408260a..52dbcce 100644
--- a/src/main.c
+++ b/src/main.c
@@ -751,6 +751,7 @@ main (int argc, char *argv[])
/* Setup ratpoison's internal structures */
init_defaults ();
+ init_xkb ();
init_groups ();
init_window_stuff ();
init_xinerama ();