on xenial help sign in
application switching animation fixed
commite9630e05c02226546a80eedfd209bcafbf5d1477 authorMichael Zanetti <michael.zanetti@canonical.com> dateWed 18 Dec 2013, 14:47 (13 years ago) parentaefad3f
1 file changed+15−49
Stages/PhoneStage.qml+15−49
Stages/PhoneStage.qml+15−49
@@ -29,25 +29,13 @@ Item {
2929 target: ApplicationManager
3030
3131 onFocusRequested: {
32− print("******focus requested*********", appId, "currently focused:", priv.focusedAppId, priv.focusedScreenshot)
33− mainScreenshotImage.src = priv.focusedScreenshot;
34− mainScreenshotImage.visible = true;
35− mainScreenshotImage.anchors.leftMargin = 0;
36− priv.grantFocus(appId);
32+ priv.switchToApp(appId);
3733 }
3834
3935 onFocusedApplicationIdChanged: {
40− print("*** ApplicationManager.focusedAppId changed appId:", priv.focusedAppId, "shown:", root.shown)
41−
4236 if (ApplicationManager.focusedApplicationId.length > 0) {
4337 priv.applicationStarting = false;
4438 priv.secondApplicationStarting = false;
45−
46− // There is a new focused one
47− if (root.shown){
48− print("starting applicationSwitchingAnimation");
49− applicationSwitchingAnimation.start();
50− }
5139 }
5240 }
5341
@@ -74,10 +62,11 @@ Item {
7462 property bool applicationStarting: false
7563 property bool secondApplicationStarting: false
7664
65+ property string newFocusedAppId
66+
7767 onFocusedScreenshotChanged: {
7868 waitingForScreenshot = false;
7969 if (root.moving) {
80− print("*** moving app", ApplicationManager.focusedApplicationId, "setting screenshot to", ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).screenshot)
8170 mainScreenshotImage.anchors.leftMargin = 0;
8271 mainScreenshotImage.src = ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).screenshot;
8372 mainScreenshotImage.visible = true;
@@ -85,13 +74,13 @@ Item {
8574 }
8675
8776 function requestNewScreenshot() {
88− print("requesting new screenshot for", ApplicationManager.focusedApplicationId);
8977 waitingForScreenshot = true;
9078 ApplicationManager.updateScreenshot(ApplicationManager.focusedApplicationId);
9179 }
9280
93− function grantFocus(appId) {
94− grantFocusTimer.appId = appId;
81+ function switchToApp(appId) {
82+ priv.newFocusedAppId = appId;
83+ applicationSwitchingAnimation.start();
9584 grantFocusTimer.start();
9685 }
9786
@@ -99,12 +88,13 @@ Item {
9988
10089 Timer {
10190 id: grantFocusTimer
102− interval: 1
91+ // Delay the actual switch to be covered by the animation for sure.
92+ // 1) If we switch before starting the animation, the Mir event loop paints before the Qt event loop => flickering
93+ // 2) If we do the switch after the animation, the panel wouldn't fade in early enough.
94+ interval: UbuntuAnimation.SlowDuration / 4
10395 repeat: false
104− property string appId
10596 onTriggered: {
106− print("*** Calling AppManager.focusApplication(", appId, "). Image is visible:", mainScreenshotImage.visible)
107− ApplicationManager.focusApplication(appId);
97+ ApplicationManager.focusApplication(priv.newFocusedAppId);
10898 }
10999 }
110100
@@ -112,11 +102,14 @@ Item {
112102 id: applicationSwitchingAnimation
113103 // setup
114104 PropertyAction { target: mainScreenshotImage; property: "anchors.leftMargin"; value: 0 }
115− PropertyAction { target: fadeInScreenshotImage; property: "source"; value: priv.focusedScreenshot }
105+ PropertyAction { target: mainScreenshotImage; property: "src"; value: priv.focusedScreenshot }
106+ PropertyAction { target: mainScreenshotImage; property: "visible"; value: true }
107+ PropertyAction { target: fadeInScreenshotImage; property: "source"; value: ApplicationManager.findApplication(priv.newFocusedAppId).screenshot }
116108 PropertyAction { target: fadeInScreenshotImage; property: "visible"; value: true }
117109 PropertyAction { target: fadeInScreenshotImage; property: "opacity"; value: 0 }
118110 PropertyAction { target: fadeInScreenshotImage; property: "scale"; value: .8 }
119111
112+
120113 // The actual animation
121114 ParallelAnimation {
122115 UbuntuNumberAnimation { target: mainScreenshotImage; property: "anchors.leftMargin"; to: root.width; duration: UbuntuAnimation.SlowDuration }
@@ -142,7 +135,6 @@ Item {
142135 width: parent.width
143136 scale: .7
144137 visible: false
145−// Rectangle { anchors.fill: mainScreenshotImage; color: "green"; opacity: .5 }
146138 }
147139
148140 Rectangle {
@@ -159,31 +151,5 @@ Item {
159151 property string src
160152 source: src
161153 visible: false
162−
163− onVisibleChanged: {
164− print("------------------------ image visible", visible)
165− }
166−
167− onSrcChanged: {
168− print("*** Main image source changed", src, "visible:", visible)
169− }
170−
171− onStatusChanged: {
172− print("*** Main image status changed", status, source)
173− }
174− }
175−// Rectangle { anchors.fill: mainScreenshotImage; color: "blue"; opacity: .5 }
176−
177− Image {
178− anchors { top: parent.top; right: parent.right }
179− height: parent.height / 4
180− width: parent.width / 4
181− source: ApplicationManager.findApplication(priv.focusedAppId).screenshot
182− }
183− Image {
184− anchors { bottom: parent.bottom; right: parent.right }
185− height: parent.height / 4
186− width: parent.width / 4
187− source: mainScreenshotImage.src
188154 }
189155}