iOS: Don't intersect window maximized/fullscreen size with nil UIWindow

When making a QWindow maximized or fullscreen we intersect its final
geometry with that of its UIWindow, as in the case of split-view or
floating windows on iOS the UIWindow size will be smaller than the
corresponding UIScreen.

However, after 76ebf51bc08f6af624a8540e7af88b9129b22ae1 we no longer
track UIWindows via UIScreen, and instead manage them as part of the
UIWindowScene. Unfortunately the default scene that iOS manages is
created and connected after returning from didFinishLaunching, which
means that during main() there is no UIWindow. Attempts at manually
connecting this session before main via activateSceneSessionForRequest
were not successful, as we don't support multiple window scenes (yet).

Intersecting the window geometry to this non-existent window during
setWindowState() would result in an initial 0x0 size for windows.
Which would normally be okey, because once we have a UIWindow we re-
apply the window state, resulting in new QWindow geometry.

However the initial 0x0 size can in some rare scenarios trigger
QWidgets into setting the Qt::WA_OutsideWSRange attribute on the
top level widget, and due to a possible bug in QWidgetWindow, this
attribute is not reset once the QWidgetWindow receives an updated
resize event.

As a workaround for the widget issue, and to restore the semantics
of receiving an initial valid size of the window, we skip the logic
of intersecting the geometry with the UIWindow if we don't have one
yet.

Note the for visionOS and iOS applications running on macOS we
rely solely on the UIWindow for geometry, which means that this
issue still exists in those environments as long as the underlying
widget issue is not fixed.

Fixes: QTBUG-129472
Change-Id: Id81c356446f6e69f8a1eda59272ac04f02cc005f
Reviewed-by: Doris Verria <doris.verria@qt.io>
(cherry picked from commit b78baf634c6c2b8165432bf1e22a96abb2016f42)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Tor Arne Vestbø 2024-10-04 17:16:55 +02:00 committed by Qt Cherry-pick Bot
parent e3594963f3
commit 5baa0d759b

View File

@ -282,10 +282,20 @@ void QIOSWindow::setWindowState(Qt::WindowStates state)
} }
#endif #endif
if (m_view.window) {
// On application startup, during main(), we don't have a UIWindow yet (because
// the UIWindowScene has not been connected yet), but once the scene has been
// connected and we have a UIWindow we can adjust the maximized/fullscreen size
// to account for split-view or floating window mode, where the UIWindow is
// smaller than the screen.
fullscreenGeometry = fullscreenGeometry.intersected(uiWindowBounds);
maximizedGeometry = maximizedGeometry.intersected(uiWindowBounds);
}
if (state & Qt::WindowFullScreen) if (state & Qt::WindowFullScreen)
applyGeometry(fullscreenGeometry.intersected(uiWindowBounds)); applyGeometry(fullscreenGeometry);
else else
applyGeometry(maximizedGeometry.intersected(uiWindowBounds)); applyGeometry(maximizedGeometry);
} }
} else { } else {
applyGeometry(m_normalGeometry); applyGeometry(m_normalGeometry);