on xenial help sign in
[Stage] Make sure we only use saved states when appropriate

If the app is fullscreen at startup, we should not use saved state Example of why: if you open game that only requests fullscreen at Statup, this will automaticly be set to "restored state" since thats the default value of stateStorage, this will result in the app having the "restored state" as it will not make a fullscreen call after the app has started. If saved state is fullscreen, we should use app inital state Example of why: if you open browser with youtube video at fullscreen and close this app, it will be fullscreen next time you open the app. This fixes: https://github.com/ubports/ubuntu-touch/issues/1081 This fixes: https://github.com/ubports/unity8/issues/170

commitb76b31e68c91e7211c299d9ef1116253c87cc275 authorMarius Gripsgard <marius@ubports.com> dateSat 3 Aug 2019, 01:49 (7 years ago) parent1829fbf
3 files changed+51−1
qml/Stage/Stage.qml+20−1 tests/mocks/Unity/Application/ApplicationManager.cpp+13 tests/qmltests/Stage/tst_DesktopStage.qml+18
qml/Stage/Stage.qml+20−1
@@ -1021,6 +1021,25 @@ FocusScope {
10211021 onWindowReadyChanged: {
10221022 if (windowReady) {
10231023 var loadedMirState = WindowStateStorage.toMirState(windowStateSaver.loadedState);
1024+ var state = loadedMirState;
1025+
1026+ if (window.state == Mir.FullscreenState) {
1027+ // If the app is fullscreen at startup, we should not use saved state
1028+ // Example of why: if you open game that only requests fullscreen at
1029+ // Statup, this will automaticly be set to "restored state" since
1030+ // thats the default value of stateStorage, this will result in the app
1031+ // having the "restored state" as it will not make a fullscreen
1032+ // call after the app has started.
1033+ console.log("Inital window state is fullscreen, not using saved state.");
1034+ state = window.state;
1035+ } else if (loadedMirState == Mir.FullscreenState) {
1036+ // If saved state is fullscreen, we should use app inital state
1037+ // Example of why: if you open browser with youtube video at fullscreen
1038+ // and close this app, it will be fullscreen next time you open the app.
1039+ console.log("Saved window state is fullscreen, using inital window state");
1040+ state = window.state;
1041+ }
1042+
10241043 // need to apply the shell chrome policy on top the saved window state
10251044 var policy;
10261045 if (root.mode == "windowed") {
@@ -1028,7 +1047,7 @@ FocusScope {
10281047 } else {
10291048 policy = stagedFullscreenPolicy
10301049 }
1031− window.requestState(policy.applyPolicy(loadedMirState, surface.shellChrome));
1050+ window.requestState(policy.applyPolicy(state, surface.shellChrome));
10321051 }
10331052 }
10341053
tests/mocks/Unity/Application/ApplicationManager.cpp+13
@@ -355,6 +355,19 @@ void ApplicationManager::buildListOfAvailableApplications()
355355 application->setRotatesWindowContents(true);
356356 m_availableApplications.append(application);
357357
358+ application = new ApplicationInfo(this);
359+ application->setAppId("camera-app3");
360+ application->setName("Camera3");
361+ application->setScreenshotId("camera");
362+ application->setIconId("camera");
363+ application->setFullscreen(true);
364+ application->setSupportedOrientations(Qt::PortraitOrientation
365+ | Qt::LandscapeOrientation
366+ | Qt::InvertedPortraitOrientation
367+ | Qt::InvertedLandscapeOrientation);
368+ application->setRotatesWindowContents(true);
369+ m_availableApplications.append(application);
370+
358371 application = new ApplicationInfo(this);
359372 application->setAppId("gallery-app");
360373 application->setName("Gallery");
tests/qmltests/Stage/tst_DesktopStage.qml+18
@@ -1063,5 +1063,23 @@ Item {
10631063 verify(surfaceItem);
10641064 tryCompare(surfaceItem, "activeFocus", true);
10651065 }
1066+
1067+ function test_ignoreSavedStateIfInitalIsFullscreenAndLowChrome() {
1068+ WindowStateStorage.saveState("camera-app", WindowStateStorage.WindowStateNormal);
1069+ var appDelegate = startApplication("camera-app");
1070+ tryCompare(appDelegate, "state", "restored");
1071+ }
1072+
1073+ function test_ignoreSavedStateIfInitalIsFullscreen() {
1074+ WindowStateStorage.saveState("camera-app3", WindowStateStorage.WindowStateNormal);
1075+ var appDelegate = startApplication("camera-app3");
1076+ tryCompare(appDelegate, "state", "fullscreen");
1077+ }
1078+
1079+ function test_ignoreSavedFullscreen() {
1080+ WindowStateStorage.saveState("dialer-app", WindowStateStorage.WindowStateFullscreen);
1081+ var appDelegate = startApplication("dialer-app");
1082+ tryCompare(appDelegate, "state", "normal");
1083+ }
10661084 }
10671085}