on xenial help sign in
Merge pull request #417 from ubports/xenial_-_ghostwindowfix

Fix ghost window if application creates and destroys surface early in lifecycle

commit3981e796ac9d7b61a289de709a99bb9785573a6f authorNotKit <nekit1000@gmail.com> dateSun 17 Oct 2021, 20:21 (5 years ago) parent7b30fe3ff11a24
2 files changed+16−6
plugins/WindowManager/TopLevelWindowModel.cpp+4−3 qml/Stage/ApplicationWindow.qml+12−3
plugins/WindowManager/TopLevelWindowModel.cpp+4−3
@@ -317,10 +317,11 @@ void TopLevelWindowModel::onSurfaceDied(unityapi::MirSurfaceInterface *surface)
317317
318318 auto application = m_windowModel[i].application;
319319
320− // can't be starting if it already has a surface
321− Q_ASSERT(application->state() != unityapi::ApplicationInfoInterface::Starting);
320+ DEBUG_MSG << " application->name()=" << application->name()
321+ << " application->state()=" << application->state();
322322
323− if (application->state() == unityapi::ApplicationInfoInterface::Running) {
323+ if (application->state() == unityapi::ApplicationInfoInterface::Running
324+ || application->state() == unityapi::ApplicationInfoInterface::Starting) {
324325 m_windowModel[i].removeOnceSurfaceDestroyed = true;
325326 } else {
326327 // assume it got killed by the out-of-memory daemon.
qml/Stage/ApplicationWindow.qml+12−3
@@ -53,6 +53,7 @@ FocusScope {
5353 if (surface) {
5454 surfaceContainer.surface = surface;
5555 d.liveSurface = surface.live;
56+ d.surfaceSeenLive = d.liveSurface;
5657 d.hadSurface = false;
5758 surfaceInitTimer.start();
5859 } else {
@@ -70,7 +71,12 @@ FocusScope {
7071 property bool liveSurface: false;
7172 property var con: Connections {
7273 target: root.surface
73− onLiveChanged: d.liveSurface = root.surface.live
74+ onLiveChanged: {
75+ d.liveSurface = root.surface.live;
76+ if (d.liveSurface) {
77+ d.surfaceSeenLive = true;
78+ }
79+ }
7480 }
7581 // using liveSurface instead of root.surface.live because with the latter
7682 // this expression is not reevaluated when root.surface changes
@@ -101,6 +107,7 @@ FocusScope {
101107 // might show the UI accommodating due to surface resizes on startup.
102108 // Remove this when possible
103109 property bool surfaceInitialized: false
110+ property bool surfaceSeenLive: false
104111
105112 readonly property bool supportsSurfaceResize:
106113 application &&
@@ -251,6 +258,7 @@ FocusScope {
251258 name: "splashScreen"
252259 when:
253260 !d.hadSurface && (!root.surface || !d.surfaceInitialized)
261+ && (d.liveSurface || !d.surfaceSeenLive)
254262 &&
255263 screenshotImage.status !== Image.Ready
256264 },
@@ -283,8 +291,9 @@ FocusScope {
283291 when:
284292 // The surface died while the application is running. It must have been closed
285293 // by the shell or the application decided to destroy it by itself
286− root.surface && d.surfaceInitialized && !d.liveSurface
287− && d.applicationState === ApplicationInfoInterface.Running
294+ root.surface && (d.surfaceInitialized || d.surfaceSeenLive) && !d.liveSurface
295+ && (d.applicationState === ApplicationInfoInterface.Running
296+ || d.applicationState === ApplicationInfoInterface.Starting)
288297 }
289298 ]
290299