on xenial help sign in
Make some small changes to the greeter's session list
43fc49dJosh Arenson
qml/Greeter/LoginList.qml+1−1
@@ -35,7 +35,7 @@ StyledItem {
35 readonly property int cellHeight: units.gu(5)
35 readonly property int cellHeight: units.gu(5)
36 readonly property int highlightedHeight: highlightItem.height
36 readonly property int highlightedHeight: highlightItem.height
37 readonly property int moveDuration: UbuntuAnimation.FastDuration
37 readonly property int moveDuration: UbuntuAnimation.FastDuration
38− property string currentSession
38+ property string currentSession // Initially set by LightDM
39 readonly property string currentUser: userList.currentItem.username
39 readonly property string currentUser: userList.currentItem.username
40
40
41 signal responded(string response)
41 signal responded(string response)
qml/Greeter/SessionsList.qml+34−17
@@ -24,22 +24,24 @@ Item {
24 id: root
24 id: root
25 objectName: "sessionsList"
25 objectName: "sessionsList"
26
26
27− property string initiallySelectedSession
28 signal sessionSelected(string sessionKey)
27 signal sessionSelected(string sessionKey)
29 signal showLoginList()
28 signal showLoginList()
30
29
31− onInitiallySelectedSessionChanged: {
30+ // Sets the position of the background highlight
31+ function updateHighlight(session) {
32− sessionsList.currentIndex = getSelectedIndex();
32+ sessionsList.currentIndex = getIndexOfSession(session);
33− sessionsList.positionViewAtIndex(sessionsList.currentIndex, ListView.Contain);
33+ sessionsList.currentItem.initialSession = session;
34 }
34 }
35
35
36− function getSelectedIndex() {
36+ function getIndexOfSession(session) {
37 for (var i = 0; i < sessionsList.model.count; i++) {
37 for (var i = 0; i < sessionsList.model.count; i++) {
38− var key = sessionsList.model.get(i).key
38+ var key = sessionsList.model.get(i).key;
39− if (key === initiallySelectedSession) {
39+ if (key === session) {
40 return i;
40 return i;
41 }
41 }
42 }
42 }
43+
44+ return 0; // Just choose the first session
43 }
45 }
44
46
45 function currentKey() {
47 function currentKey() {
@@ -49,7 +51,8 @@ Item {
49 }
51 }
50
52
51 Keys.onEnterPressed: {
53 Keys.onEnterPressed: {
54+ sessionSelected(currentKey());
52− showLoginList(); // Session is already selected
55+ showLoginList();
53 event.accepted = true;
56 event.accepted = true;
54 }
57 }
55
58
@@ -59,6 +62,7 @@ Item {
59 }
62 }
60
63
61 Keys.onReturnPressed: {
64 Keys.onReturnPressed: {
65+ sessionSelected(currentKey());
62 showLoginList();
66 showLoginList();
63 event.accepted = true;
67 event.accepted = true;
64 }
68 }
@@ -66,20 +70,18 @@ Item {
66 Keys.onDownPressed: {
70 Keys.onDownPressed: {
67 if (sessionsList.currentIndex < sessionsList.model.count - 1)
71 if (sessionsList.currentIndex < sessionsList.model.count - 1)
68 sessionsList.currentIndex++;
72 sessionsList.currentIndex++;
69− sessionSelected(currentKey());
70 event.accepted = true;
73 event.accepted = true;
71 }
74 }
72
75
73 Keys.onUpPressed: {
76 Keys.onUpPressed: {
74 if (sessionsList.currentIndex > 0)
77 if (sessionsList.currentIndex > 0)
75 sessionsList.currentIndex--;
78 sessionsList.currentIndex--;
76− sessionSelected(currentKey());
77 event.accepted = true;
79 event.accepted = true;
78 }
80 }
79
81
80 LoginAreaContainer {
82 LoginAreaContainer {
81 readonly property real margins: sessionsList.anchors.margins
83 readonly property real margins: sessionsList.anchors.margins
82− readonly property real prefferedHeight: {
84+ readonly property real preferredHeight: {
83 if (sessionsList.currentItem) {
85 if (sessionsList.currentItem) {
84 return (sessionsList.currentItem.height *
86 return (sessionsList.currentItem.height *
85 (1 + sessionsList.model.count)) + 2 * margins
87 (1 + sessionsList.model.count)) + 2 * margins
@@ -88,7 +90,7 @@ Item {
88 }
90 }
89 }
91 }
90
92
91− height: prefferedHeight < parent.height ? prefferedHeight : parent.height - units.gu(4)
93+ height: preferredHeight < parent.height ? preferredHeight : parent.height - units.gu(4)
92 width: parent.width
94 width: parent.width
93
95
94 anchors {
96 anchors {
@@ -107,8 +109,8 @@ Item {
107 margins: units.gu(2)
109 margins: units.gu(2)
108 }
110 }
109
111
112+ clip: true
110− height: parent.height - headerItem.height
113+ height: parent.height - units.gu(2.5)
111−
112 boundsBehavior: Flickable.StopAtBounds
114 boundsBehavior: Flickable.StopAtBounds
113
115
114 model: LightDMService.sessions
116 model: LightDMService.sessions
@@ -135,14 +137,18 @@ Item {
135 }
137 }
136
138
137 headerPositioning: ListView.OverlayHeader
139 headerPositioning: ListView.OverlayHeader
140+
141+ // The highlighting is all self-managed, so account for that
138 highlightFollowsCurrentItem: false
142 highlightFollowsCurrentItem: false
143+ highlight: QtObject {}
139
144
140 delegate: ListItem {
145 delegate: ListItem {
141 id: delegate
146 id: delegate
142 objectName: "sessionDelegate" + index
147 objectName: "sessionDelegate" + index
143
148
144− divider.visible: false
149+ property string initialSession: ""
145
150
151+ divider.visible: false
146 visible: y > sessionsList.headerItem.y
152 visible: y > sessionsList.headerItem.y
147 + sessionsList.headerItem.height
153 + sessionsList.headerItem.height
148 - sessionsList.anchors.margins
154 - sessionsList.anchors.margins
@@ -156,6 +162,16 @@ Item {
156 }
162 }
157 }
163 }
158
164
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+
159 Rectangle {
175 Rectangle {
160 height: parent.height
176 height: parent.height
161 width: parent.width
177 width: parent.width
@@ -171,15 +187,16 @@ Item {
171 ListItemLayout {
187 ListItemLayout {
172 id: layout
188 id: layout
173
189
190+ readonly property color itemColor: theme.palette.normal.raisedText
174 SessionIcon {
191 SessionIcon {
175 id: sessionIcon
192 id: sessionIcon
176 source: icon_url
193 source: icon_url
177 SlotsLayout.position: SlotsLayout.Leading
194 SlotsLayout.position: SlotsLayout.Leading
178− color: theme.palette.normal.raisedSecondaryText
195+ color: parent.itemColor
179 }
196 }
180
197
181 title.text: display
198 title.text: display
182− title.color: theme.palette.normal.raisedText
199+ title.color: itemColor
183 }
200 }
184 }
201 }
185 }
202 }
qml/Greeter/WideView.qml+7−5
@@ -20,6 +20,8 @@ import "." 0.1
20
20
21FocusScope {
21FocusScope {
22 id: root
22 id: root
23+ objectName: "WideView"
24+
23 focus: true
25 focus: true
24
26
25 property alias background: coverPage.background
27 property alias background: coverPage.background
@@ -32,13 +34,13 @@ FocusScope {
32 property int delayMinutes // TODO
34 property int delayMinutes // TODO
33 property alias alphanumeric: loginList.alphanumeric
35 property alias alphanumeric: loginList.alphanumeric
34 property alias locked: loginList.locked
36 property alias locked: loginList.locked
35− property alias sessionToStart: loginList.currentSession
36 property alias waiting: loginList.waiting
37 property alias waiting: loginList.waiting
37 property var userModel // Set from outside
38 property var userModel // Set from outside
38
39
39 readonly property bool animating: coverPage.showAnimation.running || coverPage.hideAnimation.running
40 readonly property bool animating: coverPage.showAnimation.running || coverPage.hideAnimation.running
40 readonly property bool fullyShown: coverPage.showProgress === 1
41 readonly property bool fullyShown: coverPage.showProgress === 1
41 readonly property bool required: coverPage.required
42 readonly property bool required: coverPage.required
43+ readonly property alias sessionToStart: loginList.currentSession
42
44
43 // so that it can be replaced in tests with a mock object
45 // so that it can be replaced in tests with a mock object
44 property var inputMethod: Qt.inputMethod
46 property var inputMethod: Qt.inputMethod
@@ -144,6 +146,7 @@ FocusScope {
144
146
145 height: loginList.height
147 height: loginList.height
146 width: loginList.width
148 width: loginList.width
149+
147 anchors {
150 anchors {
148 left: parent.left
151 left: parent.left
149 leftMargin: Math.min(parent.width * 0.16, units.gu(20))
152 leftMargin: Math.min(parent.width * 0.16, units.gu(20))
@@ -153,10 +156,9 @@ FocusScope {
153 active: false
156 active: false
154
157
155 onLoaded: sessionChooserLoader.item.forceActiveFocus();
158 onLoaded: sessionChooserLoader.item.forceActiveFocus();
156− Binding {
159+ onActiveChanged: {
157− target: sessionChooserLoader.item
160+ if (!active) return;
158− property: "initiallySelectedSession"
159− value: loginList.currentSession
161+ item.updateHighlight(loginList.currentSession);
160 }
162 }
161
163
162 Connections {
164 Connections {
tests/qmltests/Greeter/tst_WideView.qml+2−1
@@ -426,7 +426,8 @@ StyledItem {
426 var sessionChooserButton = findChild(view, "sessionChooserButton");
426 var sessionChooserButton = findChild(view, "sessionChooserButton");
427 compare(sessionChooserButton.visible, true);
427 compare(sessionChooserButton.visible, true);
428
428
429+ var loginList = findChild(view, "loginList");
429− var session = String(view.sessionToStart).toLowerCase();
430+ var session = String(loginList.currentSession).toLowerCase();
430 var icon = String(sessionChooserButton.icon);
431 var icon = String(sessionChooserButton.icon);
431 compare(icon.indexOf(session) > -1, true);
432 compare(icon.indexOf(session) > -1, true);
432
433
tests/qmltests/tst_Shell.qml+23
@@ -794,6 +794,29 @@ Rectangle {
794 tryCompare(ApplicationManager, "focusedApplicationId", mainAppId);
794 tryCompare(ApplicationManager, "focusedApplicationId", mainAppId);
795 }
795 }
796
796
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+
797 function swipeAwayGreeter() {
820 function swipeAwayGreeter() {
798 var greeter = findChild(shell, "greeter");
821 var greeter = findChild(shell, "greeter");
799 tryCompare(greeter, "fullyShown", true);
822 tryCompare(greeter, "fullyShown", true);