mirror of
https://github.com/glfw/glfw.git
synced 2025-10-03 05:11:01 +00:00
xkb is a compile-time option: a run-time option would also be possible, but the fallback XKeycodeToKeysym is deprecated on many platforms, and is preferably disabled if not necessary
This commit is contained in:
parent
06289110e7
commit
e3a278e2b5
@ -238,12 +238,16 @@ if (_GLFW_X11)
|
|||||||
list(APPEND glfw_LIBRARIES Xxf86vm)
|
list(APPEND glfw_LIBRARIES Xxf86vm)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
option(GLFW_USE_XKB "Use the X keyboard extension" ON)
|
||||||
|
if(GLFW_USE_XKB)
|
||||||
# Check for Xkb (X keyboard extension)
|
# Check for Xkb (X keyboard extension)
|
||||||
if (NOT X11_Xkb_FOUND)
|
if (NOT X11_Xkb_FOUND)
|
||||||
message(FATAL_ERROR "The X keyboard extension headers were not found")
|
message("The X keyboard extension headers were not found")
|
||||||
endif()
|
else()
|
||||||
|
|
||||||
list(APPEND glfw_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH})
|
list(APPEND glfw_INCLUDE_DIR ${X11_Xkb_INCLUDE_PATH})
|
||||||
|
set(_GLFW_USE_XKB 1)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
find_library(RT_LIBRARY rt)
|
find_library(RT_LIBRARY rt)
|
||||||
mark_as_advanced(RT_LIBRARY)
|
mark_as_advanced(RT_LIBRARY)
|
||||||
|
@ -68,6 +68,8 @@
|
|||||||
#cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT
|
#cmakedefine _GLFW_HAS_GLXGETPROCADDRESSEXT
|
||||||
// Define this to 1 if dlopen is available
|
// Define this to 1 if dlopen is available
|
||||||
#cmakedefine _GLFW_HAS_DLOPEN
|
#cmakedefine _GLFW_HAS_DLOPEN
|
||||||
|
// Define this to 1 if Xkb is available
|
||||||
|
#cmakedefine _GLFW_USE_XKB
|
||||||
|
|
||||||
// Define this to 1 if glfwInit should change the current directory
|
// Define this to 1 if glfwInit should change the current directory
|
||||||
#cmakedefine _GLFW_USE_CHDIR
|
#cmakedefine _GLFW_USE_CHDIR
|
||||||
|
@ -44,6 +44,7 @@ static int translateKey(int keyCode)
|
|||||||
if (keyCode < 8 || keyCode > 255)
|
if (keyCode < 8 || keyCode > 255)
|
||||||
return GLFW_KEY_UNKNOWN;
|
return GLFW_KEY_UNKNOWN;
|
||||||
|
|
||||||
|
#if defined(_GLFW_USE_XKB)
|
||||||
// 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
|
||||||
@ -72,6 +73,10 @@ 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
|
||||||
|
keySym = XKeycodeToKeysym(_glfw.x11.display, keyCode, 0);
|
||||||
|
#endif
|
||||||
|
|
||||||
switch (keySym)
|
switch (keySym)
|
||||||
{
|
{
|
||||||
case XK_Escape: return GLFW_KEY_ESCAPE;
|
case XK_Escape: return GLFW_KEY_ESCAPE;
|
||||||
@ -216,7 +221,9 @@ static int translateKey(int keyCode)
|
|||||||
//
|
//
|
||||||
static void updateKeyCodeLUT(void)
|
static void updateKeyCodeLUT(void)
|
||||||
{
|
{
|
||||||
int i, keyCode, keyCodeGLFW;
|
int keyCode, keyCodeGLFW;
|
||||||
|
#if defined(_GLFW_USE_XKB)
|
||||||
|
int i;
|
||||||
char name[XkbKeyNameLength + 1];
|
char name[XkbKeyNameLength + 1];
|
||||||
XkbDescPtr descr;
|
XkbDescPtr descr;
|
||||||
|
|
||||||
@ -302,6 +309,7 @@ static void updateKeyCodeLUT(void)
|
|||||||
|
|
||||||
// Free the keyboard description
|
// Free the keyboard description
|
||||||
XkbFreeKeyboard(descr, 0, True);
|
XkbFreeKeyboard(descr, 0, True);
|
||||||
|
#endif
|
||||||
|
|
||||||
// Translate the un-translated key codes using traditional X11 KeySym
|
// Translate the un-translated key codes using traditional X11 KeySym
|
||||||
// lookups
|
// lookups
|
||||||
@ -481,6 +489,7 @@ static GLboolean initExtensions(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if Xkb is supported on this display
|
// Check if Xkb is supported on this display
|
||||||
|
#if defined(_GLFW_USE_XKB)
|
||||||
_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,
|
if (!XkbQueryExtension(_glfw.x11.display,
|
||||||
@ -508,6 +517,7 @@ static GLboolean initExtensions(void)
|
|||||||
"X11: Detectable key repeat is not supported");
|
"X11: Detectable key repeat is not supported");
|
||||||
return GL_FALSE;
|
return GL_FALSE;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
// Update the key code LUT
|
// Update the key code LUT
|
||||||
// FIXME: We should listen to XkbMapNotify events to track changes to
|
// FIXME: We should listen to XkbMapNotify events to track changes to
|
||||||
|
@ -45,7 +45,9 @@
|
|||||||
#include <X11/extensions/XInput2.h>
|
#include <X11/extensions/XInput2.h>
|
||||||
|
|
||||||
// The Xkb extension provides improved keyboard support
|
// The Xkb extension provides improved keyboard support
|
||||||
|
#if defined(_GLFW_USE_XKB)
|
||||||
#include <X11/XKBlib.h>
|
#include <X11/XKBlib.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(_GLFW_GLX)
|
#if defined(_GLFW_GLX)
|
||||||
#define _GLFW_X11_CONTEXT_VISUAL window->glx.visual
|
#define _GLFW_X11_CONTEXT_VISUAL window->glx.visual
|
||||||
|
Loading…
Reference in New Issue
Block a user