diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index b04aef2b..367ab358 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -255,6 +255,7 @@ video tutorials. - Jay Weisskopf - Frank Wille - Richard A. Wilkes + - Andy Williams - Tatsuya Yatagawa - Ryogo Yoshimura - Rácz Zalán diff --git a/README.md b/README.md index ed88f277..092445f6 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,8 @@ information on what to include when reporting a bug. ## Changelog + - Bugfix: `glfwGetKeyName` emitted `GLFW_INVALID_VALUE` for scancodes with no + key token (#1785,#2214) - [Wayland] Bugfix: Terminating the library before showing a window could segfault - [Linux] Bugfix: `regfree´ was called on invalid data (#2464) diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 2d065c35..d7e89cf3 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -1635,14 +1635,15 @@ const char* _glfwPlatformGetScancodeName(int scancode) { @autoreleasepool { - if (scancode < 0 || scancode > 0xff || - _glfw.ns.keycodes[scancode] == GLFW_KEY_UNKNOWN) + if (scancode < 0 || scancode > 0xff) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode %i", scancode); return NULL; } const int key = _glfw.ns.keycodes[scancode]; + if (key == GLFW_KEY_UNKNOWN) + return NULL; UInt32 deadKeyState = 0; UniChar characters[4]; diff --git a/src/win32_window.c b/src/win32_window.c index 3c22ab16..5aecaadd 100644 --- a/src/win32_window.c +++ b/src/win32_window.c @@ -2191,14 +2191,19 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) const char* _glfwPlatformGetScancodeName(int scancode) { - if (scancode < 0 || scancode > (KF_EXTENDED | 0xff) || - _glfw.win32.keycodes[scancode] == GLFW_KEY_UNKNOWN) + int key; + + if (scancode < 0 || scancode > (KF_EXTENDED | 0xff)) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode %i", scancode); return NULL; } - return _glfw.win32.keynames[_glfw.win32.keycodes[scancode]]; + key = _glfw.win32.keycodes[scancode]; + if (key == GLFW_KEY_UNKNOWN) + return NULL; + + return _glfw.win32.keynames[key]; } int _glfwPlatformGetKeyScancode(int key) diff --git a/src/wl_window.c b/src/wl_window.c index a077c15a..4e51e186 100644 --- a/src/wl_window.c +++ b/src/wl_window.c @@ -2575,8 +2575,7 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) const char* _glfwPlatformGetScancodeName(int scancode) { - if (scancode < 0 || scancode > 255 || - _glfw.wl.keycodes[scancode] == GLFW_KEY_UNKNOWN) + if (scancode < 0 || scancode > 255) { _glfwInputError(GLFW_INVALID_VALUE, "Wayland: Invalid scancode %i", @@ -2585,6 +2584,9 @@ const char* _glfwPlatformGetScancodeName(int scancode) } const int key = _glfw.wl.keycodes[scancode]; + if (key == GLFW_KEY_UNKNOWN) + return NULL; + const xkb_keycode_t keycode = scancode + 8; const xkb_layout_index_t layout = xkb_state_key_get_layout(_glfw.wl.xkb.state, keycode); diff --git a/src/x11_window.c b/src/x11_window.c index 9bd29e34..ef02f139 100644 --- a/src/x11_window.c +++ b/src/x11_window.c @@ -2930,14 +2930,16 @@ const char* _glfwPlatformGetScancodeName(int scancode) if (!_glfw.x11.xkb.available) return NULL; - if (scancode < 0 || scancode > 0xff || - _glfw.x11.keycodes[scancode] == GLFW_KEY_UNKNOWN) + if (scancode < 0 || scancode > 0xff) { _glfwInputError(GLFW_INVALID_VALUE, "Invalid scancode %i", scancode); return NULL; } const int key = _glfw.x11.keycodes[scancode]; + if (key == GLFW_KEY_UNKNOWN) + return NULL; + const KeySym keysym = XkbKeycodeToKeysym(_glfw.x11.display, scancode, _glfw.x11.xkb.group, 0); if (keysym == NoSymbol)