From a080fc9f89d0e1efa41841219dbb38454a2ff375 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Mon, 19 Dec 2022 19:03:44 +0100 Subject: [PATCH] macOS: Send synthetic cursorUpdate events for utility windows In faffaa729282b435fb330e1c92523fc0df3fc051 we limited our cursor update workaround to key windows, but macOS also sends cursorUpdate events to non-key windows with the NSWindowStyleMaskUtilityWindow style mask, so we include this in our workaround logic from ae8e96d4c2fc43. We include NSWindowStyleMaskTitled in this check, as macOS seems to require a window to be titled to treat it as a utility window. Task-number: QTBUG-96374 Change-Id: I1c54da181acbe472c2f598fec37aeadada3956bb Reviewed-by: Timur Pocheptsov --- src/plugins/platforms/cocoa/qcocoawindow.mm | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index d7d82a9a7d..af5afab00d 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1797,6 +1797,8 @@ void QCocoaWindow::setWindowCursor(NSCursor *cursor) if (isForeignWindow()) return; + qCInfo(lcQpaMouse) << "Setting" << this << "cursor to" << cursor; + QNSView *view = qnsview_cast(m_view); if (cursor == view.cursor) return; @@ -1808,11 +1810,15 @@ void QCocoaWindow::setWindowCursor(NSCursor *cursor) // There's a bug in AppKit where calling invalidateCursorRectsForView when // there's an override cursor active (for example when hovering over the // window frame), will not result in a cursorUpdate: callback. To work around - // this we synthesize a cursor update event and call the callback ourselves, - // if we detect that the mouse is currently over the view, and the window key. + // this we synthesize a cursor update event and call the callback ourselves. + // We only do this is if the window would normally receive cursor updates. auto locationInWindow = m_view.window.mouseLocationOutsideOfEventStream; auto locationInSuperview = [m_view.superview convertPoint:locationInWindow fromView:nil]; - if (m_view.window.keyWindow && [m_view hitTest:locationInSuperview] == m_view) { + bool mouseIsOverView = [m_view hitTest:locationInSuperview] == m_view; + auto utilityMask = NSWindowStyleMaskUtilityWindow | NSWindowStyleMaskTitled; + bool isUtilityWindow = (m_view.window.styleMask & utilityMask) == utilityMask; + if (mouseIsOverView && (m_view.window.keyWindow || isUtilityWindow)) { + qCDebug(lcQpaMouse) << "Synthesizing cursor update"; [m_view cursorUpdate:[NSEvent enterExitEventWithType:NSEventTypeCursorUpdate location:locationInWindow modifierFlags:0 timestamp:0 windowNumber:m_view.window.windowNumber context:nil