From 5d48eb8bbc43b37235c29c2caf1e5fafec864b49 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Mon, 19 May 2014 19:58:35 +0200 Subject: Cocoa: Make sure modal windows get correct geometry on show MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit beginModalSessionForWindow will center the window and ignore the set geometry. So to workaround this it checks the new value against the old one and moves it back if need be. Change-Id: I38bc74c04138992f2e0570fca666414025aeeba8 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index e0ce9f9648..b625f233ce 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -622,7 +622,8 @@ NSModalSession QCocoaEventDispatcherPrivate::currentModalSession() if (!info.session) { QCocoaAutoReleasePool pool; - NSWindow *nswindow = static_cast(info.window->handle())->nativeWindow(); + QCocoaWindow *cocoaWindow = static_cast(info.window->handle()); + NSWindow *nswindow = cocoaWindow->nativeWindow(); if (!nswindow) continue; @@ -630,7 +631,10 @@ NSModalSession QCocoaEventDispatcherPrivate::currentModalSession() QBoolBlocker block1(blockSendPostedEvents, true); info.nswindow = nswindow; [(NSWindow*) info.nswindow retain]; + QRect rect = cocoaWindow->geometry(); info.session = [NSApp beginModalSessionForWindow:nswindow]; + if (rect != cocoaWindow->geometry()) + cocoaWindow->setGeometry(rect); } currentModalSessionCached = info.session; cleanupModalSessionsNeeded = false; -- cgit v1.2.3 From 7ba0eb5a0daae59c495bbf250fa37a2627950e94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 21 May 2014 11:30:54 +0200 Subject: Cocoa: Prevent crash on QWindow delete. Clear the QCocoaWindow pointer stored on the QNSWindowHelper when detaching from the platform window. This makes sure callbacks from cocoa does not try access deleted Qt window objects. Task-number: QTBUG-39141 Change-Id: I4672eae92940dcbd59a2848e56f94b50a828bbf6 Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qcocoawindow.mm | 1 + 1 file changed, 1 insertion(+) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 651fedb26e..13e8dde012 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -182,6 +182,7 @@ static bool isMouseEvent(NSEvent *ev) - (void)detachFromPlatformWindow { + _platformWindow = 0; [self.window.delegate release]; self.window.delegate = nil; } -- cgit v1.2.3 From 1ac0f953ba70ceda76e90918ab4ae7ebe2339969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 21 May 2014 11:36:54 +0200 Subject: Cocoa: Remove the NSWindow -> QCococaWindow hash. Cast the NSWindow to a QNSWindow instead. Now there is no way we can fail to maintain the hash properly. Change-Id: I5fd03b6fad964a61fadb3460b7063fd43ff25c79 Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qcocoaintegration.h | 3 --- src/plugins/platforms/cocoa/qcocoaintegration.mm | 17 +++++------------ src/plugins/platforms/cocoa/qcocoawindow.mm | 5 ----- 3 files changed, 5 insertions(+), 20 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.h b/src/plugins/platforms/cocoa/qcocoaintegration.h index 9c4f86d893..07b73c1a7a 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.h +++ b/src/plugins/platforms/cocoa/qcocoaintegration.h @@ -139,8 +139,6 @@ public: void setToolbar(QWindow *window, NSToolbar *toolbar); NSToolbar *toolbar(QWindow *window) const; void clearToolbars(); - void setWindow(NSWindow* nsWindow, QCocoaWindow *window); - QCocoaWindow *window(NSWindow *window); private: static QCocoaIntegration *mInstance; @@ -159,7 +157,6 @@ private: QScopedPointer mKeyboardMapper; QHash mToolbars; - QHash mWindows; }; QT_END_NAMESPACE diff --git a/src/plugins/platforms/cocoa/qcocoaintegration.mm b/src/plugins/platforms/cocoa/qcocoaintegration.mm index c4398622e8..19753ccc89 100644 --- a/src/plugins/platforms/cocoa/qcocoaintegration.mm +++ b/src/plugins/platforms/cocoa/qcocoaintegration.mm @@ -159,9 +159,12 @@ qreal QCocoaScreen::devicePixelRatio() const QWindow *QCocoaScreen::topLevelAt(const QPoint &point) const { // Get a z-ordered list of windows. Iterate through it until - // we find a window which contains the point. + // we find a (Qt) window which contains the point. for (NSWindow *nsWindow in [NSApp orderedWindows]) { - QCocoaWindow *cocoaWindow = QCocoaIntegration::instance()->window(nsWindow); + if (![nsWindow isKindOfClass:[QNSWindow class]]) + continue; + QNSWindow *qnsWindow = static_cast(nsWindow); + QCocoaWindow *cocoaWindow = qnsWindow.helper.platformWindow; if (!cocoaWindow) continue; QWindow *window = cocoaWindow->window(); @@ -518,16 +521,6 @@ NSToolbar *QCocoaIntegration::toolbar(QWindow *window) const return mToolbars.value(window); } -void QCocoaIntegration::setWindow(NSWindow* nsWindow, QCocoaWindow *window) -{ - mWindows.insert(nsWindow, window); -} - -QCocoaWindow *QCocoaIntegration::window(NSWindow *window) -{ - return mWindows.value(window); -} - void QCocoaIntegration::clearToolbars() { QHash::const_iterator it = mToolbars.constBegin(); diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 13e8dde012..0f51d0664c 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -262,8 +262,6 @@ static bool isMouseEvent(NSEvent *ev) { [self close]; - QCocoaIntegration::instance()->setWindow(self, 0); - if (self.helper.grabbingMouse) { self.helper.releaseOnMouseUp = YES; } else { @@ -330,7 +328,6 @@ static bool isMouseEvent(NSEvent *ev) { [self.helper detachFromPlatformWindow]; [self close]; - QCocoaIntegration::instance()->setWindow(self, 0); [self release]; } @@ -1414,8 +1411,6 @@ QCocoaNSWindow * QCocoaWindow::createNSWindow() applyContentBorderThickness(createdWindow); - QCocoaIntegration::instance()->setWindow(createdWindow, this); - return createdWindow; } -- cgit v1.2.3 From b214c177ea799baa33fe7ef7cf6446407928a38b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 22 May 2014 09:38:34 +0200 Subject: Make QT_MAC_OPENGL_SURFACE_ORDER=-1 work better Mark the window as not opaque and give it a transparent background when layering OpenGL below the window. Change-Id: I2188842249c592f17619f7a2c3ef1fd30958987e Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qcocoawindow.mm | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 0f51d0664c..7ab7486ce9 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -999,9 +999,14 @@ bool QCocoaWindow::isExposed() const bool QCocoaWindow::isOpaque() const { + // OpenGL surfaces can be ordered either above(default) or below the NSWindow. + // When ordering below the window must be tranclucent. + static GLint openglSourfaceOrder = qt_mac_resolveOption(1, "QT_MAC_OPENGL_SURFACE_ORDER"); + bool translucent = (window()->format().alphaBufferSize() > 0 || window()->opacity() < 1 - || (m_qtView && [m_qtView hasMask])); + || (m_qtView && [m_qtView hasMask])) + || (surface()->supportsOpenGL() && openglSourfaceOrder == -1); return !translucent; } @@ -1402,7 +1407,13 @@ QCocoaNSWindow * QCocoaWindow::createNSWindow() NSInteger level = windowLevel(flags); [createdWindow setLevel:level]; - if (window()->format().alphaBufferSize() > 0) { + // OpenGL surfaces can be ordered either above(default) or below the NSWindow. + // When ordering below the window must be tranclucent and have a clear background color. + static GLint openglSourfaceOrder = qt_mac_resolveOption(1, "QT_MAC_OPENGL_SURFACE_ORDER"); + + bool isTranslucent = window()->format().alphaBufferSize() > 0 + || (surface()->supportsOpenGL() && openglSourfaceOrder == -1); + if (isTranslucent) { [createdWindow setBackgroundColor:[NSColor clearColor]]; [createdWindow setOpaque:NO]; } -- cgit v1.2.3 From 626e0f204e846040e8e3a67bfc088f09b5091e7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 14 May 2014 11:30:35 +0200 Subject: Revert "Cocoa: Post event to "show()" a modal window" This reverts commit a9cbddf4739f3cfabd38367b5f872fe2c1a3814c. The reverted commit is an incorrect bug-fix for a regression introduced by adding a call to [NSApp abortModal] in change d9875f7b. Change-Id: If23463ebdfe2ff64c68739dbece73a13773683c9 Reviewed-by: Gabriel de Dietrich --- .../platforms/cocoa/qcocoaeventdispatcher.h | 3 +-- .../platforms/cocoa/qcocoaeventdispatcher.mm | 25 ++++++++++------------ 2 files changed, 12 insertions(+), 16 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h index de6c6585e9..0274ed8201 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h @@ -134,8 +134,6 @@ public: void interrupt(); void flush(); - bool event(QEvent *); - friend void qt_mac_maybeCancelWaitForMoreEventsForwarder(QAbstractEventDispatcher *eventDispatcher); }; @@ -165,6 +163,7 @@ public: // The following variables help organizing modal sessions: QStack cocoaModalSessionStack; bool currentExecIsNSAppRun; + bool modalSessionOnNSAppRun; bool nsAppRunCalledByQt; bool cleanupModalSessionsNeeded; uint processEventsCalled; diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index b625f233ce..98becf0728 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -738,25 +738,13 @@ void QCocoaEventDispatcherPrivate::beginModalSession(QWindow *window) updateChildrenWorksWhenModal(); currentModalSessionCached = 0; if (currentExecIsNSAppRun) { - QEvent *e = new QEvent(QEvent::User); - qApp->postEvent(q, e, Qt::HighEventPriority); + modalSessionOnNSAppRun = true; + q->wakeUp(); } else { q->interrupt(); } } -bool QCocoaEventDispatcher::event(QEvent *e) -{ - Q_D(QCocoaEventDispatcher); - - if (e->type() == QEvent::User) { - d->q_func()->processEvents(QEventLoop::DialogExec | QEventLoop::EventLoopExec | QEventLoop::WaitForMoreEvents); - return true; - } - - return QObject::event(e); -} - void QCocoaEventDispatcherPrivate::endModalSession(QWindow *window) { Q_Q(QCocoaEventDispatcher); @@ -793,6 +781,7 @@ QCocoaEventDispatcherPrivate::QCocoaEventDispatcherPrivate() runLoopTimerRef(0), blockSendPostedEvents(false), currentExecIsNSAppRun(false), + modalSessionOnNSAppRun(false), nsAppRunCalledByQt(false), cleanupModalSessionsNeeded(false), processEventsCalled(0), @@ -923,6 +912,14 @@ void QCocoaEventDispatcherPrivate::postedEventsSourceCallback(void *info) // processEvents() was called "manually," ignore this source for now d->maybeCancelWaitForMoreEvents(); return; + } else if (d->modalSessionOnNSAppRun) { + // We're about to spawn the 1st modal session on top of the main runloop. + // Instead of calling processPostedEvents(), which would need us stop + // NSApp, we just re-enter processEvents(). This is equivalent to calling + // QDialog::exec() except that it's done in a non-blocking way. + d->modalSessionOnNSAppRun = false; + d->q_func()->processEvents(QEventLoop::DialogExec | QEventLoop::EventLoopExec | QEventLoop::WaitForMoreEvents); + return; } d->processPostedEvents(); d->maybeCancelWaitForMoreEvents(); -- cgit v1.2.3 From 385ba9e7e3604fa181e89ae7242a6b1a36544c94 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 14 May 2014 11:30:46 +0200 Subject: Revert "Cocoa: Don't stop NSApp when showing a modal dialog" This reverts commit ff3dcc49c4a1912189091e35e87cb61af2f62d47. The reverted commit is an incorrect bug-fix for a regression introduced by adding a call to [NSApp abortModal] in change d9875f7b. Change-Id: I1307d1790ada740e0552d62267b6009cbccd6c4c Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qcocoaeventdispatcher.h | 1 - src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm | 16 +--------------- 2 files changed, 1 insertion(+), 16 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h index 0274ed8201..33d7dcbcf4 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h @@ -163,7 +163,6 @@ public: // The following variables help organizing modal sessions: QStack cocoaModalSessionStack; bool currentExecIsNSAppRun; - bool modalSessionOnNSAppRun; bool nsAppRunCalledByQt; bool cleanupModalSessionsNeeded; uint processEventsCalled; diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index 98becf0728..97b8771354 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -725,6 +725,7 @@ void QCocoaEventDispatcherPrivate::beginModalSession(QWindow *window) // setting currentModalSessionCached to zero, so that interrupt() calls // [NSApp abortModal] if another modal session is currently running Q_Q(QCocoaEventDispatcher); + q->interrupt(); // Add a new, empty (null), NSModalSession to the stack. // It will become active the next time QEventDispatcher::processEvents is called. @@ -737,12 +738,6 @@ void QCocoaEventDispatcherPrivate::beginModalSession(QWindow *window) cocoaModalSessionStack.push(info); updateChildrenWorksWhenModal(); currentModalSessionCached = 0; - if (currentExecIsNSAppRun) { - modalSessionOnNSAppRun = true; - q->wakeUp(); - } else { - q->interrupt(); - } } void QCocoaEventDispatcherPrivate::endModalSession(QWindow *window) @@ -781,7 +776,6 @@ QCocoaEventDispatcherPrivate::QCocoaEventDispatcherPrivate() runLoopTimerRef(0), blockSendPostedEvents(false), currentExecIsNSAppRun(false), - modalSessionOnNSAppRun(false), nsAppRunCalledByQt(false), cleanupModalSessionsNeeded(false), processEventsCalled(0), @@ -912,14 +906,6 @@ void QCocoaEventDispatcherPrivate::postedEventsSourceCallback(void *info) // processEvents() was called "manually," ignore this source for now d->maybeCancelWaitForMoreEvents(); return; - } else if (d->modalSessionOnNSAppRun) { - // We're about to spawn the 1st modal session on top of the main runloop. - // Instead of calling processPostedEvents(), which would need us stop - // NSApp, we just re-enter processEvents(). This is equivalent to calling - // QDialog::exec() except that it's done in a non-blocking way. - d->modalSessionOnNSAppRun = false; - d->q_func()->processEvents(QEventLoop::DialogExec | QEventLoop::EventLoopExec | QEventLoop::WaitForMoreEvents); - return; } d->processPostedEvents(); d->maybeCancelWaitForMoreEvents(); -- cgit v1.2.3 From 11fdc4f6c06922b474a311d7afb8a393686ddf13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Wed, 14 May 2014 11:32:54 +0200 Subject: Partially revert "Cocoa: support modal windows" This reverts parts of commit d9875f7bff6d52a52a1d0bf4002044a5304cf6bf, in particular the code for "2. Make interrupt() use [NSApp abortModal]" abortModal is not the right way to end a modal session, and introduced bad side effects, as reported in QTBUG-34677. Restore this part of the event dispatcher to the Qt 4 state. Change-Id: Iacc2d4a0757807c87c4320c93ed4db186622945c Reviewed-by: Gabriel de Dietrich --- .../platforms/cocoa/qcocoaeventdispatcher.mm | 36 ++++++++-------------- 1 file changed, 12 insertions(+), 24 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index 97b8771354..96a8fa1ad4 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -721,9 +721,7 @@ void QCocoaEventDispatcherPrivate::beginModalSession(QWindow *window) { // We need to start spinning the modal session. Usually this is done with // QDialog::exec() for Qt Widgets based applications, but for others that - // just call show(), we need to interrupt(). We call this here, before - // setting currentModalSessionCached to zero, so that interrupt() calls - // [NSApp abortModal] if another modal session is currently running + // just call show(), we need to interrupt(). Q_Q(QCocoaEventDispatcher); q->interrupt(); @@ -759,10 +757,7 @@ void QCocoaEventDispatcherPrivate::endModalSession(QWindow *window) info.window = 0; if (i + endedSessions == stackSize-1) { // The top sessions ended. Interrupt the event dispatcher to - // start spinning the correct session immediately. Like in - // beginModalSession(), we call interrupt() before clearing - // currentModalSessionCached to make sure we stop any currently - // running modal session with [NSApp abortModal] + // start spinning the correct session immediately. q->interrupt(); currentModalSessionCached = 0; cleanupModalSessionsNeeded = true; @@ -935,23 +930,16 @@ void QCocoaEventDispatcher::interrupt() { Q_D(QCocoaEventDispatcher); d->interrupt = true; - if (d->currentModalSessionCached) { - // If a modal session is active, abort it so that we can clean it up - // later. We can't use [NSApp stopModal] here, because we do not know - // where the interrupt() came from. - [NSApp abortModal]; - } else { - wakeUp(); - - // We do nothing more here than setting d->interrupt = true, and - // poke the event loop if it is sleeping. Actually stopping - // NSApp, or the current modal session, is done inside the send - // posted events callback. We do this to ensure that all current pending - // cocoa events gets delivered before we stop. Otherwise, if we now stop - // the last event loop recursion, cocoa will just drop pending posted - // events on the floor before we get a chance to reestablish a new session. - d->cancelWaitForMoreEvents(); - } + wakeUp(); + + // We do nothing more here than setting d->interrupt = true, and + // poke the event loop if it is sleeping. Actually stopping + // NSApp, or the current modal session, is done inside the send + // posted events callback. We do this to ensure that all current pending + // cocoa events gets delivered before we stop. Otherwise, if we now stop + // the last event loop recursion, cocoa will just drop pending posted + // events on the floor before we get a chance to reestablish a new session. + d->cancelWaitForMoreEvents(); } void QCocoaEventDispatcher::flush() -- cgit v1.2.3 From 530607d8ba0dac8d91d20ec0e62d3129cb21e225 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 15 May 2014 13:29:25 +0200 Subject: Cocoa: Fix modal session cleanup. Call [NSApp endModalSession] at the correct time. Calling cleanupModalSessions() from processPostedEvents() resulted in endModalSession being called from within [NSApp runModalSession] - ending and cleaning up the the modal session while Cocoa is still using it. Move the cleanupModalSessions() call to to after runModalSession returns. Task-number: QTBUG-37699 Change-Id: I5868def36f6869667b0bbe33733286e3e49488eb Reviewed-by: Gabriel de Dietrich --- src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index 96a8fa1ad4..9aaf08adcf 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -415,6 +415,11 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) // 'session' as well. As a result, we need to restart all internal sessions: d->temporarilyStopAllModalSessions(); } + + // Clean up the modal session list, call endModalSession. + if (d->cleanupModalSessionsNeeded) + d->cleanupModalSessions(); + } else { d->nsAppRunCalledByQt = true; QBoolBlocker execGuard(d->currentExecIsNSAppRun, true); @@ -441,6 +446,11 @@ bool QCocoaEventDispatcher::processEvents(QEventLoop::ProcessEventsFlags flags) // 'session' as well. As a result, we need to restart all internal sessions: d->temporarilyStopAllModalSessions(); } + + // Clean up the modal session list, call endModalSession. + if (d->cleanupModalSessionsNeeded) + d->cleanupModalSessions(); + retVal = true; } else do { // Dispatch all non-user events (but que non-user events up for later). In @@ -860,9 +870,6 @@ void QCocoaEventDispatcherPrivate::processPostedEvents() return; } - if (cleanupModalSessionsNeeded) - cleanupModalSessions(); - if (interrupt) { if (currentExecIsNSAppRun) { // The event dispatcher has been interrupted. But since -- cgit v1.2.3 From 9e02f9cf085386f44045e5991a39c05acb660b5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Morten=20Johan=20S=C3=B8rvig?= Date: Thu, 15 May 2014 23:14:58 +0200 Subject: Cocoa: Make QMacNativeWidget event processing work MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Don't interrupt the Qt event loop if the Qt event loop isn't running (meaning processEvents has not/ will not be called). This can happen in the QMacNativeWidget or plugin case where the native code calls [NSApp run] and QApplication::exec() is never called. In Qt 4 this was not necessary since UI event processing was more direct: QCocoaView would call QCoreApplication::sendMouseEvent/sendSpontaneousEvent directly on mouse events. Task-number: QTBUG-36225 Change-Id: I2894cbbca66a902652c9f8bc916e94ad8ce0e18e Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index 9aaf08adcf..45c0714b6b 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -870,7 +870,7 @@ void QCocoaEventDispatcherPrivate::processPostedEvents() return; } - if (interrupt) { + if (processEventsCalled > 0 && interrupt) { if (currentExecIsNSAppRun) { // The event dispatcher has been interrupted. But since // [NSApplication run] is running the event loop, we -- cgit v1.2.3 From 70e4428b6f1c6a4bad112203f67ee7d22107616c Mon Sep 17 00:00:00 2001 From: Gabriel de Dietrich Date: Tue, 3 Jun 2014 14:20:20 +0200 Subject: Cocoa: Adapt to Xcode 6 clang version sudden pickiness MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Yes, that means OS X Yosemite fix. Change-Id: I236f7af7b803de24ff0895e04c9a9253b5cfdb3b Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm | 2 +- src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm | 2 +- src/plugins/platforms/cocoa/qcocoamenuloader.mm | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm index dd3b9f53db..078dc67cad 100644 --- a/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm +++ b/src/plugins/platforms/cocoa/qcocoaaccessibilityelement.mm @@ -380,7 +380,7 @@ - (BOOL)accessibilityIsAttributeSettable:(NSString *)attribute { QAccessibleInterface *iface = QAccessible::accessibleInterface(axid); if (!iface) - return nil; + return NO; if ([attribute isEqualToString:NSAccessibilityFocusedAttribute]) { return iface->state().focusable ? YES : NO; diff --git a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm index f8411845dc..548c6a23f0 100644 --- a/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm +++ b/src/plugins/platforms/cocoa/qcocoaapplicationdelegate.mm @@ -124,7 +124,7 @@ static void cleanupCocoaApplicationDelegate() [dockMenu release]; [qtMenuLoader release]; if (reflectionDelegate) { - [NSApp setDelegate:reflectionDelegate]; + [[NSApplication sharedApplication] setDelegate:reflectionDelegate]; [reflectionDelegate release]; } [[NSNotificationCenter defaultCenter] removeObserver:self]; diff --git a/src/plugins/platforms/cocoa/qcocoamenuloader.mm b/src/plugins/platforms/cocoa/qcocoamenuloader.mm index 60bc3b5a55..9340e945fb 100644 --- a/src/plugins/platforms/cocoa/qcocoamenuloader.mm +++ b/src/plugins/platforms/cocoa/qcocoamenuloader.mm @@ -174,7 +174,7 @@ QT_END_NAMESPACE - (void)removeActionsFromAppMenu { for (NSMenuItem *item in [appMenu itemArray]) - [item setTag:nil]; + [item setTag:0]; } - (void)dealloc -- cgit v1.2.3 From ac7bf97f51837eecc5e5570d5d62996746f378ed Mon Sep 17 00:00:00 2001 From: Dyami Caliri Date: Thu, 22 May 2014 15:19:46 -0700 Subject: Cocoa: clear queued user input events when window is destroyed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QCocoaEventDispatcher stores user input events in a queue in certain cases. If the target of those events is destroyed, the events are later sent to the stale window, causing a crash. Task-number: QTBUG-39211 Change-Id: Ie55d2df5697c742bcb644ebf8c5028015a0b8148 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/cocoa/qcocoaeventdispatcher.h | 2 ++ src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm | 15 +++++++++++++++ src/plugins/platforms/cocoa/qcocoawindow.mm | 10 +++++++++- 3 files changed, 26 insertions(+), 1 deletion(-) (limited to 'src/plugins/platforms/cocoa') diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h index 33d7dcbcf4..dc0b8fcc18 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.h @@ -178,6 +178,8 @@ public: void maybeCancelWaitForMoreEvents(); void ensureNSAppInitialized(); + void removeQueuedUserInputEvents(int nsWinNumber); + QCFSocketNotifier cfSocketNotifier; QList queuedUserInputEvents; // NSEvent * CFRunLoopSourceRef postedEventsSource; diff --git a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm index 45c0714b6b..e7f8992c6d 100644 --- a/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm +++ b/src/plugins/platforms/cocoa/qcocoaeventdispatcher.mm @@ -892,6 +892,21 @@ void QCocoaEventDispatcherPrivate::processPostedEvents() } } +void QCocoaEventDispatcherPrivate::removeQueuedUserInputEvents(int nsWinNumber) +{ + if (nsWinNumber) { + int eventIndex = queuedUserInputEvents.size(); + + while (--eventIndex >= 0) { + NSEvent * nsevent = static_cast(queuedUserInputEvents.at(eventIndex)); + if ([nsevent windowNumber] == nsWinNumber) { + queuedUserInputEvents.removeAt(eventIndex); + [nsevent release]; + } + } + } +} + void QCocoaEventDispatcherPrivate::firstLoopEntry(CFRunLoopObserverRef ref, CFRunLoopActivity activity, void *info) diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm index 7ab7486ce9..c8ca494b33 100644 --- a/src/plugins/platforms/cocoa/qcocoawindow.mm +++ b/src/plugins/platforms/cocoa/qcocoawindow.mm @@ -189,7 +189,15 @@ static bool isMouseEvent(NSEvent *ev) - (void)clearWindow { - _window = nil; + if (_window) { + QCocoaEventDispatcher *cocoaEventDispatcher = qobject_cast(QGuiApplication::instance()->eventDispatcher()); + if (cocoaEventDispatcher) { + QCocoaEventDispatcherPrivate *cocoaEventDispatcherPrivate = static_cast(QObjectPrivate::get(cocoaEventDispatcher)); + cocoaEventDispatcherPrivate->removeQueuedUserInputEvents([_window windowNumber]); + } + + _window = nil; + } } - (void)dealloc -- cgit v1.2.3