mirror of
https://github.com/glfw/glfw.git
synced 2025-10-02 21:00:57 +00:00
Merge d2a2d1ff57
into e02b278db1
This commit is contained in:
commit
f3f8d9ddc6
@ -261,10 +261,11 @@ if (_GLFW_X11)
|
||||
|
||||
# Check for Xkb (X keyboard extension)
|
||||
if (NOT X11_Xkb_FOUND)
|
||||
message(FATAL_ERROR "The X keyboard extension headers were not found")
|
||||
endif()
|
||||
|
||||
message("The X keyboard extension headers were not found")
|
||||
else()
|
||||
list(APPEND glfw_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH})
|
||||
set(_GLFW_HAS_XKB 1)
|
||||
endif()
|
||||
|
||||
find_library(RT_LIBRARY rt)
|
||||
mark_as_advanced(RT_LIBRARY)
|
||||
|
@ -70,6 +70,8 @@
|
||||
#cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT
|
||||
// Define this to 1 if dlopen is available
|
||||
#cmakedefine _GLFW_HAS_DLOPEN
|
||||
// Define this to 1 if Xkb is available
|
||||
#cmakedefine _GLFW_HAS_XKB
|
||||
|
||||
// Define this to 1 if glfwInit should change the current directory
|
||||
#cmakedefine _GLFW_USE_CHDIR
|
||||
|
@ -40,11 +40,16 @@
|
||||
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 defined(_GLFW_HAS_XKB)
|
||||
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 +78,19 @@ 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
|
||||
#endif
|
||||
{
|
||||
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,14 +235,20 @@ static int translateKey(int keyCode)
|
||||
//
|
||||
static void updateKeyCodeLUT(void)
|
||||
{
|
||||
int i, keyCode, keyCodeGLFW;
|
||||
int keyCode;
|
||||
#if defined(_GLFW_HAS_XKB)
|
||||
int keyCodeGLFW, i;
|
||||
char name[XkbKeyNameLength + 1];
|
||||
XkbDescPtr descr;
|
||||
#endif
|
||||
|
||||
// Clear the LUT
|
||||
for (keyCode = 0; keyCode < 256; keyCode++)
|
||||
_glfw.x11.keyCodeLUT[keyCode] = GLFW_KEY_UNKNOWN;
|
||||
|
||||
#if defined(_GLFW_HAS_XKB)
|
||||
if(_glfw.x11.xkb.available)
|
||||
{
|
||||
// Use XKB to determine physical key locations independently of the current
|
||||
// keyboard layout
|
||||
|
||||
@ -303,6 +327,8 @@ static void updateKeyCodeLUT(void)
|
||||
|
||||
// Free the keyboard description
|
||||
XkbFreeKeyboard(descr, 0, True);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Translate the un-translated key codes using traditional X11 KeySym
|
||||
// lookups
|
||||
@ -431,7 +457,9 @@ static void detectEWMH(void)
|
||||
//
|
||||
static GLboolean initExtensions(void)
|
||||
{
|
||||
#if defined(_GLFW_HAS_XKB) // suppress unused variable warning
|
||||
Bool supported;
|
||||
#endif
|
||||
|
||||
// Find or create window manager atoms
|
||||
_glfw.x11.WM_PROTOCOLS = XInternAtom(_glfw.x11.display,
|
||||
@ -494,33 +522,32 @@ static GLboolean initExtensions(void)
|
||||
}
|
||||
|
||||
// Check if Xkb is supported on this display
|
||||
#if defined(_GLFW_HAS_XKB)
|
||||
_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;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// Update the key code LUT
|
||||
// FIXME: We should listen to XkbMapNotify events to track changes to
|
||||
|
@ -46,7 +46,9 @@
|
||||
#include <X11/extensions/XInput2.h>
|
||||
|
||||
// The Xkb extension provides improved keyboard support
|
||||
#if defined(_GLFW_HAS_XKB)
|
||||
#include <X11/XKBlib.h>
|
||||
#endif
|
||||
|
||||
#include "posix_tls.h"
|
||||
|
||||
@ -175,6 +177,7 @@ typedef struct _GLFWlibraryX11
|
||||
} randr;
|
||||
|
||||
struct {
|
||||
GLboolean available;
|
||||
int majorOpcode;
|
||||
int eventBase;
|
||||
int errorBase;
|
||||
|
Loading…
Reference in New Issue
Block a user