1
0
Fork 0
mirror of https://github.com/gwm17/glfw.git synced 2024-10-08 07:07:25 -04:00

Added compile time detection of the XKB X11 extension.

This commit is contained in:
Marcus 2011-01-03 21:44:05 +01:00
parent c0cb4c2fe1
commit a44d566057
5 changed files with 26 additions and 7 deletions

View File

@ -74,6 +74,10 @@ if (UNIX AND NOT APPLE AND NOT CYGWIN)
list(APPEND GLFW_LIBRARIES ${X11_XF86VIDMODE_LIBRARIES}) list(APPEND GLFW_LIBRARIES ${X11_XF86VIDMODE_LIBRARIES})
endif(X11_XF86VIDMODE_FOUND) 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) CHECK_FUNCTION_EXISTS(glXGetProcAddress _GLFW_HAS_GLXGETPROCADDRESS)
if (NOT _GLFW_HAS_GLXGETPROCADDRESS) if (NOT _GLFW_HAS_GLXGETPROCADDRESS)

View File

@ -40,6 +40,9 @@
// Define this to 1 if Xf86VidMode is available // Define this to 1 if Xf86VidMode is available
#cmakedefine _GLFW_HAS_XF86VIDMODE 1 #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 // Define this to 1 if glXGetProcAddress is available
#cmakedefine _GLFW_HAS_GLXGETPROCADDRESS 1 #cmakedefine _GLFW_HAS_GLXGETPROCADDRESS 1
// Define this to 1 if glXGetProcAddressARB is available // Define this to 1 if glXGetProcAddressARB is available

View File

@ -67,8 +67,9 @@
#endif #endif
// The Xkb extension provides improved keyboard support // The Xkb extension provides improved keyboard support
#if defined(_GLFW_HAS_XKB)
#include <X11/XKBlib.h> #include <X11/XKBlib.h>
#endif
#ifndef GL_VERSION_3_0 #ifndef GL_VERSION_3_0
@ -183,9 +184,11 @@ typedef struct _GLFWlibraryX11
int errorBase; int errorBase;
int majorVersion; int majorVersion;
int minorVersion; int minorVersion;
int keyCodeLUT[256];
} Xkb; } Xkb;
// Key code LUT (mapping X11 key codes to GLFW key codes)
int keyCodeLUT[256];
// Screensaver data // Screensaver data
struct { struct {
GLboolean changed; GLboolean changed;

View File

@ -68,16 +68,20 @@ static void initLibraries(void)
static void updateKeyCodeLUT(void) static void updateKeyCodeLUT(void)
{ {
int i, keyCode, keyCodeGLFW; #if defined(_GLFW_HAS_XKB)
int keyCode, keyCodeGLFW;
char name[XkbKeyNameLength+1]; char name[XkbKeyNameLength+1];
XkbDescPtr descr; XkbDescPtr descr;
#endif
int i;
// Clear the LUT // Clear the LUT
for (i = 0; i < 256; ++i) 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 // This functionality requires the Xkb extension
if (!_glfwLibrary.X11.Xkb.available) if (!_glfwLibrary.X11.Xkb.available)
{ {
@ -154,12 +158,13 @@ static void updateKeyCodeLUT(void)
// Update the key code LUT // Update the key code LUT
if ((keyCode >= 0) && (keyCode < 256)) if ((keyCode >= 0) && (keyCode < 256))
{ {
_glfwLibrary.X11.Xkb.keyCodeLUT[keyCode] = keyCodeGLFW; _glfwLibrary.X11.keyCodeLUT[keyCode] = keyCodeGLFW;
} }
} }
// Free the keyboard description // Free the keyboard description
XkbFreeKeyboard(descr, 0, True); XkbFreeKeyboard(descr, 0, True);
#endif /* _GLFW_HAS_XKB */
} }
@ -228,6 +233,7 @@ static GLboolean initDisplay(void)
} }
// Check if Xkb is supported on this display // Check if Xkb is supported on this display
#if defined(_GLFW_HAS_XKB)
_glfwLibrary.X11.Xkb.majorVersion = 1; _glfwLibrary.X11.Xkb.majorVersion = 1;
_glfwLibrary.X11.Xkb.minorVersion = 0; _glfwLibrary.X11.Xkb.minorVersion = 0;
_glfwLibrary.X11.Xkb.available = _glfwLibrary.X11.Xkb.available =
@ -237,6 +243,9 @@ static GLboolean initDisplay(void)
&_glfwLibrary.X11.Xkb.errorBase, &_glfwLibrary.X11.Xkb.errorBase,
&_glfwLibrary.X11.Xkb.majorVersion, &_glfwLibrary.X11.Xkb.majorVersion,
&_glfwLibrary.X11.Xkb.minorVersion); &_glfwLibrary.X11.Xkb.minorVersion);
#else
_glfwLibrary.X11.Xkb.available = GL_FALSE;
#endif /* _GLFW_HAS_XKB */
// Update the key code LUT // Update the key code LUT
// FIXME: We should listen to XkbMapNotify events to track changes to // FIXME: We should listen to XkbMapNotify events to track changes to

View File

@ -335,7 +335,7 @@ static int translateKey(int keycode)
// a positive result if we have the Xkb extension. // a positive result if we have the Xkb extension.
if ((keycode >= 0) && (keycode < 256)) if ((keycode >= 0) && (keycode < 256))
{ {
int result = _glfwLibrary.X11.Xkb.keyCodeLUT[keycode]; int result = _glfwLibrary.X11.keyCodeLUT[keycode];
if (result >= 0) if (result >= 0)
{ {
return result; return result;