on xenial help sign in
Show nothing if running app loses surface
f2281d6Daniel d'Andrada
qml/Stages/ApplicationWindow.qml+29−1
@@ -39,6 +39,9 @@ Item {
39 readonly property int applicationState: root.application ? root.application.state : -1
39 readonly property int applicationState: root.application ? root.application.state : -1
40 readonly property var promptSurfaces: root.application ? root.application.promptSurfaces : null
40 readonly property var promptSurfaces: root.application ? root.application.promptSurfaces : null
41
41
42+ // Whether the Application had a surface before but lost it.
43+ property bool hadSurface: false
44+
42 property bool needToTakeScreenshot:
45 property bool needToTakeScreenshot:
43 d.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
46 d.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
44 && d.applicationState === ApplicationInfo.Stopped
47 && d.applicationState === ApplicationInfo.Stopped
@@ -56,6 +59,7 @@ Item {
56 if (surface) {
59 if (surface) {
57 surfaceInitTimer.start();
60 surfaceInitTimer.start();
58 } else {
61 } else {
62+ hadSurface = true;
59 surfaceInitialized = false;
63 surfaceInitialized = false;
60 }
64 }
61 }
65 }
@@ -147,10 +151,17 @@ Item {
147 StateGroup {
151 StateGroup {
148 objectName: "applicationWindowStateGroup"
152 objectName: "applicationWindowStateGroup"
149 states: [
153 states: [
154+ State {
155+ name: "void"
156+ when:
157+ d.hadSurface && (!d.surface || !d.surfaceInitialized)
158+ &&
159+ screenshotImage.status !== Image.Ready
160+ },
150 State {
161 State {
151 name: "splashScreen"
162 name: "splashScreen"
152 when:
163 when:
153− (!d.surface || !d.surfaceInitialized)
164+ !d.hadSurface && (!d.surface || !d.surfaceInitialized)
154 &&
165 &&
155 screenshotImage.status !== Image.Ready
166 screenshotImage.status !== Image.Ready
156 },
167 },
@@ -225,6 +236,23 @@ Item {
225 PropertyAction { target: screenshotImage; property: "visible"; value: false }
236 PropertyAction { target: screenshotImage; property: "visible"; value: false }
226 PropertyAction { target: screenshotImage; property: "source"; value: "" }
237 PropertyAction { target: screenshotImage; property: "source"; value: "" }
227 }
238 }
239+ },
240+ Transition {
241+ from: "surface"; to: "void"
242+ SequentialAnimation {
243+ PropertyAction { target: surfaceContainer; property: "visible"; value: false }
244+ ScriptAction { script: { if (d.surface) { d.surface.release(); } } }
245+ }
246+ },
247+ Transition {
248+ from: "void"; to: "surface"
249+ SequentialAnimation {
250+ PropertyAction { target: surfaceContainer; property: "opacity"; value: 0.0 }
251+ PropertyAction { target: surfaceContainer; property: "visible"; value: true }
252+ UbuntuNumberAnimation { target: surfaceContainer; property: "opacity";
253+ from: 0.0; to: 1.0
254+ duration: UbuntuAnimation.BriskDuration }
255+ }
228 }
256 }
229 ]
257 ]
230 }
258 }
tests/qmltests/Stages/tst_ApplicationWindow.qml+11
@@ -331,5 +331,16 @@ Rectangle {
331 verify(fakeSurface.touchPressCount === 1);
331 verify(fakeSurface.touchPressCount === 1);
332 verify(fakeSurface.touchReleaseCount === 1);
332 verify(fakeSurface.touchReleaseCount === 1);
333 }
333 }
334+
335+ function test_showNothingOnSuddenSurfaceLoss() {
336+ surfaceCheckbox.checked = true;
337+ setApplicationState(appRunning);
338+ tryCompare(stateGroup, "state", "surface");
339+ waitUntilTransitionsEnd();
340+
341+ surfaceCheckbox.checked = false;
342+
343+ verify(stateGroup.state === "void");
344+ }
334 }
345 }
335}
346}