From 8b60ebf93a4ca443a0c101ea72cb806a2b105f04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Tue, 21 Jul 2020 16:48:48 +0200 Subject: 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 --- src/plugins/platforms/cocoa/qcocoawindow.mm | 12 ++++++++++-- 1 file changed, 10 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 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; } -- cgit v1.2.3