macOS: Send synthetic cursorUpdate events for utility windows

In faffaa7292 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 ae8e96d4c2. 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 <timur.pocheptsov@qt.io>
This commit is contained in:
Tor Arne Vestbø 2022-12-19 19:03:44 +01:00
parent 49a8311ae5
commit a080fc9f89

View File

@ -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