Added compile time detection of the XKB X11 extension.
This commit is contained in:
parent
c0cb4c2fe1
commit
a44d566057
@ -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)
|
||||
|
@ -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
|
||||
|
@ -67,8 +67,9 @@
|
||||
#endif
|
||||
|
||||
// The Xkb extension provides improved keyboard support
|
||||
#if defined(_GLFW_HAS_XKB)
|
||||
#include <X11/XKBlib.h>
|
||||
|
||||
#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;
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user