From 6c31256aa14ce8b432bfb7364e8aa2de5ad06468 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 7 Mar 2024 08:29:10 +0530 Subject: [PATCH] Keyboard protocol: Do not deliver a fake key release events on OS window focus out for engaged modifiers Fixes #7196 --- docs/changelog.rst | 2 ++ glfw/glfw3.h | 3 +++ glfw/window.c | 2 +- kitty/glfw-wrapper.h | 3 +++ kitty/glfw.c | 2 +- 5 files changed, 10 insertions(+), 2 deletions(-) diff --git a/docs/changelog.rst b/docs/changelog.rst index 5b9a63eab..ac10c4a43 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -86,6 +86,8 @@ Detailed list of changes - Remote control: Fix ``--match`` argument not working for @ls, @send-key, @set-background-image (:iss:`7192`) +- Keyboard protocol: Do not deliver a fake key release events on OS window focus out for engaged modifiers (:iss:`7196`) + 0.32.2 [2024-02-12] ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/glfw/glfw3.h b/glfw/glfw3.h index 28b2fcb0e..a2167e243 100644 --- a/glfw/glfw3.h +++ b/glfw/glfw3.h @@ -1288,6 +1288,9 @@ typedef struct GLFWkeyevent // For internal use only. On Linux it is the actual keycode reported by the windowing system, in contrast // to native_key which can be the result of a compose operation. On macOS it is the same as native_key. uint32_t native_key_id; + + // True if this is a synthesized event on focus change + bool fake_event_on_focus_change; } GLFWkeyevent; /*! @brief The function pointer type for error callbacks. diff --git a/glfw/window.c b/glfw/window.c index 6899d5751..0e55b0577 100644 --- a/glfw/window.c +++ b/glfw/window.c @@ -57,7 +57,7 @@ void _glfwInputWindowFocus(_GLFWwindow* window, bool focused) if (window->activated_keys[i].key > 0 && window->activated_keys[i].action == GLFW_PRESS) { const int native_key = _glfwPlatformGetNativeKeyForKey(window->activated_keys[i].key); - GLFWkeyevent ev = {.key = window->activated_keys[i].key, .native_key = native_key, .action = GLFW_RELEASE}; + GLFWkeyevent ev = {.key = window->activated_keys[i].key, .native_key = native_key, .action = GLFW_RELEASE, .fake_event_on_focus_change = true}; _glfwInputKeyboard(window, &ev); } } diff --git a/kitty/glfw-wrapper.h b/kitty/glfw-wrapper.h index 4cd275e90..d2c506780 100644 --- a/kitty/glfw-wrapper.h +++ b/kitty/glfw-wrapper.h @@ -1026,6 +1026,9 @@ typedef struct GLFWkeyevent // For internal use only. On Linux it is the actual keycode reported by the windowing system, in contrast // to native_key which can be the result of a compose operation. On macOS it is the same as native_key. uint32_t native_key_id; + + // True if this is a synthesized event on focus change + bool fake_event_on_focus_change; } GLFWkeyevent; /*! @brief The function pointer type for error callbacks. diff --git a/kitty/glfw.c b/kitty/glfw.c index bc23dcaf9..9076b6891 100644 --- a/kitty/glfw.c +++ b/kitty/glfw.c @@ -457,7 +457,7 @@ key_callback(GLFWwindow *w, GLFWkeyevent *ev) { #endif mods_at_last_key_or_button_event = ev->mods; global_state.callback_os_window->cursor_blink_zero_time = monotonic(); - if (is_window_ready_for_callbacks()) on_key_input(ev); + if (is_window_ready_for_callbacks() && !ev->fake_event_on_focus_change) on_key_input(ev); global_state.callback_os_window = NULL; request_tick_callback(); }