From 9d9bc7db50e7d4fc29da10be4bc7a4157b13a566 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Tue, 28 Feb 2023 16:09:46 +0900 Subject: [PATCH] ui/cocoa: Override windowDidResignKey MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit This fixes pressed keys being stuck when the deck is clicked and the window loses focus. In the past, Gustavo Noronha Silva also had a patch to fix this issue though it only ungrabs mouse and does not release keys, and depends on another out-of-tree patch: https://github.com/akihikodaki/qemu/pull/3/commits/e906a80147b1dc6d4f31b6a08064ef9871a2b76c Signed-off-by: Akihiko Odaki Message-Id: <20230228070946.12370-1-akihiko.odaki@daynix.com> Signed-off-by: Philippe Mathieu-Daudé --- ui/cocoa.m | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ui/cocoa.m b/ui/cocoa.m index 289a2b193e..985a0f5069 100644 --- a/ui/cocoa.m +++ b/ui/cocoa.m @@ -1330,10 +1330,15 @@ static CGEventRef handleTapEvent(CGEventTapProxy proxy, CGEventType type, CGEven return NO; } -/* Called when QEMU goes into the background */ -- (void) applicationWillResignActive: (NSNotification *)aNotification +/* + * Called when QEMU goes into the background. Note that + * [-NSWindowDelegate windowDidResignKey:] is used here instead of + * [-NSApplicationDelegate applicationWillResignActive:] because it cannot + * detect that the window loses focus when the deck is clicked on macOS 13.2.1. + */ +- (void) windowDidResignKey: (NSNotification *)aNotification { - COCOA_DEBUG("QemuCocoaAppController: applicationWillResignActive\n"); + COCOA_DEBUG("%s\n", __func__); [cocoaView ungrabMouse]; [cocoaView raiseAllKeys]; } -- 2.49.0