on xenial help sign in
Show nothing if running app loses surface
commitf2281d65346c9e5a27723116cad03f989b054b2c authorDaniel d'Andrada <daniel.dandrada@canonical.com> dateTue 19 Aug 2014, 10:15 (12 years ago) parentcf5ebf5
2 files changed+40−1
qml/Stages/ApplicationWindow.qml+29−1 tests/qmltests/Stages/tst_ApplicationWindow.qml+11
qml/Stages/ApplicationWindow.qml+29−1
@@ -39,6 +39,9 @@ Item {
3939 readonly property int applicationState: root.application ? root.application.state : -1
4040 readonly property var promptSurfaces: root.application ? root.application.promptSurfaces : null
4141
42+ // Whether the Application had a surface before but lost it.
43+ property bool hadSurface: false
44+
4245 property bool needToTakeScreenshot:
4346 d.surface && d.surfaceInitialized && screenshotImage.status === Image.Null
4447 && d.applicationState === ApplicationInfo.Stopped
@@ -56,6 +59,7 @@ Item {
5659 if (surface) {
5760 surfaceInitTimer.start();
5861 } else {
62+ hadSurface = true;
5963 surfaceInitialized = false;
6064 }
6165 }
@@ -147,10 +151,17 @@ Item {
147151 StateGroup {
148152 objectName: "applicationWindowStateGroup"
149153 states: [
154+ State {
155+ name: "void"
156+ when:
157+ d.hadSurface && (!d.surface || !d.surfaceInitialized)
158+ &&
159+ screenshotImage.status !== Image.Ready
160+ },
150161 State {
151162 name: "splashScreen"
152163 when:
153− (!d.surface || !d.surfaceInitialized)
164+ !d.hadSurface && (!d.surface || !d.surfaceInitialized)
154165 &&
155166 screenshotImage.status !== Image.Ready
156167 },
@@ -225,6 +236,23 @@ Item {
225236 PropertyAction { target: screenshotImage; property: "visible"; value: false }
226237 PropertyAction { target: screenshotImage; property: "source"; value: "" }
227238 }
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+ }
228256 }
229257 ]
230258 }
tests/qmltests/Stages/tst_ApplicationWindow.qml+11
@@ -331,5 +331,16 @@ Rectangle {
331331 verify(fakeSurface.touchPressCount === 1);
332332 verify(fakeSurface.touchReleaseCount === 1);
333333 }
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+ }
334345 }
335346}