+ QWindowSystemInterface::handleExposeEvent(window(), QRect(QPoint(), geometry().size()));
+ QWindowSystemInterface::flushWindowSystemEvents();
+
+ if (m_nsWindow) {
+ // setWindowState might have been called while the window was hidden and
+ // will not change the NSWindow state in that case. Sync up here:
+ syncWindowState(window()->windowState());
+
+ if (window()->windowState() != Qt::WindowMinimized) {
+ if ((window()->modality() == Qt::WindowModal
+ || window()->type() == Qt::Sheet)
+ && parentCocoaWindow) {
+ // show the window as a sheet
+ [NSApp beginSheet:m_nsWindow modalForWindow:parentCocoaWindow->m_nsWindow modalDelegate:nil didEndSelector:nil contextInfo:nil];
+ } else if (window()->modality() != Qt::NonModal) {
+ // show the window as application modal
+ QCocoaEventDispatcher *cocoaEventDispatcher = qobject_cast<QCocoaEventDispatcher *>(QGuiApplication::instance()->eventDispatcher());
+ Q_ASSERT(cocoaEventDispatcher != 0);
+ QCocoaEventDispatcherPrivate *cocoaEventDispatcherPrivate = static_cast<QCocoaEventDispatcherPrivate *>(QObjectPrivate::get(cocoaEventDispatcher));
+ cocoaEventDispatcherPrivate->beginModalSession(window());
+ m_hasModalSession = true;
+ } else if ([m_nsWindow canBecomeKeyWindow]) {
+ [m_nsWindow makeKeyAndOrderFront:nil];
+ } else {
+ [m_nsWindow orderFront: nil];
+ }
+
+ // We want the events to properly reach the popup
+ if (window()->type() == Qt::Popup)
+ [(NSPanel *)m_nsWindow setWorksWhenModal:YES];
+ }
+ }
+ } else {
+ // qDebug() << "close" << this;
+ if (m_nsWindow) {
+ if (m_hasModalSession) {
+ QCocoaEventDispatcher *cocoaEventDispatcher = qobject_cast<QCocoaEventDispatcher *>(QGuiApplication::instance()->eventDispatcher());
+ Q_ASSERT(cocoaEventDispatcher != 0);
+ QCocoaEventDispatcherPrivate *cocoaEventDispatcherPrivate = static_cast<QCocoaEventDispatcherPrivate *>(QObjectPrivate::get(cocoaEventDispatcher));
+ cocoaEventDispatcherPrivate->endModalSession(window());
+ m_hasModalSession = false;
+ } else {
+ if ([m_nsWindow isSheet])
+ [NSApp endSheet:m_nsWindow];
+ }
+ [m_nsWindow orderOut:m_nsWindow];
+ }
+ if (!QCoreApplication::closingDown())
+ QWindowSystemInterface::handleExposeEvent(window(), QRegion());
+ }
+}
+
+NSInteger QCocoaWindow::windowLevel(Qt::WindowFlags flags)
+{
+ Qt::WindowType type = static_cast<Qt::WindowType>(int(flags & Qt::WindowType_Mask));
+
+ NSInteger windowLevel = NSNormalWindowLevel;
+
+ if (type == Qt::Tool)
+ windowLevel = NSFloatingWindowLevel;
+ else if ((type & Qt::Popup) == Qt::Popup)
+ windowLevel = NSPopUpMenuWindowLevel;