on xenial help sign in
Make some small changes to the greeter's session list

Approved by: Michał Sawicz, Unity8 CI Bot

commit43fc49ddef7a5b7b80badc6396735567a14cbcbb authorJosh Arenson <joshua.arenson@canonical.com> dateTue 4 Apr 2017, 22:52 (10 years ago) parent001b3181851573
5 files changed+67−24
qml/Greeter/LoginList.qml+1−1 qml/Greeter/SessionsList.qml+34−17 qml/Greeter/WideView.qml+7−5 tests/qmltests/Greeter/tst_WideView.qml+2−1 tests/qmltests/tst_Shell.qml+23
qml/Greeter/LoginList.qml+1−1
@@ -35,7 +35,7 @@ StyledItem {
3535 readonly property int cellHeight: units.gu(5)
3636 readonly property int highlightedHeight: highlightItem.height
3737 readonly property int moveDuration: UbuntuAnimation.FastDuration
38− property string currentSession
38+ property string currentSession // Initially set by LightDM
3939 readonly property string currentUser: userList.currentItem.username
4040
4141 signal responded(string response)
qml/Greeter/SessionsList.qml+34−17
@@ -24,22 +24,24 @@ Item {
2424 id: root
2525 objectName: "sessionsList"
2626
27− property string initiallySelectedSession
2827 signal sessionSelected(string sessionKey)
2928 signal showLoginList()
3029
31− onInitiallySelectedSessionChanged: {
32− sessionsList.currentIndex = getSelectedIndex();
33− sessionsList.positionViewAtIndex(sessionsList.currentIndex, ListView.Contain);
30+ // Sets the position of the background highlight
31+ function updateHighlight(session) {
32+ sessionsList.currentIndex = getIndexOfSession(session);
33+ sessionsList.currentItem.initialSession = session;
3434 }
3535
36− function getSelectedIndex() {
36+ function getIndexOfSession(session) {
3737 for (var i = 0; i < sessionsList.model.count; i++) {
38− var key = sessionsList.model.get(i).key
39− if (key === initiallySelectedSession) {
38+ var key = sessionsList.model.get(i).key;
39+ if (key === session) {
4040 return i;
4141 }
4242 }
43+
44+ return 0; // Just choose the first session
4345 }
4446
4547 function currentKey() {
@@ -49,7 +51,8 @@ Item {
4951 }
5052
5153 Keys.onEnterPressed: {
52− showLoginList(); // Session is already selected
54+ sessionSelected(currentKey());
55+ showLoginList();
5356 event.accepted = true;
5457 }
5558
@@ -59,6 +62,7 @@ Item {
5962 }
6063
6164 Keys.onReturnPressed: {
65+ sessionSelected(currentKey());
6266 showLoginList();
6367 event.accepted = true;
6468 }
@@ -66,20 +70,18 @@ Item {
6670 Keys.onDownPressed: {
6771 if (sessionsList.currentIndex < sessionsList.model.count - 1)
6872 sessionsList.currentIndex++;
69− sessionSelected(currentKey());
7073 event.accepted = true;
7174 }
7275
7376 Keys.onUpPressed: {
7477 if (sessionsList.currentIndex > 0)
7578 sessionsList.currentIndex--;
76− sessionSelected(currentKey());
7779 event.accepted = true;
7880 }
7981
8082 LoginAreaContainer {
8183 readonly property real margins: sessionsList.anchors.margins
82− readonly property real prefferedHeight: {
84+ readonly property real preferredHeight: {
8385 if (sessionsList.currentItem) {
8486 return (sessionsList.currentItem.height *
8587 (1 + sessionsList.model.count)) + 2 * margins
@@ -88,7 +90,7 @@ Item {
8890 }
8991 }
9092
91− height: prefferedHeight < parent.height ? prefferedHeight : parent.height - units.gu(4)
93+ height: preferredHeight < parent.height ? preferredHeight : parent.height - units.gu(4)
9294 width: parent.width
9395
9496 anchors {
@@ -107,8 +109,8 @@ Item {
107109 margins: units.gu(2)
108110 }
109111
110− height: parent.height - headerItem.height
111−
112+ clip: true
113+ height: parent.height - units.gu(2.5)
112114 boundsBehavior: Flickable.StopAtBounds
113115
114116 model: LightDMService.sessions
@@ -135,14 +137,18 @@ Item {
135137 }
136138
137139 headerPositioning: ListView.OverlayHeader
140+
141+ // The highlighting is all self-managed, so account for that
138142 highlightFollowsCurrentItem: false
143+ highlight: QtObject {}
139144
140145 delegate: ListItem {
141146 id: delegate
142147 objectName: "sessionDelegate" + index
143148
144− divider.visible: false
149+ property string initialSession: ""
145150
151+ divider.visible: false
146152 visible: y > sessionsList.headerItem.y
147153 + sessionsList.headerItem.height
148154 - sessionsList.anchors.margins
@@ -156,6 +162,16 @@ Item {
156162 }
157163 }
158164
165+ Rectangle {
166+ id: backgroundHighlight
167+
168+ height: sessionsList.currentItem.height
169+ width: sessionsList.currentItem.width
170+ color: theme.palette.normal.selection
171+
172+ visible: initialSession === key && !!key
173+ }
174+
159175 Rectangle {
160176 height: parent.height
161177 width: parent.width
@@ -171,15 +187,16 @@ Item {
171187 ListItemLayout {
172188 id: layout
173189
190+ readonly property color itemColor: theme.palette.normal.raisedText
174191 SessionIcon {
175192 id: sessionIcon
176193 source: icon_url
177194 SlotsLayout.position: SlotsLayout.Leading
178− color: theme.palette.normal.raisedSecondaryText
195+ color: parent.itemColor
179196 }
180197
181198 title.text: display
182− title.color: theme.palette.normal.raisedText
199+ title.color: itemColor
183200 }
184201 }
185202 }
qml/Greeter/WideView.qml+7−5
@@ -20,6 +20,8 @@ import "." 0.1
2020
2121FocusScope {
2222 id: root
23+ objectName: "WideView"
24+
2325 focus: true
2426
2527 property alias background: coverPage.background
@@ -32,13 +34,13 @@ FocusScope {
3234 property int delayMinutes // TODO
3335 property alias alphanumeric: loginList.alphanumeric
3436 property alias locked: loginList.locked
35− property alias sessionToStart: loginList.currentSession
3637 property alias waiting: loginList.waiting
3738 property var userModel // Set from outside
3839
3940 readonly property bool animating: coverPage.showAnimation.running || coverPage.hideAnimation.running
4041 readonly property bool fullyShown: coverPage.showProgress === 1
4142 readonly property bool required: coverPage.required
43+ readonly property alias sessionToStart: loginList.currentSession
4244
4345 // so that it can be replaced in tests with a mock object
4446 property var inputMethod: Qt.inputMethod
@@ -144,6 +146,7 @@ FocusScope {
144146
145147 height: loginList.height
146148 width: loginList.width
149+
147150 anchors {
148151 left: parent.left
149152 leftMargin: Math.min(parent.width * 0.16, units.gu(20))
@@ -153,10 +156,9 @@ FocusScope {
153156 active: false
154157
155158 onLoaded: sessionChooserLoader.item.forceActiveFocus();
156− Binding {
157− target: sessionChooserLoader.item
158− property: "initiallySelectedSession"
159− value: loginList.currentSession
159+ onActiveChanged: {
160+ if (!active) return;
161+ item.updateHighlight(loginList.currentSession);
160162 }
161163
162164 Connections {
tests/qmltests/Greeter/tst_WideView.qml+2−1
@@ -426,7 +426,8 @@ StyledItem {
426426 var sessionChooserButton = findChild(view, "sessionChooserButton");
427427 compare(sessionChooserButton.visible, true);
428428
429− var session = String(view.sessionToStart).toLowerCase();
429+ var loginList = findChild(view, "loginList");
430+ var session = String(loginList.currentSession).toLowerCase();
430431 var icon = String(sessionChooserButton.icon);
431432 compare(icon.indexOf(session) > -1, true);
432433
tests/qmltests/tst_Shell.qml+23
@@ -794,6 +794,29 @@ Rectangle {
794794 tryCompare(ApplicationManager, "focusedApplicationId", mainAppId);
795795 }
796796
797+ function test_greeterStartsCorrectSession() {
798+ loadShell("desktop");
799+ setLightDMMockMode("full");
800+
801+ LightDMController.sessionMode = "full"
802+ LightDMController.numSessions = LightDMController.numAvailableSessions;
803+ var greeter = findChild(shell, "greeter");
804+ var view = findChild(greeter, "WideView");
805+ verify(view, "This test requires WideView to be loaded");
806+
807+ var loginList = findChild(view, "loginList");
808+
809+ compare(view.sessionToStart, greeter.sessionToStart());
810+
811+ // Ensure another session can actually be selected
812+ compare(LightDMController.numSessions > 1, true);
813+ loginList.currentSession = LightDM.Sessions.data(1, LightDM.SessionRoles.KeyRole);
814+
815+ compare(view.sessionToStart, greeter.sessionToStart());
816+
817+ }
818+
819+
797820 function swipeAwayGreeter() {
798821 var greeter = findChild(shell, "greeter");
799822 tryCompare(greeter, "fullyShown", true);