summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-07-21 16:48:48 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2020-07-22 14:33:29 +0000
commit8b60ebf93a4ca443a0c101ea72cb806a2b105f04 (patch)
tree5b841d218b3f1fb42ec5c4c575ce2a5aa19007aa
parenta7723f8fa70e1285c7cf7415b1a6518d4111e3ea (diff)
macOS: Ensure initial geometry is always set
QPlatformWindow initializes its view of the geometry based on the QWindow geometry during construction. If the initial geometry we then compute is the same, we would end up exiting early from QCocoaWindow::setGeometry(), because we compared the new geometry against the QPlatformWindow::geometry(), and the geometry would never be reflected in the NSView. Due to other setGeometry calls this was in most cases masked, but could in theory happen, and is preventing us from cleaning up other parts of the code. The call to QWindow::setGeometry() after setting the initial geometry is also broken, as the initial geometry is available through the platform window and QWindow::geometry() already, so setting it again serves nothing except disabling d->positionAutomatic, which is not correct. Change-Id: I0db3cfe7d7c3d14070beee6ae3ea3dfd49da9e05 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
-rw-r--r--src/plugins/platforms/cocoa/qcocoawindow.mm12
1 files changed, 10 insertions, 2 deletions
diff --git a/src/plugins/platforms/cocoa/qcocoawindow.mm b/src/plugins/platforms/cocoa/qcocoawindow.mm
index 34e60e938f..e93592879d 100644
--- a/src/plugins/platforms/cocoa/qcocoawindow.mm
+++ b/src/plugins/platforms/cocoa/qcocoawindow.mm
@@ -172,10 +172,18 @@ void QCocoaWindow::initialize()
if (!m_view)
m_view = [[QNSView alloc] initWithCocoaWindow:this];
- setGeometry(initialGeometry(window(), windowGeometry(), defaultWindowWidth, defaultWindowHeight));
+ // Compute the initial geometry based on the geometry set on the
+ // QWindow. This geometry has already been reflected to the
+ // QPlatformWindow in the constructor, so to ensure that the
+ // resulting setGeometry call does not think the geometry has
+ // already been applied, we reset the QPlatformWindow's view
+ // of the geometry first.
+ auto initialGeometry = QPlatformWindow::initialGeometry(window(),
+ windowGeometry(), defaultWindowWidth, defaultWindowHeight);
+ QPlatformWindow::d_ptr->rect = QRect();
+ setGeometry(initialGeometry);
recreateWindowIfNeeded();
- window()->setGeometry(geometry());
m_initialized = true;
}