From a44d56605748fe225d100417b874b7a3afe1a34e Mon Sep 17 00:00:00 2001 From: Marcus Date: Mon, 3 Jan 2011 21:44:05 +0100 Subject: [PATCH] Added compile time detection of the XKB X11 extension. --- CMakeLists.txt | 4 ++++ src/config.h.in | 3 +++ src/x11/platform.h | 9 ++++++--- src/x11/x11_init.c | 15 ++++++++++++--- src/x11/x11_window.c | 2 +- 5 files changed, 26 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c99d1fc8..65b494f1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -74,6 +74,10 @@ if (UNIX AND NOT APPLE AND NOT CYGWIN) list(APPEND GLFW_LIBRARIES ${X11_XF86VIDMODE_LIBRARIES}) endif(X11_XF86VIDMODE_FOUND) + # Check for Xkb (X keyboard extension) + CHECK_FUNCTION_EXISTS(XkbQueryExtension _GLFW_HAS_XKB) + + # Check for glXGetProcAddress CHECK_FUNCTION_EXISTS(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS) if (NOT _GLFW_HAS_GLXGETPROCADDRESS) diff --git a/src/config.h.in b/src/config.h.in index b1c77e73..0c547597 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -40,6 +40,9 @@ // Define this to 1 if Xf86VidMode is available #cmakedefine _GLFW_HAS_XF86VIDMODE 1 +// Define this to 1 if Xkb is available +#cmakedefine _GLFW_HAS_XKB 1 + // Define this to 1 if glXGetProcAddress is available #cmakedefine _GLFW_HAS_GLXGETPROCADDRESS 1 // Define this to 1 if glXGetProcAddressARB is available diff --git a/src/x11/platform.h b/src/x11/platform.h index a370df0b..b5e18e90 100644 --- a/src/x11/platform.h +++ b/src/x11/platform.h @@ -67,8 +67,9 @@ #endif // The Xkb extension provides improved keyboard support -#include - +#if defined(_GLFW_HAS_XKB) + #include +#endif #ifndef GL_VERSION_3_0 @@ -183,9 +184,11 @@ typedef struct _GLFWlibraryX11 int errorBase; int majorVersion; int minorVersion; - int keyCodeLUT[256]; } Xkb; + // Key code LUT (mapping X11 key codes to GLFW key codes) + int keyCodeLUT[256]; + // Screensaver data struct { GLboolean changed; diff --git a/src/x11/x11_init.c b/src/x11/x11_init.c index 2f23e334..f4f9d0b8 100644 --- a/src/x11/x11_init.c +++ b/src/x11/x11_init.c @@ -68,16 +68,20 @@ static void initLibraries(void) static void updateKeyCodeLUT(void) { - int i, keyCode, keyCodeGLFW; +#if defined(_GLFW_HAS_XKB) + int keyCode, keyCodeGLFW; char name[XkbKeyNameLength+1]; XkbDescPtr descr; +#endif + int i; // Clear the LUT for (i = 0; i < 256; ++i) { - _glfwLibrary.X11.Xkb.keyCodeLUT[i] = -1; + _glfwLibrary.X11.keyCodeLUT[i] = -1; } +#if defined(_GLFW_HAS_XKB) // This functionality requires the Xkb extension if (!_glfwLibrary.X11.Xkb.available) { @@ -154,12 +158,13 @@ static void updateKeyCodeLUT(void) // Update the key code LUT if ((keyCode >= 0) && (keyCode < 256)) { - _glfwLibrary.X11.Xkb.keyCodeLUT[keyCode] = keyCodeGLFW; + _glfwLibrary.X11.keyCodeLUT[keyCode] = keyCodeGLFW; } } // Free the keyboard description XkbFreeKeyboard(descr, 0, True); +#endif /* _GLFW_HAS_XKB */ } @@ -228,6 +233,7 @@ static GLboolean initDisplay(void) } // Check if Xkb is supported on this display +#if defined(_GLFW_HAS_XKB) _glfwLibrary.X11.Xkb.majorVersion = 1; _glfwLibrary.X11.Xkb.minorVersion = 0; _glfwLibrary.X11.Xkb.available = @@ -237,6 +243,9 @@ static GLboolean initDisplay(void) &_glfwLibrary.X11.Xkb.errorBase, &_glfwLibrary.X11.Xkb.majorVersion, &_glfwLibrary.X11.Xkb.minorVersion); +#else + _glfwLibrary.X11.Xkb.available = GL_FALSE; +#endif /* _GLFW_HAS_XKB */ // Update the key code LUT // FIXME: We should listen to XkbMapNotify events to track changes to diff --git a/src/x11/x11_window.c b/src/x11/x11_window.c index 2879ecb0..5e1c15c6 100644 --- a/src/x11/x11_window.c +++ b/src/x11/x11_window.c @@ -335,7 +335,7 @@ static int translateKey(int keycode) // a positive result if we have the Xkb extension. if ((keycode >= 0) && (keycode < 256)) { - int result = _glfwLibrary.X11.Xkb.keyCodeLUT[keycode]; + int result = _glfwLibrary.X11.keyCodeLUT[keycode]; if (result >= 0) { return result;