From 52f635b9a0e1fe074bf39b49b25d3ef3f6484676 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 27 Aug 2021 17:42:48 +0200 Subject: [PATCH] macOS: Hide mouse cursor when initiating IM enabled text input Fixes: QTBUG-72744 Pick-to: 6.2 Change-Id: I952710e88a11fd00498562c9011461a010f02f7b Reviewed-by: Volker Hilsheimer --- src/plugins/platforms/cocoa/qnsview_keys.mm | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/plugins/platforms/cocoa/qnsview_keys.mm b/src/plugins/platforms/cocoa/qnsview_keys.mm index 05f2421876b..c8c6fb320af 100644 --- a/src/plugins/platforms/cocoa/qnsview_keys.mm +++ b/src/plugins/platforms/cocoa/qnsview_keys.mm @@ -88,6 +88,19 @@ // unless we explicit set m_sendKeyEvent to deliver as a normal key event. m_sendKeyEvent = false; + // Match NSTextView's keyDown behavior of hiding the cursor before + // interpreting key events. Shortcuts should not trigger this though. + // Unfortunately many of our controls handle shortcuts by accepting + // the ShortcutOverride event and then handling the shortcut in the + // following key event, and QWSI::handleShortcutEvent doesn't reveal + // whether this will be the case. For NSTextView this is not an issue + // as shortcuts are handled via performKeyEquivalent, which happens + // prior to keyDown. To work around this until we can get the info + // we need from handleShortcutEvent we match AppKit and assume that + // any key press with a command or control modifier is a shortcut. + if (!(nsevent.modifierFlags & (NSEventModifierFlagCommand | NSEventModifierFlagControl))) + [NSCursor setHiddenUntilMouseMoves:YES]; + qCDebug(lcQpaKeys) << "Interpreting key event for focus object" << focusObject; m_currentlyInterpretedKeyEvent = nsevent; [self interpretKeyEvents:@[nsevent]];