From 2b6dde2ac5dfaa23af0ce7b17d395db4f886bfd3 Mon Sep 17 00:00:00 2001 From: Benoit de Chezelles Date: Wed, 16 Oct 2019 01:15:48 +0200 Subject: [PATCH] =?UTF-8?q?Wish:=20rename=20scancode=20=E2=86=92=20native?= =?UTF-8?q?=5Fkey=20in=20glfw=20codebase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- glfw/glfw3.h | 12 ++++++------ glfw/input.c | 6 +++--- glfw/internal.h | 3 ++- glfw/x11_window.c | 8 ++++---- glfw/xkb_glfw.c | 13 +++++++------ 5 files changed, 22 insertions(+), 20 deletions(-) diff --git a/glfw/glfw3.h b/glfw/glfw3.h index be509da1d..b6ffb112b 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -4114,9 +4114,9 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value); * __Do not use this function__ for [text input](@ref input_char). You will * break text input for many languages even if it happens to work for yours. * - * If the key is `GLFW_KEY_UNKNOWN`, the scancode is used to identify the key, - * otherwise the scancode is ignored. If you specify a non-printable key, or - * `GLFW_KEY_UNKNOWN` and a scancode that maps to a non-printable key, this + * If the key is `GLFW_KEY_UNKNOWN`, the keycode is used to identify the key, + * otherwise the keycode is ignored. If you specify a non-printable key, or + * `GLFW_KEY_UNKNOWN` and a keycode that maps to a non-printable key, this * function returns `NULL` but does not emit an error. * * This behavior allows you to always pass in the arguments in the @@ -4215,7 +4215,7 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value); * language and should be localized along with other user interface text. * * @param[in] key The key to query, or `GLFW_KEY_UNKNOWN`. - * @param[in] scancode The scancode of the key to query. + * @param[in] native_key The native key identifier of the key to query. * @return The UTF-8 encoded, layout-specific name of the key, or `NULL`. * * @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref @@ -4235,7 +4235,7 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* window, int mode, int value); * * @ingroup input */ -GLFWAPI const char* glfwGetKeyName(int key, int scancode); +GLFWAPI const char* glfwGetKeyName(int key, int native_key); /*! @brief Returns the platform-specific scancode of the specified key. * @@ -4259,7 +4259,7 @@ GLFWAPI const char* glfwGetKeyName(int key, int scancode); * * @ingroup input */ -GLFWAPI int glfwGetKeyScancode(int key); +GLFWAPI int glfwGetKeyScancode(int key); // FIXME: s/Scancode/NativeKey ? (and fix doc above) /*! @brief Returns the last reported state of a keyboard key for the specified * window. diff --git a/glfw/input.c b/glfw/input.c index 0a4e07cc2..eaf9f9aa4 100644 --- a/glfw/input.c +++ b/glfw/input.c @@ -756,7 +756,7 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value) _glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode); } -GLFWAPI const char* glfwGetKeyName(int key, int scancode) +GLFWAPI const char* glfwGetKeyName(int key, int native_key) { _GLFW_REQUIRE_INIT_OR_RETURN(NULL); @@ -769,10 +769,10 @@ GLFWAPI const char* glfwGetKeyName(int key, int scancode) return NULL; } - scancode = _glfwPlatformGetKeyScancode(key); + native_key = _glfwPlatformGetKeyScancode(key); } - return _glfwPlatformGetScancodeName(scancode); + return _glfwPlatformGetScancodeName(native_key); } GLFWAPI int glfwGetKeyScancode(int key) diff --git a/glfw/internal.h b/glfw/internal.h index c64a923cb..eb015cd3a 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -640,7 +640,8 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, GLFWCursorShape shape void _glfwPlatformDestroyCursor(_GLFWcursor* cursor); void _glfwPlatformSetCursor(_GLFWwindow* window, _GLFWcursor* cursor); -const char* _glfwPlatformGetScancodeName(int scancode); +// FIXME: s/Scancode/NativeKey ? +const char* _glfwPlatformGetScancodeName(int native_key); int _glfwPlatformGetKeyScancode(int key); void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor); diff --git a/glfw/x11_window.c b/glfw/x11_window.c index 815296fd8..2ac40de70 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -2586,13 +2586,13 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode) XFlush(_glfw.x11.display); } -const char* _glfwPlatformGetScancodeName(int scancode) +const char* _glfwPlatformGetScancodeName(int native_key) // FIXME: s/Scancode/NativeKey ? { - return glfw_xkb_keysym_name(scancode); + return glfw_xkb_keysym_name(native_key); } -int _glfwPlatformGetKeyScancode(int key) +int _glfwPlatformGetKeyScancode(int key) // FIXME: rename _glfwPlatformGetNativeKeyForKey ? { return glfw_xkb_sym_for_key(key); } @@ -2871,7 +2871,7 @@ GLFWAPI Window glfwGetX11Window(GLFWwindow* handle) return window->x11.handle; } -GLFWAPI int glfwGetXKBScancode(const char* keyName, bool caseSensitive) { +GLFWAPI int glfwGetXKBScancode(const char* keyName, bool caseSensitive) { // FIXME: s/Scancode/Keycode ? return glfw_xkb_keysym_from_name(keyName, caseSensitive); } diff --git a/glfw/xkb_glfw.c b/glfw/xkb_glfw.c index 854131e3e..1a1173b52 100644 --- a/glfw/xkb_glfw.c +++ b/glfw/xkb_glfw.c @@ -437,11 +437,11 @@ glfw_xkb_update_modifiers(_GLFWXKBData *xkb, xkb_mod_mask_t depressed, xkb_mod_m } bool -glfw_xkb_should_repeat(_GLFWXKBData *xkb, xkb_keycode_t scancode) { +glfw_xkb_should_repeat(_GLFWXKBData *xkb, xkb_keycode_t xkb_keycode) { #ifdef _GLFW_WAYLAND - scancode += 8; + xkb_keycode += 8; #endif - return xkb_keymap_key_repeats(xkb->keymap, scancode); + return xkb_keymap_key_repeats(xkb->keymap, xkb_keycode); } @@ -565,11 +565,12 @@ glfw_xkb_key_from_ime(_GLFWIBUSKeyEvent *ev, bool handled_by_ime, bool failed) { } void -glfw_xkb_handle_key_event(_GLFWwindow *window, _GLFWXKBData *xkb, xkb_keycode_t scancode, int action) { +glfw_xkb_handle_key_event(_GLFWwindow *window, _GLFWXKBData *xkb, xkb_keycode_t xkb_keycode, int action) { static char key_text[64] = {0}; const xkb_keysym_t *syms, *clean_syms, *default_syms; + // NOTE: there is no such thing as a `glfw_keycode`, => we could remove the `xkb_` prefix (?) xkb_keysym_t xkb_sym; - xkb_keycode_t code_for_sym = scancode, ibus_keycode = scancode; + xkb_keycode_t code_for_sym = xkb_keycode, ibus_keycode = xkb_keycode; GLFWkeyevent glfw_ev; _glfwInitializeKeyEvent(&glfw_ev, GLFW_KEY_UNKNOWN, 0, GLFW_PRESS, 0); // init with default values #ifdef _GLFW_WAYLAND @@ -577,7 +578,7 @@ glfw_xkb_handle_key_event(_GLFWwindow *window, _GLFWXKBData *xkb, xkb_keycode_t #else ibus_keycode -= 8; #endif - debug("%s scancode: 0x%x ", action == GLFW_RELEASE ? "Release" : "Press", scancode); + debug("%s xkb_keycode: 0x%x ", action == GLFW_RELEASE ? "Release" : "Press", xkb_keycode); XKBStateGroup *sg = &xkb->states; int num_syms = xkb_state_key_get_syms(sg->state, code_for_sym, &syms); int num_clean_syms = xkb_state_key_get_syms(sg->clean_state, code_for_sym, &clean_syms);