on xenial help sign in
application switching animation fixed
e9630e0Michael Zanetti
Stages/PhoneStage.qml+15−49
@@ -29,25 +29,13 @@ Item {
29 target: ApplicationManager
29 target: ApplicationManager
30
30
31 onFocusRequested: {
31 onFocusRequested: {
32− print("******focus requested*********", appId, "currently focused:", priv.focusedAppId, priv.focusedScreenshot)
32+ priv.switchToApp(appId);
33− mainScreenshotImage.src = priv.focusedScreenshot;
34− mainScreenshotImage.visible = true;
35− mainScreenshotImage.anchors.leftMargin = 0;
36− priv.grantFocus(appId);
37 }
33 }
38
34
39 onFocusedApplicationIdChanged: {
35 onFocusedApplicationIdChanged: {
40− print("*** ApplicationManager.focusedAppId changed appId:", priv.focusedAppId, "shown:", root.shown)
41−
42 if (ApplicationManager.focusedApplicationId.length > 0) {
36 if (ApplicationManager.focusedApplicationId.length > 0) {
43 priv.applicationStarting = false;
37 priv.applicationStarting = false;
44 priv.secondApplicationStarting = false;
38 priv.secondApplicationStarting = false;
45−
46− // There is a new focused one
47− if (root.shown){
48− print("starting applicationSwitchingAnimation");
49− applicationSwitchingAnimation.start();
50− }
51 }
39 }
52 }
40 }
53
41
@@ -74,10 +62,11 @@ Item {
74 property bool applicationStarting: false
62 property bool applicationStarting: false
75 property bool secondApplicationStarting: false
63 property bool secondApplicationStarting: false
76
64
65+ property string newFocusedAppId
66+
77 onFocusedScreenshotChanged: {
67 onFocusedScreenshotChanged: {
78 waitingForScreenshot = false;
68 waitingForScreenshot = false;
79 if (root.moving) {
69 if (root.moving) {
80− print("*** moving app", ApplicationManager.focusedApplicationId, "setting screenshot to", ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).screenshot)
81 mainScreenshotImage.anchors.leftMargin = 0;
70 mainScreenshotImage.anchors.leftMargin = 0;
82 mainScreenshotImage.src = ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).screenshot;
71 mainScreenshotImage.src = ApplicationManager.findApplication(ApplicationManager.focusedApplicationId).screenshot;
83 mainScreenshotImage.visible = true;
72 mainScreenshotImage.visible = true;
@@ -85,13 +74,13 @@ Item {
85 }
74 }
86
75
87 function requestNewScreenshot() {
76 function requestNewScreenshot() {
88− print("requesting new screenshot for", ApplicationManager.focusedApplicationId);
89 waitingForScreenshot = true;
77 waitingForScreenshot = true;
90 ApplicationManager.updateScreenshot(ApplicationManager.focusedApplicationId);
78 ApplicationManager.updateScreenshot(ApplicationManager.focusedApplicationId);
91 }
79 }
92
80
93− function grantFocus(appId) {
81+ function switchToApp(appId) {
94− grantFocusTimer.appId = appId;
82+ priv.newFocusedAppId = appId;
83+ applicationSwitchingAnimation.start();
95 grantFocusTimer.start();
84 grantFocusTimer.start();
96 }
85 }
97
86
@@ -99,12 +88,13 @@ Item {
99
88
100 Timer {
89 Timer {
101 id: grantFocusTimer
90 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
103 repeat: false
95 repeat: false
104− property string appId
105 onTriggered: {
96 onTriggered: {
106− print("*** Calling AppManager.focusApplication(", appId, "). Image is visible:", mainScreenshotImage.visible)
107− ApplicationManager.focusApplication(appId);
97+ ApplicationManager.focusApplication(priv.newFocusedAppId);
108 }
98 }
109 }
99 }
110
100
@@ -112,11 +102,14 @@ Item {
112 id: applicationSwitchingAnimation
102 id: applicationSwitchingAnimation
113 // setup
103 // setup
114 PropertyAction { target: mainScreenshotImage; property: "anchors.leftMargin"; value: 0 }
104 PropertyAction { target: mainScreenshotImage; property: "anchors.leftMargin"; value: 0 }
105+ PropertyAction { target: mainScreenshotImage; property: "src"; value: priv.focusedScreenshot }
106+ PropertyAction { target: mainScreenshotImage; property: "visible"; value: true }
115− PropertyAction { target: fadeInScreenshotImage; property: "source"; value: priv.focusedScreenshot }
107+ PropertyAction { target: fadeInScreenshotImage; property: "source"; value: ApplicationManager.findApplication(priv.newFocusedAppId).screenshot }
116 PropertyAction { target: fadeInScreenshotImage; property: "visible"; value: true }
108 PropertyAction { target: fadeInScreenshotImage; property: "visible"; value: true }
117 PropertyAction { target: fadeInScreenshotImage; property: "opacity"; value: 0 }
109 PropertyAction { target: fadeInScreenshotImage; property: "opacity"; value: 0 }
118 PropertyAction { target: fadeInScreenshotImage; property: "scale"; value: .8 }
110 PropertyAction { target: fadeInScreenshotImage; property: "scale"; value: .8 }
119
111
112+
120 // The actual animation
113 // The actual animation
121 ParallelAnimation {
114 ParallelAnimation {
122 UbuntuNumberAnimation { target: mainScreenshotImage; property: "anchors.leftMargin"; to: root.width; duration: UbuntuAnimation.SlowDuration }
115 UbuntuNumberAnimation { target: mainScreenshotImage; property: "anchors.leftMargin"; to: root.width; duration: UbuntuAnimation.SlowDuration }
@@ -142,7 +135,6 @@ Item {
142 width: parent.width
135 width: parent.width
143 scale: .7
136 scale: .7
144 visible: false
137 visible: false
145−// Rectangle { anchors.fill: mainScreenshotImage; color: "green"; opacity: .5 }
146 }
138 }
147
139
148 Rectangle {
140 Rectangle {
@@ -159,31 +151,5 @@ Item {
159 property string src
151 property string src
160 source: src
152 source: src
161 visible: false
153 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
188 }
154 }
189}
155}