diff options
Diffstat (limited to 'src/plugins/platforms/cocoa/qcocoawindow.mm')
-rw-r--r-- | src/plugins/platforms/cocoa/qcocoawindow.mm | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 5be65f2141..6bfdd82e19 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -104,7 +104,7 @@ static void qRegisterNotificationCallbacks() if (QNSView *qnsView = qnsview_cast(notification.object)) cocoaWindows += qnsView.platformWindow; } else { - qCWarning(lcCocoaNotifications) << "Unhandled notifcation" + qCWarning(lcCocoaNotifications) << "Unhandled notification" << notification.name << "for" << notification.object; return; } @@ -367,12 +367,18 @@ void QCocoaWindow::setVisible(bool visible) if (window()->windowState() != Qt::WindowMinimized) { if (parentCocoaWindow && (window()->modality() == Qt::WindowModal || window()->type() == Qt::Sheet)) { // Show the window as a sheet - [parentCocoaWindow->nativeWindow() beginSheet:m_view.window completionHandler:nil]; + NSWindow *nativeParentWindow = parentCocoaWindow->nativeWindow(); + if (!nativeParentWindow.attachedSheet) + [nativeParentWindow beginSheet:m_view.window completionHandler:nil]; + else + [nativeParentWindow beginCriticalSheet:m_view.window completionHandler:nil]; } else if (window()->modality() == Qt::ApplicationModal) { // Show the window as application modal eventDispatcher()->beginModalSession(window()); } else if (m_view.window.canBecomeKeyWindow) { - bool shouldBecomeKeyNow = !NSApp.modalWindow || m_view.window.worksWhenModal; + bool shouldBecomeKeyNow = !NSApp.modalWindow + || m_view.window.worksWhenModal + || !NSApp.modalWindow.visible; // Panels with becomesKeyOnlyIfNeeded set should not activate until a view // with needsPanelToBecomeKey, for example a line edit, is clicked. @@ -522,7 +528,10 @@ NSUInteger QCocoaWindow::windowStyleMask(Qt::WindowFlags flags) NSUInteger styleMask = (frameless || !resizable) ? NSWindowStyleMaskBorderless : NSWindowStyleMaskResizable; if (frameless) { - // No further customizations for frameless since there are no window decorations. + // Frameless windows do not display the traffic lights buttons for + // e.g. minimize, however StyleMaskMiniaturizable is required to allow + // programmatic minimize. + styleMask |= NSWindowStyleMaskMiniaturizable; } else if (flags & Qt::CustomizeWindowHint) { if (flags & Qt::WindowTitleHint) styleMask |= NSWindowStyleMaskTitled; @@ -545,9 +554,11 @@ NSUInteger QCocoaWindow::windowStyleMask(Qt::WindowFlags flags) if (m_drawContentBorderGradient) styleMask |= NSWindowStyleMaskTexturedBackground; - // Don't wipe fullscreen state + // Don't wipe existing states if (m_view.window.styleMask & NSWindowStyleMaskFullScreen) styleMask |= NSWindowStyleMaskFullScreen; + if (m_view.window.styleMask & NSWindowStyleMaskFullSizeContentView) + styleMask |= NSWindowStyleMaskFullSizeContentView; return styleMask; } @@ -676,9 +687,10 @@ void QCocoaWindow::applyWindowState(Qt::WindowStates requestedState) switch (currentState) { case Qt::WindowMinimized: [nsWindow deminiaturize:sender]; - Q_ASSERT_X(windowState() != Qt::WindowMinimized, "QCocoaWindow", - "[NSWindow deminiaturize:] is synchronous"); - break; + // Deminiaturizing is not synchronous, so we need to wait for the + // NSWindowDidMiniaturizeNotification before continuing to apply + // the new state. + return; case Qt::WindowFullScreen: { toggleFullScreen(); // Exiting fullscreen is not synchronous, so we need to wait for the @@ -842,7 +854,15 @@ void QCocoaWindow::windowDidDeminiaturize() if (!isContentView()) return; + Qt::WindowState requestedState = window()->windowState(); + handleWindowStateChanged(); + + if (requestedState != windowState() && requestedState != Qt::WindowMinimized) { + // We were only going out of minimized as an intermediate step before + // progressing into the final step, so re-sync the desired state. + applyWindowState(requestedState); + } } void QCocoaWindow::handleWindowStateChanged(HandleFlags flags) @@ -1265,11 +1285,15 @@ void QCocoaWindow::windowDidChangeScreen() return; // Note: When a window is resized to 0x0 Cocoa will report the window's screen as nil - auto *currentScreen = QCocoaScreen::get(m_view.window.screen); + NSScreen *nsScreen = m_view.window.screen; + + qCDebug(lcQpaWindow) << window() << "did change" << nsScreen; + QCocoaScreen::updateScreens(); + auto *previousScreen = static_cast<QCocoaScreen*>(screen()); + auto *currentScreen = QCocoaScreen::get(nsScreen); - Q_ASSERT_X(!m_view.window.screen || currentScreen, - "QCocoaWindow", "Failed to get QCocoaScreen for NSScreen"); + qCDebug(lcQpaWindow) << "Screen changed for" << window() << "from" << previousScreen << "to" << currentScreen; // Note: The previous screen may be the same as the current screen, either because // a) the screen was just reconfigured, which still results in AppKit sending an @@ -1282,7 +1306,6 @@ void QCocoaWindow::windowDidChangeScreen() // device-pixel ratio may have changed, and needs to be delivered to all // windows, both top level and child windows. - qCDebug(lcQpaWindow) << "Screen changed for" << window() << "from" << previousScreen << "to" << currentScreen; QWindowSystemInterface::handleWindowScreenChanged<QWindowSystemInterface::SynchronousDelivery>( window(), currentScreen ? currentScreen->screen() : nullptr); @@ -1307,10 +1330,19 @@ void QCocoaWindow::windowWillClose() bool QCocoaWindow::windowShouldClose() { qCDebug(lcQpaWindow) << "QCocoaWindow::windowShouldClose" << window(); + // This callback should technically only determine if the window // should (be allowed to) close, but since our QPA API to determine // that also involves actually closing the window we do both at the // same time, instead of doing the latter in windowWillClose. + + // If the window is closed, we will release and deallocate the NSWindow. + // But frames higher up in the stack might still expect the window to + // be alive, since the windowShouldClose: callback is technically only + // supposed to answer YES or NO. To ensure the window is still alive + // we put an autorelease in the closest pool (typically the runloop). + [[m_view.window retain] autorelease]; + return QWindowSystemInterface::handleCloseEvent<QWindowSystemInterface::SynchronousDelivery>(window()); } @@ -1714,6 +1746,20 @@ void QCocoaWindow::setWindowCursor(NSCursor *cursor) view.cursor = cursor; [m_view.window invalidateCursorRectsForView:m_view]; + + // 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. + auto locationInWindow = m_view.window.mouseLocationOutsideOfEventStream; + auto locationInSuperview = [m_view.superview convertPoint:locationInWindow fromView:nil]; + if ([m_view hitTest:locationInSuperview] == m_view) { + [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]]; + } } void QCocoaWindow::registerTouch(bool enable) |