diff --git a/docs/changelog.rst b/docs/changelog.rst index cfcdf660b..6ef6c7100 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -178,7 +178,7 @@ Detailed list of changes - Command palette: Improve searching to use word level matching (:pull:`9727`) -- GLFW: Add ``glfwGetKeyboardRepeatDelay()`` to the GLFW API to query the current keyboard key-repeat delay from the OS, implemented for X11, Wayland and Cocoa backends +- GLFW: Add ``glfwGetKeyboardRepeatDelay()`` to the GLFW API to query the current keyboard key-repeat initial delay and repeat interval from the OS, implemented for X11, Wayland and Cocoa backends 0.46.2 [2026-03-21] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index ae7e0b2bd..4a16bb45e 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -2782,9 +2782,10 @@ monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window UNUSED) return s_double_to_monotonic_t([NSEvent doubleClickInterval]); } -monotonic_t _glfwPlatformGetKeyboardRepeatDelay(void) +void _glfwPlatformGetKeyboardRepeatDelay(monotonic_t *delay, monotonic_t *interval) { - return s_double_to_monotonic_t([NSEvent keyRepeatDelay]); + if (delay) *delay = s_double_to_monotonic_t([NSEvent keyRepeatDelay]); + if (interval) *interval = s_double_to_monotonic_t([NSEvent keyRepeatInterval]); } void _glfwPlatformIconifyWindow(_GLFWwindow* window) diff --git a/glfw/glfw3.h b/glfw/glfw3.h index e3fc7122a..002e58b17 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -4370,7 +4370,7 @@ GLFWAPI void glfwPostEmptyEvent(void); GLFWAPI bool glfwGetIgnoreOSKeyboardProcessing(void); GLFWAPI void glfwSetIgnoreOSKeyboardProcessing(bool enabled); GLFWAPI bool glfwGrabKeyboard(int grab); -GLFWAPI monotonic_t glfwGetKeyboardRepeatDelay(void); +GLFWAPI void glfwGetKeyboardRepeatDelay(monotonic_t *delay, monotonic_t *interval); /*! @brief Returns the value of an input option for the specified window. * diff --git a/glfw/input.c b/glfw/input.c index 572b1fb34..9ded16610 100644 --- a/glfw/input.c +++ b/glfw/input.c @@ -720,9 +720,11 @@ GLFWAPI bool glfwGrabKeyboard(int grab) { return _glfw.keyboard_grabbed; } -GLFWAPI monotonic_t glfwGetKeyboardRepeatDelay(void) { - _GLFW_REQUIRE_INIT_OR_RETURN(ms_to_monotonic_t(500ll)); - return _glfwPlatformGetKeyboardRepeatDelay(); +GLFWAPI void glfwGetKeyboardRepeatDelay(monotonic_t *delay, monotonic_t *interval) { + _GLFW_REQUIRE_INIT(); + if (delay) *delay = ms_to_monotonic_t(500ll); + if (interval) *interval = ms_to_monotonic_t(30ll); + _glfwPlatformGetKeyboardRepeatDelay(delay, interval); } GLFWAPI int glfwGetInputMode(GLFWwindow* handle, int mode) diff --git a/glfw/internal.h b/glfw/internal.h index fa3ff57f2..3821b403f 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -745,7 +745,7 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, float* xscale, float* yscale); monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window); -monotonic_t _glfwPlatformGetKeyboardRepeatDelay(void); +void _glfwPlatformGetKeyboardRepeatDelay(monotonic_t *delay, monotonic_t *interval); void _glfwPlatformIconifyWindow(_GLFWwindow* window); void _glfwPlatformRestoreWindow(_GLFWwindow* window); void _glfwPlatformMaximizeWindow(_GLFWwindow* window); diff --git a/glfw/null_window.c b/glfw/null_window.c index 191917124..1c3c90b00 100644 --- a/glfw/null_window.c +++ b/glfw/null_window.c @@ -311,9 +311,10 @@ monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window UNUSED) return ms_to_monotonic_t(500ll); } -monotonic_t _glfwPlatformGetKeyboardRepeatDelay(void) +void _glfwPlatformGetKeyboardRepeatDelay(monotonic_t *delay, monotonic_t *interval) { - return ms_to_monotonic_t(500ll); + if (delay) *delay = ms_to_monotonic_t(500ll); + if (interval) *interval = ms_to_monotonic_t(30ll); } void _glfwPlatformIconifyWindow(_GLFWwindow* window) diff --git a/glfw/wl_window.c b/glfw/wl_window.c index 9c7deb9eb..c176915e9 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -1769,9 +1769,11 @@ monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window UNUSED) return ms_to_monotonic_t(500ll); } -monotonic_t _glfwPlatformGetKeyboardRepeatDelay(void) +void _glfwPlatformGetKeyboardRepeatDelay(monotonic_t *delay, monotonic_t *interval) { - return _glfw.wl.keyboardRepeatDelay; + if (delay) *delay = _glfw.wl.keyboardRepeatDelay; + if (interval && _glfw.wl.keyboardRepeatRate > 0) + *interval = s_to_monotonic_t(1ll) / (monotonic_t)_glfw.wl.keyboardRepeatRate; } void _glfwPlatformIconifyWindow(_GLFWwindow* window) diff --git a/glfw/x11_window.c b/glfw/x11_window.c index f7223e1b6..6be8e14ca 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -2876,16 +2876,16 @@ monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window UNUSED) return ms_to_monotonic_t(500ll); } -monotonic_t _glfwPlatformGetKeyboardRepeatDelay(void) +void _glfwPlatformGetKeyboardRepeatDelay(monotonic_t *delay, monotonic_t *interval) { - monotonic_t delay = ms_to_monotonic_t(500ll); XkbDescPtr xkb = XkbAllocKeyboard(); if (xkb) { - if (XkbGetControls(_glfw.x11.display, XkbRepeatKeysMask, xkb) == Success) - delay = ms_to_monotonic_t(xkb->ctrls->repeat_delay); + if (XkbGetControls(_glfw.x11.display, XkbRepeatKeysMask, xkb) == Success) { + if (delay) *delay = ms_to_monotonic_t(xkb->ctrls->repeat_delay); + if (interval) *interval = ms_to_monotonic_t(xkb->ctrls->repeat_interval); + } XkbFreeKeyboard(xkb, 0, True); } - return delay; } void _glfwPlatformIconifyWindow(_GLFWwindow* window) diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index b95adce28..38d7f433d 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -2206,7 +2206,7 @@ typedef bool (*glfwGrabKeyboard_func)(int); GFW_EXTERN glfwGrabKeyboard_func glfwGrabKeyboard_impl; #define glfwGrabKeyboard glfwGrabKeyboard_impl -typedef monotonic_t (*glfwGetKeyboardRepeatDelay_func)(void); +typedef void (*glfwGetKeyboardRepeatDelay_func)(monotonic_t*, monotonic_t*); GFW_EXTERN glfwGetKeyboardRepeatDelay_func glfwGetKeyboardRepeatDelay_impl; #define glfwGetKeyboardRepeatDelay glfwGetKeyboardRepeatDelay_impl