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>
This commit is contained in:
Tor Arne Vestbø 2020-07-21 16:48:48 +02:00
parent a7723f8fa7
commit 8b60ebf93a

View File

@ -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;
}