mirror of
https://github.com/glfw/glfw.git
synced 2024-11-22 10:05:10 +00:00
Cleanup
Thanks to glfwGetKeyScancode we can now pass only a scancode to the platform layer for glfwGetKeyName.
This commit is contained in:
parent
d3247a8c83
commit
82284b86eb
@ -1560,14 +1560,8 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
|||||||
updateCursorImage(window);
|
updateCursorImage(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* _glfwPlatformGetKeyName(int key, int scancode)
|
const char* _glfwPlatformGetScancodeName(int scancode)
|
||||||
{
|
{
|
||||||
if (key != GLFW_KEY_UNKNOWN)
|
|
||||||
scancode = _glfw.ns.scancodes[key];
|
|
||||||
|
|
||||||
if (!_glfwIsPrintable(_glfw.ns.keycodes[scancode]))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
UInt32 deadKeyState = 0;
|
UInt32 deadKeyState = 0;
|
||||||
UniChar characters[8];
|
UniChar characters[8];
|
||||||
UniCharCount characterCount = 0;
|
UniCharCount characterCount = 0;
|
||||||
|
22
src/input.c
22
src/input.c
@ -289,13 +289,6 @@ void _glfwInputJoystickHat(_GLFWjoystick* js, int hat, char value)
|
|||||||
////// GLFW internal API //////
|
////// GLFW internal API //////
|
||||||
//////////////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
GLFWbool _glfwIsPrintable(int key)
|
|
||||||
{
|
|
||||||
return (key >= GLFW_KEY_APOSTROPHE && key <= GLFW_KEY_WORLD_2) ||
|
|
||||||
(key >= GLFW_KEY_KP_0 && key <= GLFW_KEY_KP_ADD) ||
|
|
||||||
key == GLFW_KEY_KP_EQUAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
_GLFWjoystick* _glfwAllocJoystick(const char* name,
|
_GLFWjoystick* _glfwAllocJoystick(const char* name,
|
||||||
const char* guid,
|
const char* guid,
|
||||||
int axisCount,
|
int axisCount,
|
||||||
@ -450,7 +443,20 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
|
|||||||
GLFWAPI const char* glfwGetKeyName(int key, int scancode)
|
GLFWAPI const char* glfwGetKeyName(int key, int scancode)
|
||||||
{
|
{
|
||||||
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
_GLFW_REQUIRE_INIT_OR_RETURN(NULL);
|
||||||
return _glfwPlatformGetKeyName(key, scancode);
|
|
||||||
|
if (key != GLFW_KEY_UNKNOWN)
|
||||||
|
{
|
||||||
|
if (key != GLFW_KEY_KP_EQUAL &&
|
||||||
|
(key < GLFW_KEY_KP_0 || key > GLFW_KEY_KP_ADD) &&
|
||||||
|
(key < GLFW_KEY_APOSTROPHE || key > GLFW_KEY_WORLD_2))
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
scancode = _glfwPlatformGetKeyScancode(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
return _glfwPlatformGetScancodeName(scancode);
|
||||||
}
|
}
|
||||||
|
|
||||||
GLFWAPI int glfwGetKeyScancode(int key)
|
GLFWAPI int glfwGetKeyScancode(int key)
|
||||||
|
@ -630,7 +630,7 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, int shape);
|
|||||||
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
|
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
|
||||||
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor);
|
void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor);
|
||||||
|
|
||||||
const char* _glfwPlatformGetKeyName(int key, int scancode);
|
const char* _glfwPlatformGetScancodeName(int scancode);
|
||||||
int _glfwPlatformGetKeyScancode(int key);
|
int _glfwPlatformGetKeyScancode(int key);
|
||||||
|
|
||||||
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos);
|
void _glfwPlatformGetMonitorPos(_GLFWmonitor* monitor, int* xpos, int* ypos);
|
||||||
@ -990,10 +990,6 @@ _GLFWjoystick* _glfwAllocJoystick(const char* name,
|
|||||||
*/
|
*/
|
||||||
void _glfwFreeJoystick(_GLFWjoystick* js);
|
void _glfwFreeJoystick(_GLFWjoystick* js);
|
||||||
|
|
||||||
/*! @ingroup utility
|
|
||||||
*/
|
|
||||||
GLFWbool _glfwIsPrintable(int key);
|
|
||||||
|
|
||||||
/*! @ingroup utility
|
/*! @ingroup utility
|
||||||
*/
|
*/
|
||||||
GLFWbool _glfwInitVulkan(int mode);
|
GLFWbool _glfwInitVulkan(int mode);
|
||||||
|
@ -830,7 +830,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* _glfwPlatformGetKeyName(int key, int scancode)
|
const char* _glfwPlatformGetScancodeName(int scancode)
|
||||||
{
|
{
|
||||||
_glfwInputError(GLFW_PLATFORM_ERROR,
|
_glfwInputError(GLFW_PLATFORM_ERROR,
|
||||||
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
"Mir: Unsupported function %s", __PRETTY_FUNCTION__);
|
||||||
|
@ -261,7 +261,7 @@ const char* _glfwPlatformGetClipboardString(_GLFWwindow* window)
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* _glfwPlatformGetKeyName(int key, int scancode)
|
const char* _glfwPlatformGetScancodeName(int scancode)
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
@ -1609,16 +1609,10 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
|||||||
updateCursorImage(window);
|
updateCursorImage(window);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* _glfwPlatformGetKeyName(int key, int scancode)
|
const char* _glfwPlatformGetScancodeName(int scancode)
|
||||||
{
|
{
|
||||||
WCHAR name[16];
|
WCHAR name[16];
|
||||||
|
|
||||||
if (key != GLFW_KEY_UNKNOWN)
|
|
||||||
scancode = _glfw.win32.scancodes[key];
|
|
||||||
|
|
||||||
if (!_glfwIsPrintable(_glfw.win32.keycodes[scancode]))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (!GetKeyNameTextW(scancode << 16, name, sizeof(name) / sizeof(WCHAR)))
|
if (!GetKeyNameTextW(scancode << 16, name, sizeof(name) / sizeof(WCHAR)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -721,7 +721,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
|||||||
_glfwPlatformSetCursor(window, window->wl.currentCursor);
|
_glfwPlatformSetCursor(window, window->wl.currentCursor);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* _glfwPlatformGetKeyName(int key, int scancode)
|
const char* _glfwPlatformGetScancodeName(int scancode)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
return NULL;
|
return NULL;
|
||||||
|
@ -2474,17 +2474,11 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
|
|||||||
XFlush(_glfw.x11.display);
|
XFlush(_glfw.x11.display);
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* _glfwPlatformGetKeyName(int key, int scancode)
|
const char* _glfwPlatformGetScancodeName(int scancode)
|
||||||
{
|
{
|
||||||
if (!_glfw.x11.xkb.available)
|
if (!_glfw.x11.xkb.available)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (key != GLFW_KEY_UNKNOWN)
|
|
||||||
scancode = _glfw.x11.scancodes[key];
|
|
||||||
|
|
||||||
if (!_glfwIsPrintable(_glfw.x11.keycodes[scancode]))
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
const KeySym keysym = XkbKeycodeToKeysym(_glfw.x11.display, scancode, 0, 0);
|
const KeySym keysym = XkbKeycodeToKeysym(_glfw.x11.display, scancode, 0, 0);
|
||||||
if (keysym == NoSymbol)
|
if (keysym == NoSymbol)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user