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