on xenial help sign in
Use a fake timer as suggested by Daniel instead of using a very big interval
2d30559Albert Astals Cid
qml/Launcher/Launcher.qml+18−19
@@ -51,9 +51,9 @@ Item {
51
51
52 onStateChanged: {
52 onStateChanged: {
53 if (state == "") {
53 if (state == "") {
54− dismissTimer.stop()
54+ panel.dismissTimer.stop()
55 } else {
55 } else {
56− dismissTimer.restart()
56+ panel.dismissTimer.restart()
57 }
57 }
58 }
58 }
59
59
@@ -96,21 +96,6 @@ Item {
96 property string mode: "teasing"
96 property string mode: "teasing"
97 }
97 }
98
98
99− Timer {
100− id: dismissTimer
101− objectName: "dismissTimer"
102− interval: 500
103− onTriggered: {
104− if (root.autohideEnabled) {
105− if (!panel.preventHiding) {
106− root.state = ""
107− } else {
108− dismissTimer.restart()
109− }
110− }
111− }
112− }
113−
114 // Because the animation on x is disabled while dragging
99 // Because the animation on x is disabled while dragging
115 // switching state directly in the drag handlers would not animate
100 // switching state directly in the drag handlers would not animate
116 // the completion of the hide/reveal gesture. Lets update the state
101 // the completion of the hide/reveal gesture. Lets update the state
@@ -238,6 +223,20 @@ Item {
238 visible: root.x > 0 || x > -width || dragArea.pressed
223 visible: root.x > 0 || x > -width || dragArea.pressed
239 model: LauncherModel
224 model: LauncherModel
240
225
226+ property var dismissTimer: Timer { interval: 500 }
227+ Connections {
228+ target: panel.dismissTimer
229+ onTriggered: {
230+ if (root.autohideEnabled) {
231+ if (!panel.preventHiding) {
232+ root.state = ""
233+ } else {
234+ panel.dismissTimer.restart()
235+ }
236+ }
237+ }
238+ }
239+
241 property bool animate: true
240 property bool animate: true
242
241
243 onApplicationSelected: {
242 onApplicationSelected: {
@@ -250,8 +249,8 @@ Item {
250 }
249 }
251
250
252 onPreventHidingChanged: {
251 onPreventHidingChanged: {
253− if (dismissTimer.running) {
252+ if (panel.dismissTimer.running) {
254− dismissTimer.restart();
253+ panel.dismissTimer.restart();
255 }
254 }
256 }
255 }
257
256
tests/qmltests/Launcher/tst_Launcher.qml+21−20
@@ -159,6 +159,18 @@ Item {
159 target: LauncherModel
159 target: LauncherModel
160 }
160 }
161
161
162+ Item {
163+ id: fakeDismissTimer
164+ property bool running: false
165+ signal triggered
166+
167+ function stop() {
168+ }
169+
170+ function restart() {
171+ }
172+ }
173+
162 UnityTestCase {
174 UnityTestCase {
163 id: testCase
175 id: testCase
164 name: "Launcher"
176 name: "Launcher"
@@ -177,6 +189,11 @@ Item {
177 launcherLoader.active = true;
189 launcherLoader.active = true;
178 }
190 }
179 function init() {
191 function init() {
192+ var panel = findChild(launcher, "launcherPanel");
193+ verify(!!panel);
194+
195+ panel.dismissTimer = fakeDismissTimer;
196+
180 // Make sure we don't start the test with the mouse hovering the launcher
197 // Make sure we don't start the test with the mouse hovering the launcher
181 mouseMove(root, root.width, root.height / 2);
198 mouseMove(root, root.width, root.height / 2);
182
199
@@ -216,11 +233,6 @@ Item {
216 }
233 }
217
234
218 function revealByEdgePush() {
235 function revealByEdgePush() {
219− // make the dismissTimer interval very big temporarily
220− var dismissTimer = findInvisibleChild(launcher, "dismissTimer");
221− var oldInterval = dismissTimer.interval;
222− dismissTimer.interval = 100000;
223−
224 // Place the mouse against the window/screen edge and push beyond the barrier threshold
236 // Place the mouse against the window/screen edge and push beyond the barrier threshold
225 mouseMove(root, 1, root.height / 2);
237 mouseMove(root, 1, root.height / 2);
226 launcher.pushEdge(EdgeBarrierSettings.pushThreshold * 1.1);
238 launcher.pushEdge(EdgeBarrierSettings.pushThreshold * 1.1);
@@ -231,15 +243,6 @@ Item {
231 // wait until it gets fully extended
243 // wait until it gets fully extended
232 tryCompare(panel, "x", 0);
244 tryCompare(panel, "x", 0);
233 tryCompare(launcher, "state", "visibleTemporary");
245 tryCompare(launcher, "state", "visibleTemporary");
234−
235− // move the mouse a bit, this should not be needed but without it
236− // the mouse areas do not realize their containsMouse have changed
237− // i've tested in real life without moving the mouse at all and it works
238− // so it seems to be a test-only issue
239− mouseMove(root, 2, root.height / 2);
240−
241− // now that the launcher is out, bring the interval back
242− dismissTimer.interval = oldInterval;
243 }
246 }
244
247
245 function waitUntilLauncherDisappears() {
248 function waitUntilLauncherDisappears() {
@@ -906,15 +909,13 @@ Item {
906 revealByEdgePush();
909 revealByEdgePush();
907 compare(launcher.state, "visibleTemporary");
910 compare(launcher.state, "visibleTemporary");
908
911
909− // wait three times the dismiss timer to check the launcher still shown
910− // because the mouse is still over the launcher
911− var dismissTimer = findInvisibleChild(launcher, "dismissTimer");
912− wait(dismissTimer.interval * 3);
913− compare(panel.x, 0);
914−
915 // Now move the mouse away and make sure it hides in less than a second
912 // Now move the mouse away and make sure it hides in less than a second
916 mouseMove(root, root.width, root.height / 2)
913 mouseMove(root, root.width, root.height / 2)
917
914
915+ // trigger the hide timer
916+ fakeDismissTimer.triggered();
917+ tryCompare(panel, "x", 0);
918+
918 tryCompare(launcher, "state", "", 1000, "Launcher didn't hide after moving mouse away from it");
919 tryCompare(launcher, "state", "", 1000, "Launcher didn't hide after moving mouse away from it");
919 waitUntilLauncherDisappears();
920 waitUntilLauncherDisappears();
920 }
921 }