mirror of
https://github.com/glfw/glfw.git
synced 2024-11-26 06:14:35 +00:00
Automatically detect Xkb at run-time.
Uses XGetKeyboardMapping as a fallback. Fixes #282.
This commit is contained in:
parent
e02b278db1
commit
b889aa7841
@ -78,6 +78,7 @@ The following dependencies are needed by the examples and test programs:
|
||||
the error callback
|
||||
- [Win32] Bugfix: Some keys were reported based on the current layout instead
|
||||
of their physical location
|
||||
- [X11] Added run-time support for systems lacking the XKB extension
|
||||
- [X11] Made GLX 1.3 the minimum supported version
|
||||
- [X11] Bugfix: The case of finding no usable CRTCs was not detected
|
||||
- [X11] Bugfix: Detection of broken Nvidia RandR gamma support did not verify
|
||||
|
@ -40,11 +40,15 @@
|
||||
static int translateKey(int keyCode)
|
||||
{
|
||||
int keySym;
|
||||
int keysyms_per_keycode_return;
|
||||
KeySym *keysyms;
|
||||
|
||||
// Valid key code range is [8,255], according to the XLib manual
|
||||
if (keyCode < 8 || keyCode > 255)
|
||||
return GLFW_KEY_UNKNOWN;
|
||||
|
||||
if(_glfw.x11.xkb.available)
|
||||
{
|
||||
// Try secondary keysym, for numeric keypad keys
|
||||
// Note: This way we always force "NumLock = ON", which is intentional
|
||||
// since the returned key code should correspond to a physical
|
||||
@ -73,6 +77,18 @@ static int translateKey(int keyCode)
|
||||
// should not be layout dependent (i.e. US layout and international
|
||||
// layouts should give the same result).
|
||||
keySym = XkbKeycodeToKeysym(_glfw.x11.display, keyCode, 0, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
keysyms =
|
||||
XGetKeyboardMapping(_glfw.x11.display,
|
||||
keyCode,
|
||||
1,
|
||||
&keysyms_per_keycode_return);
|
||||
keySym = keysyms[0];
|
||||
XFree(keysyms);
|
||||
}
|
||||
|
||||
switch (keySym)
|
||||
{
|
||||
case XK_Escape: return GLFW_KEY_ESCAPE;
|
||||
@ -217,7 +233,8 @@ static int translateKey(int keyCode)
|
||||
//
|
||||
static void updateKeyCodeLUT(void)
|
||||
{
|
||||
int i, keyCode, keyCodeGLFW;
|
||||
int keyCode;
|
||||
int keyCodeGLFW, i;
|
||||
char name[XkbKeyNameLength + 1];
|
||||
XkbDescPtr descr;
|
||||
|
||||
@ -225,6 +242,8 @@ static void updateKeyCodeLUT(void)
|
||||
for (keyCode = 0; keyCode < 256; keyCode++)
|
||||
_glfw.x11.keyCodeLUT[keyCode] = GLFW_KEY_UNKNOWN;
|
||||
|
||||
if(_glfw.x11.xkb.available)
|
||||
{
|
||||
// Use XKB to determine physical key locations independently of the current
|
||||
// keyboard layout
|
||||
|
||||
@ -303,6 +322,7 @@ static void updateKeyCodeLUT(void)
|
||||
|
||||
// Free the keyboard description
|
||||
XkbFreeKeyboard(descr, 0, True);
|
||||
}
|
||||
|
||||
// Translate the un-translated key codes using traditional X11 KeySym
|
||||
// lookups
|
||||
@ -496,30 +516,27 @@ static GLboolean initExtensions(void)
|
||||
// Check if Xkb is supported on this display
|
||||
_glfw.x11.xkb.versionMajor = 1;
|
||||
_glfw.x11.xkb.versionMinor = 0;
|
||||
if (!XkbQueryExtension(_glfw.x11.display,
|
||||
_glfw.x11.xkb.available =
|
||||
XkbQueryExtension(_glfw.x11.display,
|
||||
&_glfw.x11.xkb.majorOpcode,
|
||||
&_glfw.x11.xkb.eventBase,
|
||||
&_glfw.x11.xkb.errorBase,
|
||||
&_glfw.x11.xkb.versionMajor,
|
||||
&_glfw.x11.xkb.versionMinor))
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"X11: The keyboard extension is not available");
|
||||
return GL_FALSE;
|
||||
}
|
||||
&_glfw.x11.xkb.versionMinor);
|
||||
|
||||
if(_glfw.x11.xkb.available)
|
||||
{
|
||||
if (!XkbSetDetectableAutoRepeat(_glfw.x11.display, True, &supported))
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"X11: Failed to set detectable key repeat");
|
||||
return GL_FALSE;
|
||||
// X11: Failed to set detectable key repeat
|
||||
_glfw.x11.xkb.available = GL_FALSE;
|
||||
}
|
||||
|
||||
if (!supported)
|
||||
{
|
||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||
"X11: Detectable key repeat is not supported");
|
||||
return GL_FALSE;
|
||||
// X11: Detectable key repeat is not supported
|
||||
_glfw.x11.xkb.available = GL_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
// Update the key code LUT
|
||||
|
@ -175,6 +175,7 @@ typedef struct _GLFWlibraryX11
|
||||
} randr;
|
||||
|
||||
struct {
|
||||
GLboolean available;
|
||||
int majorOpcode;
|
||||
int eventBase;
|
||||
int errorBase;
|
||||
|
Loading…
Reference in New Issue
Block a user