on xenial help sign in
Enable the PIN lockscreen to be used with a HW keyboard Fixes: #1550359

Approved by: Unity8 CI Bot, Albert Astals Cid

commit8391b0accebdb0762151542362ab30fe7bf8660a authorLukáš Tinkl <lukas.tinkl@canonical.com> dateThu 10 Mar 2016, 22:42 (11 years ago) parentb89fa9410eba0f
5 files changed+133−106
qml/Components/Lockscreen.qml+80−94 qml/Components/PassphraseLockscreen.qml+5−4 qml/Components/PinLockscreen.qml+22−1 qml/Greeter/NarrowView.qml+12 tests/qmltests/Components/tst_Lockscreen.qml+14−7
qml/Components/Lockscreen.qml+80−94
@@ -121,108 +121,94 @@ Showable {
121121 opacity: root.darkenBackground
122122 }
123123
124− MouseArea {
125− anchors.fill: root
126− onClicked: {
127− if (pinPadLoader.item)
128− pinPadLoader.item.forceActiveFocus()
129− }
130− }
131−
132− FocusScope {
133− id: loaderScope
124+ Loader {
125+ id: pinPadLoader
126+ objectName: "pinPadLoader"
134127 anchors.fill: parent
135−
136− Loader {
137− id: pinPadLoader
138− objectName: "pinPadLoader"
139− anchors.fill: parent
140− property bool resetting: false
141− property bool waiting: false
142− property bool showWrongText: false
143−
144− source: {
145− if (resetting || !root.required) {
146− return ""
147− } else if (root.delayMinutes > 0) {
148− return "DelayedLockscreen.qml"
149− } else if (root.alphaNumeric) {
150− return "PassphraseLockscreen.qml"
151− } else {
152− return "PinLockscreen.qml"
153− }
154− }
155− onSourceChanged: {
156− waiting = false
157− showWrongText = false
158− if (loaderScope.activeFocus && pinPadLoader.item)
159− pinPadLoader.item.forceActiveFocus()
128+ property bool resetting: false
129+ property bool waiting: false
130+ property bool showWrongText: false
131+ focus: true
132+
133+ source: {
134+ if (resetting || !root.required) {
135+ return ""
136+ } else if (root.delayMinutes > 0) {
137+ return "DelayedLockscreen.qml"
138+ } else if (root.alphaNumeric) {
139+ return "PassphraseLockscreen.qml"
140+ } else {
141+ return "PinLockscreen.qml"
160142 }
143+ }
144+ onSourceChanged: {
145+ waiting = false
146+ showWrongText = false
147+ }
161148
162− Connections {
163− target: pinPadLoader.item
164−
165− onEntered: {
166− pinPadLoader.waiting = true
167− root.entered(passphrase);
168− }
149+ Connections {
150+ target: pinPadLoader.item
169151
170− onCancel: {
171− root.cancel()
172− }
152+ onEntered: {
153+ pinPadLoader.waiting = true
154+ root.entered(passphrase);
173155 }
174156
175− Binding {
176− target: pinPadLoader.item
177− property: "minPinLength"
178− value: root.minPinLength
179− }
180− Binding {
181− target: pinPadLoader.item
182− property: "maxPinLength"
183− value: root.maxPinLength
184− }
185− Binding {
186− target: pinPadLoader.item
187− property: "infoText"
188− value: root.infoText
189− }
190− Binding {
191− target: pinPadLoader.item
192− property: "retryText"
193− value: root.retryText
194− }
195− Binding {
196− target: pinPadLoader.item
197− property: "errorText"
198− value: pinPadLoader.showWrongText ? root.errorText : ""
199− }
200− Binding {
201− target: pinPadLoader.item
202− property: "entryEnabled"
203− value: !pinPadLoader.waiting
204− }
205− Binding {
206− target: pinPadLoader.item
207− property: "alphaNumeric"
208− value: root.alphaNumeric
209− }
210− Binding {
211− target: pinPadLoader.item
212− property: "delayMinutes"
213− value: root.delayMinutes
214− }
215− Binding {
216− target: pinPadLoader.item
217− property: "showCancelButton"
218− value: root.showCancelButton
219− }
220− Binding {
221− target: pinPadLoader.item
222− property: "foregroundColor"
223− value: root.foregroundColor
157+ onCancel: {
158+ root.cancel()
224159 }
225160 }
161+
162+ Binding {
163+ target: pinPadLoader.item
164+ property: "minPinLength"
165+ value: root.minPinLength
166+ }
167+ Binding {
168+ target: pinPadLoader.item
169+ property: "maxPinLength"
170+ value: root.maxPinLength
171+ }
172+ Binding {
173+ target: pinPadLoader.item
174+ property: "infoText"
175+ value: root.infoText
176+ }
177+ Binding {
178+ target: pinPadLoader.item
179+ property: "retryText"
180+ value: root.retryText
181+ }
182+ Binding {
183+ target: pinPadLoader.item
184+ property: "errorText"
185+ value: pinPadLoader.showWrongText ? root.errorText : ""
186+ }
187+ Binding {
188+ target: pinPadLoader.item
189+ property: "entryEnabled"
190+ value: !pinPadLoader.waiting
191+ }
192+ Binding {
193+ target: pinPadLoader.item
194+ property: "alphaNumeric"
195+ value: root.alphaNumeric
196+ }
197+ Binding {
198+ target: pinPadLoader.item
199+ property: "delayMinutes"
200+ value: root.delayMinutes
201+ }
202+ Binding {
203+ target: pinPadLoader.item
204+ property: "showCancelButton"
205+ value: root.showCancelButton
206+ }
207+ Binding {
208+ target: pinPadLoader.item
209+ property: "foregroundColor"
210+ value: root.foregroundColor
211+ }
226212 }
227213
228214 Item {
qml/Components/PassphraseLockscreen.qml+5−4
@@ -18,10 +18,11 @@ import QtQuick 2.4
1818import Ubuntu.Components 1.3
1919import "../Components"
2020
21−Item {
21+FocusScope {
2222 id: root
2323 y: units.gu(4)
2424 height: shakeContainer.height
25+ focus: true
2526
2627 property string infoText
2728 property string errorText
@@ -42,8 +43,6 @@ Item {
4243 }
4344 }
4445
45− onActiveFocusChanged: if (activeFocus) pinentryField.forceActiveFocus()
46−
4746 Column {
4847 id: shakeContainer
4948 anchors.horizontalCenter: parent.horizontalCenter
@@ -59,14 +58,16 @@ Item {
5958 text: root.infoText
6059 }
6160
62− Item {
61+ FocusScope {
6362 id: entryContainer
6463 anchors { left: parent.left; right: parent.right; margins: units.gu(2) }
6564 height: units.gu(4)
65+ focus: true
6666
6767 TextInput {
6868 id: pinentryField
6969 objectName: "pinentryField"
70+ focus: true
7071
7172 property bool incorrectOverride: false
7273
qml/Components/PinLockscreen.qml+22−1
@@ -19,8 +19,9 @@ import Ubuntu.Components 1.3
1919import Ubuntu.Components.ListItems 1.3
2020import "../Components"
2121
22−Item {
22+FocusScope {
2323 id: root
24+ focus: true
2425
2526 property string infoText
2627 property string retryText
@@ -45,6 +46,24 @@ Item {
4546 }
4647 }
4748
49+ Keys.onPressed: {
50+ if (pinentryField.text.length == root.maxPinLength)
51+ return;
52+
53+ if (event.key === Qt.Key_Backspace) {
54+ pinentryField.backspace();
55+ } else if (event.key === Qt.Key_Delete || event.key === Qt.Key_Escape) {
56+ closeButton.clicked()
57+ } else if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
58+ confirmButton.clicked()
59+ } else {
60+ var digit = parseInt(event.text);
61+ if (!isNaN(digit) && typeof digit == "number") {
62+ pinentryField.appendNumber(digit);
63+ }
64+ }
65+ }
66+
4867 Column {
4968 anchors {
5069 left: parent.left;
@@ -204,6 +223,7 @@ Item {
204223 width: numbersGrid.buttonWidth
205224 }
206225 PinPadButton {
226+ id: closeButton
207227 iconName: "close"
208228 height: units.gu(5) // visual spec has this row a little closer in
209229 width: numbersGrid.buttonWidth
@@ -216,6 +236,7 @@ Item {
216236 width: numbersGrid.buttonWidth
217237 }
218238 PinPadButton {
239+ id: confirmButton
219240 iconName: "tick"
220241 objectName: "confirmButton"
221242 height: units.gu(5)
qml/Greeter/NarrowView.qml+12
@@ -125,6 +125,18 @@ FocusScope {
125125 onCancel: coverPage.show()
126126 onEmergencyCall: root.emergencyCall()
127127
128+ onEnabledChanged: {
129+ if (enabled) {
130+ lockscreen.forceActiveFocus();
131+ }
132+ }
133+
134+ onVisibleChanged: {
135+ if (visible) {
136+ lockscreen.forceActiveFocus();
137+ }
138+ }
139+
128140 function maybeShow() {
129141 if (root.locked && !shown) {
130142 showNow();
tests/qmltests/Components/tst_Lockscreen.qml+14−7
@@ -235,11 +235,14 @@ Rectangle {
235235
236236 function test_unlock_data() {
237237 return [
238− {tag: "numeric", alphanumeric: false, password: "1234", minPinLength: 4, maxPinLength: 4},
239− {tag: "alphanumeric", alphanumeric: true, password: "password", minPinLength: -1, maxPinLength: -1},
240− {tag: "numeric (wrong)", alphanumeric: false, password: "4321", minPinLength: 4, maxPinLength: 4},
241− {tag: "alphanumeric (wrong)", alphanumeric: true, password: "drowssap", minPinLength: -1, maxPinLength: -1},
242− {tag: "flexible length", alphanumeric: false, password: "1234", minPinLength: -1, maxPinLength: -1},
238+ {tag: "numeric", alphanumeric: false, password: "1234", minPinLength: 4, maxPinLength: 4, keyboard: false},
239+ {tag: "alphanumeric", alphanumeric: true, password: "password", minPinLength: -1, maxPinLength: -1, keyboard: false},
240+ {tag: "numeric (wrong)", alphanumeric: false, password: "4321", minPinLength: 4, maxPinLength: 4, keyboard: false},
241+ {tag: "alphanumeric (wrong)", alphanumeric: true, password: "drowssap", minPinLength: -1, maxPinLength: -1, keyboard: false},
242+ {tag: "flexible length", alphanumeric: false, password: "1234", minPinLength: -1, maxPinLength: -1, keyboard: false},
243+ {tag: "numeric", alphanumeric: false, password: "1234", minPinLength: 4, maxPinLength: 4, keyboard: true},
244+ {tag: "numeric (wrong)", alphanumeric: false, password: "4321", minPinLength: 4, maxPinLength: 4, keyboard: true},
245+ {tag: "flexible length", alphanumeric: false, password: "1234", minPinLength: -1, maxPinLength: -1, keyboard: true}
243246 ]
244247 }
245248
@@ -259,8 +262,12 @@ Rectangle {
259262 } else {
260263 for (var i = 0; i < data.password.length; ++i) {
261264 var character = data.password.charAt(i)
262− var button = findChild(lockscreen, "pinPadButton" + character)
263− mouseClick(button, units.gu(1), units.gu(1))
265+ if (data.keyboard) {
266+ typeString(character)
267+ } else {
268+ var button = findChild(lockscreen, "pinPadButton" + character)
269+ mouseClick(button, units.gu(1), units.gu(1))
270+ }
264271 }
265272 var confirmButton = findChild(lockscreen, "confirmButton");
266273 mouseClick(confirmButton, units.gu(1), units.gu(1));