|
|
@ -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
|
|
|
|