on xenial help sign in
Drop greeterWrapper and instead add a launcherOffset property to the Greeter object
commit16a8ab4ebd55e9f44f16fed3cafcddad3dfc12d9 authorMichael Terry <michael.terry@canonical.com> dateFri 28 Nov 2014, 13:13 (12 years ago) parent7f18c1d
3 files changed+98−89
qml/Greeter/Greeter.qml+32−9 qml/Shell.qml+64−78 tests/qmltests/tst_TabletShell.qml+2−2
qml/Greeter/Greeter.qml+32−9
@@ -25,13 +25,18 @@ Showable {
2525 enabled: shown
2626 created: greeterContentLoader.status == Loader.Ready && greeterContentLoader.item.ready
2727
28+ x: launcherOffsetProxy + dragOffset
29+
2830 property url background
2931 property bool loadContent: required
3032
33+ // How far to offset the top greeter layer during a launcher left-drag
34+ property real launcherOffset
35+
3136 // 1 when fully shown and 0 when fully hidden
3237 property real showProgress: MathUtils.clamp((width - Math.abs(x)) / width, 0, 1)
3338
34− showAnimation: StandardAnimation { property: "x"; to: 0; duration: UbuntuAnimation.FastDuration }
39+ showAnimation: StandardAnimation { property: "dragOffset"; to: 0; duration: UbuntuAnimation.FastDuration }
3540 hideAnimation: __leftHideAnimation
3641
3742 property alias dragHandleWidth: dragHandle.width
@@ -43,8 +48,26 @@ Showable {
4348
4449 readonly property int currentIndex: greeterContentLoader.currentIndex
4550
46− property var __leftHideAnimation: StandardAnimation { property: "x"; to: -width }
47− property var __rightHideAnimation: StandardAnimation { property: "x"; to: width }
51+ property var __leftHideAnimation: StandardAnimation { property: "dragOffset"; to: -width }
52+ property var __rightHideAnimation: StandardAnimation { property: "dragOffset"; to: width }
53+
54+ property real dragOffset
55+
56+ // We define a proxy and "is valid" property for launcherOffset because of
57+ // a quirk in Qml. We only want this animation to fire if we are reset
58+ // back to zero (on a release of the drag). But by defining a Behavior,
59+ // we delay the property from reaching zero until it's too late. So we set
60+ // a proxy bound to launcherOffset, which lets us see the target value of
61+ // zero as we also slowly adjust the value down to zero. But Qml will send
62+ // change notifications in declaration order. So unless we define the
63+ // proxy first, we need a little "is valid" property defined above the
64+ // proxy, so we know when to enable the proxy behavior. Phew!
65+ readonly property bool launcherOffsetValid: launcherOffset > 0
66+ property real launcherOffsetProxy: launcherOffset
67+ Behavior on launcherOffsetProxy {
68+ enabled: !launcherOffsetValid
69+ StandardAnimation {}
70+ }
4871
4972 signal selected(int uid)
5073 signal unlocked(int uid)
@@ -110,9 +133,9 @@ Showable {
110133 onPressAndHold: {} // eat event, but no need to tease, as drag will cover it
111134
112135 onDragEnd: {
113− if (greeter.x > 0 && rightEvaluator.shouldAutoComplete()) {
136+ if (greeter.dragOffset > 0 && rightEvaluator.shouldAutoComplete()) {
114137 greeter.hideRight()
115− } else if (greeter.x < 0 && leftEvaluator.shouldAutoComplete()) {
138+ } else if (greeter.dragOffset < 0 && leftEvaluator.shouldAutoComplete()) {
116139 greeter.hide();
117140 } else {
118141 greeter.show(); // undo drag
@@ -120,20 +143,20 @@ Showable {
120143 }
121144
122145 onDragValueChanged: {
123− // dragValue is kept as a "step" value since we do this x adjusting on the fly
124− greeter.x += dragValue
146+ // dragValue is kept as a "step" value since we do this adjusting on the fly
147+ greeter.dragOffset += dragValue;
125148 }
126149
127150 EdgeDragEvaluator {
128151 id: rightEvaluator
129− trackedPosition: dragHandle.dragValue + greeter.x
152+ trackedPosition: dragHandle.dragValue + greeter.dragOffset
130153 maxDragDistance: parent.width
131154 direction: Direction.Rightwards
132155 }
133156
134157 EdgeDragEvaluator {
135158 id: leftEvaluator
136− trackedPosition: dragHandle.dragValue + greeter.x
159+ trackedPosition: dragHandle.dragValue + greeter.dragOffset
137160 maxDragDistance: parent.width
138161 direction: Direction.Leftwards
139162 }
qml/Shell.qml+64−78
@@ -493,118 +493,104 @@ Item {
493493 Rectangle {
494494 anchors.fill: parent
495495 color: "black"
496− opacity: greeterWrapper.showProgress * 0.8
496+ opacity: greeter.showProgress * 0.8
497497 }
498498
499− Item {
500− // Just a tiny wrapper to adjust greeter's x without messing with its own dragging
501− id: greeterWrapper
502− objectName: "greeterWrapper"
503− x: greeter.narrowMode ? launcher.progress : 0
499+ Greeter {
500+ id: greeter
501+ objectName: "greeter"
502+
503+ property string lockedApp: ""
504+ property bool hasLockedApp: lockedApp !== ""
505+
506+ available: true
507+ hides: [launcher, panel.indicators]
508+ shown: true
509+ loadContent: required || lockscreen.required // keeps content in memory for quick show()
510+ launcherOffset: narrowMode ? launcher.progress : 0
511+
512+ locked: shell.locked
513+
514+ background: shell.background
515+
504516 y: panel.panelHeight
505517 width: parent.width
506518 height: parent.height - panel.panelHeight
507519
508− Behavior on x {
509− enabled: !launcher.dashSwipe
510− StandardAnimation {}
511− }
520+ dragHandleWidth: shell.edgeSize
512521
513522 property bool fullyShown: showProgress === 1.0
514523 onFullyShownChanged: {
515524 // Wait until the greeter is completely covering lockscreen before resetting it.
516− if (greeter.narrowMode && fullyShown && !LightDM.Greeter.authenticated) {
525+ if (narrowMode && fullyShown && !LightDM.Greeter.authenticated) {
517526 lockscreen.reset();
518527 lockscreen.maybeShow();
519528 }
520529 }
521530
522− readonly property real showProgress: MathUtils.clamp((1 - x/width) + greeter.showProgress - 1, 0, 1)
523531 onShowProgressChanged: {
524532 if (showProgress === 0) {
525533 if ((LightDM.Greeter.promptless && LightDM.Greeter.authenticated) || shell.forcedUnlock) {
526534 greeter.login()
527− } else if (greeter.narrowMode) {
535+ } else if (narrowMode) {
528536 lockscreen.clear(false) // to reset focus if necessary
529537 }
530538 }
531539 }
532540
533− Greeter {
534− id: greeter
535− objectName: "greeter"
536−
537− property string lockedApp: ""
538− property bool hasLockedApp: lockedApp !== ""
539−
540− available: true
541− hides: [launcher, panel.indicators]
542− shown: true
543− loadContent: required || lockscreen.required // keeps content in memory for quick show()
544−
545− locked: shell.locked
546−
547− background: shell.background
548−
549− width: parent.width
550− height: parent.height
551−
552− dragHandleWidth: shell.edgeSize
553−
554− onSessionStarted: {
555− hide();
556− lockscreen.hide();
557− launcher.hide();
558− }
541+ onSessionStarted: {
542+ hide();
543+ lockscreen.hide();
544+ launcher.hide();
545+ }
559546
560− function startUnlock() {
561− if (narrowMode) {
562− if (!LightDM.Greeter.authenticated) {
563− lockscreen.maybeShow()
564− }
565− hide()
566− } else {
567− show()
568− tryToUnlock()
547+ function startUnlock() {
548+ if (narrowMode) {
549+ if (!LightDM.Greeter.authenticated) {
550+ lockscreen.maybeShow()
569551 }
552+ hide()
553+ } else {
554+ show()
555+ tryToUnlock()
570556 }
557+ }
571558
572− onShownChanged: {
573− if (shown) {
574− // Disable everything so that user can't swipe greeter or
575− // launcher until we get first prompt/authenticate, which
576− // will re-enable the shell.
577− shell.enabled = false;
578−
579− if (greeter.narrowMode) {
580− LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
581− } else {
582− reset()
583− }
584− greeter.lockedApp = "";
585− greeter.forceActiveFocus();
559+ onShownChanged: {
560+ if (shown) {
561+ // Disable everything so that user can't swipe greeter or
562+ // launcher until we get first prompt/authenticate, which
563+ // will re-enable the shell.
564+ shell.enabled = false;
565+
566+ if (greeter.narrowMode) {
567+ LightDM.Greeter.authenticate(LightDM.Users.data(0, LightDM.UserRoles.NameRole));
568+ } else {
569+ reset()
586570 }
571+ greeter.lockedApp = "";
572+ greeter.forceActiveFocus();
587573 }
574+ }
588575
589− Component.onCompleted: {
590− Connectivity.unlockAllModems()
591− }
576+ Component.onCompleted: {
577+ Connectivity.unlockAllModems()
578+ }
592579
593− onUnlocked: greeter.hide()
594− onSelected: {
595− // Update launcher items for new user
596− var user = LightDM.Users.data(uid, LightDM.UserRoles.NameRole);
597− AccountsService.user = user;
598− LauncherModel.setUser(user);
599− }
580+ onUnlocked: greeter.hide()
581+ onSelected: {
582+ // Update launcher items for new user
583+ var user = LightDM.Users.data(uid, LightDM.UserRoles.NameRole);
584+ AccountsService.user = user;
585+ LauncherModel.setUser(user);
586+ }
600587
601− onTease: launcher.tease()
588+ onTease: launcher.tease()
602589
603− Binding {
604− target: ApplicationManager
605− property: "suspended"
606− value: (greeter.shown && greeterWrapper.showProgress == 1) || lockscreen.shown
607− }
590+ Binding {
591+ target: ApplicationManager
592+ property: "suspended"
593+ value: (greeter.shown && greeter.showProgress == 1) || lockscreen.shown
608594 }
609595 }
610596
tests/qmltests/tst_TabletShell.qml+2−2
@@ -211,8 +211,8 @@ Row {
211211 }
212212
213213 function confirmLoggedIn(loggedIn) {
214− var greeterWrapper = findChild(shell, "greeterWrapper")
215− tryCompare(greeterWrapper, "showProgress", loggedIn ? 0 : 1)
214+ var greeter = findChild(shell, "greeter");
215+ tryCompare(greeter, "showProgress", loggedIn ? 0 : 1);
216216 tryCompare(sessionSpy, "count", loggedIn ? 1 : 0)
217217 }
218218