diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index f29927751a..bb86040481 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -1788,26 +1788,28 @@ void QCocoaWindow::setWindowCursor(NSCursor *cursor) view.cursor = cursor; + // We're not using the the legacy cursor rects API to manage our + // cursor, but calling this function also invalidates AppKit's + // view of whether or not we need a cursorUpdate callback for + // our tracking area. [m_view.window invalidateCursorRectsForView:m_view]; - if (QOperatingSystemVersion::current() <= QOperatingSystemVersion::MacOSMonterey) { - // 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. - // 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]; - 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 - eventNumber:0 trackingNumber:0 userData:0]]; - } + // We've informed AppKit that we need a cursorUpdate, but cursor + // updates for tracking areas are deferred in some cases, such as + // when the mouse is down, whereas we want a synchronous update. + // To ensure an updated cursor we synthesize a cursor update event + // now if the window is otherwise allowed to change the cursor. + auto locationInWindow = m_view.window.mouseLocationOutsideOfEventStream; + auto locationInSuperview = [m_view.superview convertPoint:locationInWindow fromView:nil]; + 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 + eventNumber:0 trackingNumber:0 userData:0]]; } }