Skip to content

Commit

Permalink
macOS: Send synthetic cursorUpdate events for utility windows
Browse files Browse the repository at this point in the history
In faffaa7 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 ae8e96d. 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 <[email protected]>
  • Loading branch information
torarnv committed Jan 3, 2023
1 parent 49a8311 commit a080fc9
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/plugins/platforms/cocoa/qcocoawindow.mm
Original file line number Diff line number Diff line change
Expand Up @@ -1797,6 +1797,8 @@ Posted whenever an NSView object that has attached surfaces (that is,
if (isForeignWindow())
return;

qCInfo(lcQpaMouse) << "Setting" << this << "cursor to" << cursor;

QNSView *view = qnsview_cast(m_view);
if (cursor == view.cursor)
return;
Expand All @@ -1808,11 +1810,15 @@ Posted whenever an NSView object that has attached surfaces (that is,
// 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
Expand Down

0 comments on commit a080fc9

Please sign in to comment.