summaryrefslogtreecommitdiffstats
path: root/src/plugins/platforms/cocoa/qnswindowdelegate.mm
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@qt.io>2018-06-30 22:59:21 +0200
committerLiang Qi <liang.qi@qt.io>2018-07-02 11:23:45 +0200
commite3ed2281c0c891cf3b15c95f9f7cdae42e9f233a (patch)
treeaae8da6ce616eae02b69fb1fcdcb4383c8fe6811 /src/plugins/platforms/cocoa/qnswindowdelegate.mm
parent3be141d5bc199080b524d8f6f5ce514e8f74d23a (diff)
parente75e4b39b78ba05ea2cd45dc96acf99fc89c5915 (diff)
Merge remote-tracking branch 'origin/5.11' into dev
Conflicts: src/plugins/platforms/cocoa/qnsview.mm src/plugins/platforms/cocoa/qnsview_dragging.mm src/plugins/platforms/ios/qiosinputcontext.mm src/plugins/platforms/xcb/qxcbconnection.cpp src/plugins/platforms/xcb/qxcbconnection_xi2.cpp src/plugins/platforms/xcb/qxcbwindow.cpp src/tools/androiddeployqt/main.cpp Was moved from qttools into qtbase in 5.11. So re-apply 32398e4d here. tests/auto/corelib/global/qlogging/test/test.pro tests/auto/corelib/global/qlogging/tst_qlogging.cpp tests/auto/corelib/io/qfile/tst_qfile.cpp tests/auto/corelib/kernel/qtimer/tst_qtimer.cpp tests/auto/corelib/thread/qthreadstorage/test/test.pro tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp tests/auto/widgets/kernel/qapplication/test/test.pro Done-with: Gatis Paeglis <gatis.paeglis@qt.io> Done-with: MÃ¥rten Nordheim <marten.nordheim@qt.io> Done-with: Oliver Wolff <oliver.wolff@qt.io> Change-Id: Id970486c5315a1718c540f00deb2633533e8fc7b
Diffstat (limited to 'src/plugins/platforms/cocoa/qnswindowdelegate.mm')
-rw-r--r--src/plugins/platforms/cocoa/qnswindowdelegate.mm35
1 files changed, 24 insertions, 11 deletions
diff --git a/src/plugins/platforms/cocoa/qnswindowdelegate.mm b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
index 6079a35d05..1c21879a89 100644
--- a/src/plugins/platforms/cocoa/qnswindowdelegate.mm
+++ b/src/plugins/platforms/cocoa/qnswindowdelegate.mm
@@ -72,25 +72,38 @@ static QRegExp whitespaceRegex = QRegExp(QStringLiteral("\\s*"));
/*!
Overridden to ensure that the zoomed state always results in a maximized
window, which would otherwise not be the case for borderless windows.
+
+ We also keep the window on the same screen as before; something AppKit
+ sometimes fails to do using its built in logic.
*/
- (NSRect)windowWillUseStandardFrame:(NSWindow *)window defaultFrame:(NSRect)proposedFrame
{
Q_UNUSED(proposedFrame);
Q_ASSERT(window == m_cocoaWindow->nativeWindow());
-
- // We compute the maximized state based on the maximum size, and
- // the current position of the window. This may result in the window
- // geometry falling outside of the current screen's available geometry,
- // e.g. when there is not maximize size set, but this is okey, AppKit
- // will then shift and possibly clip the geometry for us.
const QWindow *w = m_cocoaWindow->window();
- QRect maximizedRect = QRect(w->framePosition(), w->maximumSize());
- // QWindow::maximumSize() refers to the client size,
- // but AppKit expects the full frame size.
- maximizedRect.adjust(0, 0, 0, w->frameMargins().top());
+ // maximumSize() refers to the client size, but AppKit expects the full frame size
+ QSizeF maximumSize = w->maximumSize() + QSize(0, w->frameMargins().top());
+
+ // The window should never be larger than the current screen geometry
+ const QRectF screenGeometry = m_cocoaWindow->screen()->geometry();
+ maximumSize = maximumSize.boundedTo(screenGeometry.size());
+
+ // Use the current frame position for the initial maximized frame,
+ // so that the window stays put and just expand, in case its maximum
+ // size is within the screen bounds.
+ QRectF maximizedFrame = QRectF(w->framePosition(), maximumSize);
+
+ // But constrain the frame to the screen bounds in case the frame
+ // extends beyond the screen bounds as a result of starting out
+ // with the current frame position.
+ maximizedFrame.translate(QPoint(
+ qMax(screenGeometry.left() - maximizedFrame.left(), 0.0) +
+ qMin(screenGeometry.right() - maximizedFrame.right(), 0.0),
+ qMax(screenGeometry.top() - maximizedFrame.top(), 0.0) +
+ qMin(screenGeometry.bottom() - maximizedFrame.bottom(), 0.0)));
- return QCocoaScreen::mapToNative(maximizedRect);
+ return QCocoaScreen::mapToNative(maximizedFrame);
}
- (BOOL)window:(NSWindow *)window shouldPopUpDocumentPathMenu:(NSMenu *)menu