From 998ee22ecb152bfca58da7bc3ea632c3cf35bf76 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 23 Mar 2026 11:46:35 +0000 Subject: [PATCH] Add glfwGetKeyboardRepeatDelay() to the GLFW API for X11, Wayland and Cocoa Co-authored-by: kovidgoyal <1308621+kovidgoyal@users.noreply.github.com> Agent-Logs-Url: https://github.com/kovidgoyal/kitty/sessions/4765810b-ecf5-4348-ae3a-ff0ff481aaae --- docs/changelog.rst | 2 ++ glfw/cocoa_window.m | 5 +++++ glfw/glfw3.h | 1 + glfw/input.c | 5 +++++ glfw/internal.h | 1 + glfw/null_window.c | 5 +++++ glfw/wl_window.c | 5 +++++ glfw/x11_window.c | 12 ++++++++++++ kitty/glfw-wrapper.c | 3 +++ kitty/glfw-wrapper.h | 4 ++++ 10 files changed, 43 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index bb7ef9f61..cfcdf660b 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -178,6 +178,8 @@ 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 + 0.46.2 [2026-03-21] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/glfw/cocoa_window.m b/glfw/cocoa_window.m index f1342b457..ae7e0b2bd 100644 --- a/glfw/cocoa_window.m +++ b/glfw/cocoa_window.m @@ -2782,6 +2782,11 @@ monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window UNUSED) return s_double_to_monotonic_t([NSEvent doubleClickInterval]); } +monotonic_t _glfwPlatformGetKeyboardRepeatDelay(void) +{ + return s_double_to_monotonic_t([NSEvent keyRepeatDelay]); +} + void _glfwPlatformIconifyWindow(_GLFWwindow* window) { [window->ns.object miniaturize:nil]; diff --git a/glfw/glfw3.h b/glfw/glfw3.h index 497385dcd..e3fc7122a 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -4370,6 +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); /*! @brief Returns the value of an input option for the specified window. * diff --git a/glfw/input.c b/glfw/input.c index d35f11ba6..572b1fb34 100644 --- a/glfw/input.c +++ b/glfw/input.c @@ -720,6 +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 int glfwGetInputMode(GLFWwindow* handle, int mode) { _GLFWwindow* window = (_GLFWwindow*) handle; diff --git a/glfw/internal.h b/glfw/internal.h index 71a647def..fa3ff57f2 100644 --- a/glfw/internal.h +++ b/glfw/internal.h @@ -745,6 +745,7 @@ void _glfwPlatformGetWindowFrameSize(_GLFWwindow* window, void _glfwPlatformGetWindowContentScale(_GLFWwindow* window, float* xscale, float* yscale); monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window); +monotonic_t _glfwPlatformGetKeyboardRepeatDelay(void); 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 b46279c9d..191917124 100644 --- a/glfw/null_window.c +++ b/glfw/null_window.c @@ -311,6 +311,11 @@ monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window UNUSED) return ms_to_monotonic_t(500ll); } +monotonic_t _glfwPlatformGetKeyboardRepeatDelay(void) +{ + return ms_to_monotonic_t(500ll); +} + void _glfwPlatformIconifyWindow(_GLFWwindow* window) { if (_glfw.null.focusedWindow == window) diff --git a/glfw/wl_window.c b/glfw/wl_window.c index ff3b8b69c..9c7deb9eb 100644 --- a/glfw/wl_window.c +++ b/glfw/wl_window.c @@ -1769,6 +1769,11 @@ monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window UNUSED) return ms_to_monotonic_t(500ll); } +monotonic_t _glfwPlatformGetKeyboardRepeatDelay(void) +{ + return _glfw.wl.keyboardRepeatDelay; +} + void _glfwPlatformIconifyWindow(_GLFWwindow* window) { if (window->wl.xdg.toplevel) { diff --git a/glfw/x11_window.c b/glfw/x11_window.c index 05c8ea094..f7223e1b6 100644 --- a/glfw/x11_window.c +++ b/glfw/x11_window.c @@ -2876,6 +2876,18 @@ monotonic_t _glfwPlatformGetDoubleClickInterval(_GLFWwindow* window UNUSED) return ms_to_monotonic_t(500ll); } +monotonic_t _glfwPlatformGetKeyboardRepeatDelay(void) +{ + 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); + XkbFreeKeyboard(xkb, 0, True); + } + return delay; +} + void _glfwPlatformIconifyWindow(_GLFWwindow* window) { XIconifyWindow(_glfw.x11.display, window->x11.handle, _glfw.x11.screen); diff --git a/kitty/glfw-wrapper.c b/kitty/glfw-wrapper.c index da2d85780..37a35891a 100644 --- a/kitty/glfw-wrapper.c +++ b/kitty/glfw-wrapper.c @@ -296,6 +296,9 @@ load_glfw(const char* path) { *(void **) (&glfwGrabKeyboard_impl) = dlsym(handle, "glfwGrabKeyboard"); if (glfwGrabKeyboard_impl == NULL) fail("Failed to load glfw function glfwGrabKeyboard with error: %s", dlerror()); + *(void **) (&glfwGetKeyboardRepeatDelay_impl) = dlsym(handle, "glfwGetKeyboardRepeatDelay"); + if (glfwGetKeyboardRepeatDelay_impl == NULL) fail("Failed to load glfw function glfwGetKeyboardRepeatDelay with error: %s", dlerror()); + *(void **) (&glfwGetInputMode_impl) = dlsym(handle, "glfwGetInputMode"); if (glfwGetInputMode_impl == NULL) fail("Failed to load glfw function glfwGetInputMode with error: %s", dlerror()); diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index 9ca42a9a6..b95adce28 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -2206,6 +2206,10 @@ typedef bool (*glfwGrabKeyboard_func)(int); GFW_EXTERN glfwGrabKeyboard_func glfwGrabKeyboard_impl; #define glfwGrabKeyboard glfwGrabKeyboard_impl +typedef monotonic_t (*glfwGetKeyboardRepeatDelay_func)(void); +GFW_EXTERN glfwGetKeyboardRepeatDelay_func glfwGetKeyboardRepeatDelay_impl; +#define glfwGetKeyboardRepeatDelay glfwGetKeyboardRepeatDelay_impl + typedef int (*glfwGetInputMode_func)(GLFWwindow*, int); GFW_EXTERN glfwGetInputMode_func glfwGetInputMode_impl; #define glfwGetInputMode glfwGetInputMode_impl