From 2945c6223bf067f240a020b2454d6bcac8fa961a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 25 Aug 2021 15:39:47 +0200 Subject: [PATCH] macOS: Return early from key handler if shortcut was handled The code paths after accepting a shortcut event can never be hit. Pick-to: 6.2 Change-Id: Ida77417adb8fcfd25a4b20c4eb86056b3769f014 Reviewed-by: Volker Hilsheimer --- src/plugins/platforms/cocoa/qnsview_keys.mm | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/plugins/platforms/cocoa/qnsview_keys.mm b/src/plugins/platforms/cocoa/qnsview_keys.mm index 9ff3a8a762..db2b4f4139 100644 --- a/src/plugins/platforms/cocoa/qnsview_keys.mm +++ b/src/plugins/platforms/cocoa/qnsview_keys.mm @@ -93,8 +93,9 @@ qCDebug(lcQpaKeys) << "Handling" << nsevent << "as" << qtKey << "with" << modifiers << "and resulting text" << text; + QBoolBlocker resendKeyEventGuard(m_resendKeyEvent, false); // We will send a key event unless the input method sets m_sendKeyEvent to false - m_sendKeyEvent = true; + QBoolBlocker sendKeyEventGuard(m_sendKeyEvent, true); if (eventType == QEvent::KeyPress) { @@ -103,10 +104,7 @@ if (QWindowSystemInterface::handleShortcutEvent(window, timestamp, qtKey, modifiers, nativeScanCode, nativeVirtualKey, nativeModifiers, text, [nsevent isARepeat], 1)) { qCDebug(lcQpaKeys) << "Found matching shortcut; will not send as key event"; - m_sendKeyEvent = false; - // Handling a shortcut may result in closing the window - if (!m_platformWindow) - return true; + return true; } else { qCDebug(lcQpaKeys) << "No matching shortcuts; continuing with key event delivery"; } @@ -157,8 +155,6 @@ nativeScanCode, nativeVirtualKey, nativeModifiers, text, [nsevent isARepeat], 1, false); accepted = QWindowSystemInterface::flushWindowSystemEvents(); } - m_sendKeyEvent = false; - m_resendKeyEvent = false; return accepted; }