Wish: rename scancode → native_key in glfw codebase

This commit is contained in:
Benoit de Chezelles 2019-10-16 01:15:48 +02:00
parent 0c254fa7c7
commit 2b6dde2ac5
5 changed files with 22 additions and 20 deletions

12
glfw/glfw3.h vendored
View File

@ -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 * __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. * 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, * If the key is `GLFW_KEY_UNKNOWN`, the keycode is used to identify the key,
* otherwise the scancode is ignored. If you specify a non-printable key, or * otherwise the keycode is ignored. If you specify a non-printable key, or
* `GLFW_KEY_UNKNOWN` and a scancode that maps to a non-printable key, this * `GLFW_KEY_UNKNOWN` and a keycode that maps to a non-printable key, this
* function returns `NULL` but does not emit an error. * function returns `NULL` but does not emit an error.
* *
* This behavior allows you to always pass in the arguments in the * 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. * language and should be localized along with other user interface text.
* *
* @param[in] key The key to query, or `GLFW_KEY_UNKNOWN`. * @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`. * @return The UTF-8 encoded, layout-specific name of the key, or `NULL`.
* *
* @errors Possible errors include @ref GLFW_NOT_INITIALIZED and @ref * @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 * @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. /*! @brief Returns the platform-specific scancode of the specified key.
* *
@ -4259,7 +4259,7 @@ GLFWAPI const char* glfwGetKeyName(int key, int scancode);
* *
* @ingroup input * @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 /*! @brief Returns the last reported state of a keyboard key for the specified
* window. * window.

6
glfw/input.c vendored
View File

@ -756,7 +756,7 @@ GLFWAPI void glfwSetInputMode(GLFWwindow* handle, int mode, int value)
_glfwInputError(GLFW_INVALID_ENUM, "Invalid input mode 0x%08X", mode); _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); _GLFW_REQUIRE_INIT_OR_RETURN(NULL);
@ -769,10 +769,10 @@ GLFWAPI const char* glfwGetKeyName(int key, int scancode)
return NULL; return NULL;
} }
scancode = _glfwPlatformGetKeyScancode(key); native_key = _glfwPlatformGetKeyScancode(key);
} }
return _glfwPlatformGetScancodeName(scancode); return _glfwPlatformGetScancodeName(native_key);
} }
GLFWAPI int glfwGetKeyScancode(int key) GLFWAPI int glfwGetKeyScancode(int key)

3
glfw/internal.h vendored
View File

@ -640,7 +640,8 @@ int _glfwPlatformCreateStandardCursor(_GLFWcursor* cursor, GLFWCursorShape shape
void _glfwPlatformDestroyCursor(_GLFWcursor* cursor); void _glfwPlatformDestroyCursor(_GLFWcursor* cursor);
void _glfwPlatformSetCursor(_GLFWwindow* window, _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); int _glfwPlatformGetKeyScancode(int key);
void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor); void _glfwPlatformFreeMonitor(_GLFWmonitor* monitor);

8
glfw/x11_window.c vendored
View File

@ -2586,13 +2586,13 @@ void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)
XFlush(_glfw.x11.display); 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); return glfw_xkb_sym_for_key(key);
} }
@ -2871,7 +2871,7 @@ GLFWAPI Window glfwGetX11Window(GLFWwindow* handle)
return window->x11.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); return glfw_xkb_keysym_from_name(keyName, caseSensitive);
} }

13
glfw/xkb_glfw.c vendored
View File

@ -437,11 +437,11 @@ glfw_xkb_update_modifiers(_GLFWXKBData *xkb, xkb_mod_mask_t depressed, xkb_mod_m
} }
bool 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 #ifdef _GLFW_WAYLAND
scancode += 8; xkb_keycode += 8;
#endif #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 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}; static char key_text[64] = {0};
const xkb_keysym_t *syms, *clean_syms, *default_syms; 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_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; GLFWkeyevent glfw_ev;
_glfwInitializeKeyEvent(&glfw_ev, GLFW_KEY_UNKNOWN, 0, GLFW_PRESS, 0); // init with default values _glfwInitializeKeyEvent(&glfw_ev, GLFW_KEY_UNKNOWN, 0, GLFW_PRESS, 0); // init with default values
#ifdef _GLFW_WAYLAND #ifdef _GLFW_WAYLAND
@ -577,7 +578,7 @@ glfw_xkb_handle_key_event(_GLFWwindow *window, _GLFWXKBData *xkb, xkb_keycode_t
#else #else
ibus_keycode -= 8; ibus_keycode -= 8;
#endif #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; XKBStateGroup *sg = &xkb->states;
int num_syms = xkb_state_key_get_syms(sg->state, code_for_sym, &syms); 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); int num_clean_syms = xkb_state_key_get_syms(sg->clean_state, code_for_sym, &clean_syms);