mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-08-03 10:14:45 +00:00
Add support for grace lock in lockscreen keypad
This commit is contained in:
parent
849cb5f88f
commit
01026a223a
2 changed files with 67 additions and 30 deletions
|
|
@ -24,6 +24,7 @@ import org.kde.plasma.core 2.0 as PlasmaCore
|
||||||
import org.kde.plasma.workspace.keyboardlayout 1.0
|
import org.kde.plasma.workspace.keyboardlayout 1.0
|
||||||
|
|
||||||
Rectangle {
|
Rectangle {
|
||||||
|
id: keypadRoot
|
||||||
color: Qt.rgba(250, 250, 250, 0.85) // slightly translucent background, for key contrast
|
color: Qt.rgba(250, 250, 250, 0.85) // slightly translucent background, for key contrast
|
||||||
property string pinLabel: qsTr("Enter PIN")
|
property string pinLabel: qsTr("Enter PIN")
|
||||||
|
|
||||||
|
|
@ -31,40 +32,70 @@ Rectangle {
|
||||||
property string lastKeyPressValue: "0"
|
property string lastKeyPressValue: "0"
|
||||||
property int indexWithNumber: -2
|
property int indexWithNumber: -2
|
||||||
|
|
||||||
|
// if waiting for result of auth
|
||||||
|
property bool waitingForAuth: false
|
||||||
|
|
||||||
|
function reset() {
|
||||||
|
waitingForAuth = false;
|
||||||
|
root.password = "";
|
||||||
|
keypadRoot.pinLabel = qsTr("Enter PIN");
|
||||||
|
}
|
||||||
|
|
||||||
// keypad functions
|
// keypad functions
|
||||||
function backspace() {
|
function backspace() {
|
||||||
lastKeyPressValue = "0";
|
if (!keypadRoot.waitingForAuth) {
|
||||||
indexWithNumber = -2;
|
keypadRoot.lastKeyPressValue = "0";
|
||||||
|
keypadRoot.indexWithNumber = -2;
|
||||||
root.password = root.password.substr(0, root.password.length - 1);
|
root.password = root.password.substr(0, root.password.length - 1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function clear() {
|
function clear() {
|
||||||
lastKeyPressValue = "0";
|
if (!keypadRoot.waitingForAuth) {
|
||||||
indexWithNumber = -2;
|
keypadRoot.lastKeyPressValue = "0";
|
||||||
|
keypadRoot.indexWithNumber = -2;
|
||||||
root.password = "";
|
root.password = "";
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function enter() {
|
function enter() {
|
||||||
|
keypadRoot.waitingForAuth = true;
|
||||||
|
// don't try to unlock if there is a timeout (unlock once unlocked)
|
||||||
|
if (!authenticator.graceLocked) {
|
||||||
authenticator.tryUnlock(root.password);
|
authenticator.tryUnlock(root.password);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function keyPress(data) {
|
function keyPress(data) {
|
||||||
if (keypad.pinLabel !== qsTr("Enter PIN")) {
|
if (!keypadRoot.waitingForAuth) {
|
||||||
keypad.pinLabel = qsTr("Enter PIN");
|
if (keypadRoot.pinLabel !== qsTr("Enter PIN")) {
|
||||||
|
keypadRoot.pinLabel = qsTr("Enter PIN");
|
||||||
}
|
}
|
||||||
lastKeyPressValue = data;
|
keypadRoot.lastKeyPressValue = data;
|
||||||
indexWithNumber = root.password.length;
|
keypadRoot.indexWithNumber = root.password.length;
|
||||||
root.password += data
|
root.password += data
|
||||||
|
|
||||||
// trigger turning letter into dot later
|
// trigger turning letter into dot later
|
||||||
letterTimer.restart();
|
letterTimer.restart();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: authenticator
|
target: authenticator
|
||||||
|
function onSucceeded() {
|
||||||
|
pinLabel = qsTr("Logging in...");
|
||||||
|
keypadRoot.waitingForAuth = false;
|
||||||
|
}
|
||||||
function onFailed() {
|
function onFailed() {
|
||||||
root.password = "";
|
root.password = "";
|
||||||
pinLabel = qsTr("Wrong PIN")
|
pinLabel = qsTr("Wrong PIN");
|
||||||
|
keypadRoot.waitingForAuth = false;
|
||||||
|
}
|
||||||
|
function onGraceLockedChanged() {
|
||||||
|
// try authenticating if it was waiting for grace lock to stop and it has stopped
|
||||||
|
if (!authenticator.graceLocked && keypadRoot.waitingForAuth) {
|
||||||
|
authenticator.tryUnlock(root.password);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,11 +103,11 @@ Rectangle {
|
||||||
Keys.onPressed: {
|
Keys.onPressed: {
|
||||||
if (event.modifiers === Qt.NoModifier) {
|
if (event.modifiers === Qt.NoModifier) {
|
||||||
if (event.key === Qt.Key_Backspace) {
|
if (event.key === Qt.Key_Backspace) {
|
||||||
backspace();
|
keypadRoot.backspace();
|
||||||
} else if (event.key === Qt.Key_Return) {
|
} else if (event.key === Qt.Key_Return) {
|
||||||
enter();
|
keypadRoot.enter();
|
||||||
} else if (event.text != "") {
|
} else if (event.text != "") {
|
||||||
keyPress(event.text);
|
keypadRoot.keyPress(event.text);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -88,8 +119,8 @@ Rectangle {
|
||||||
running: false
|
running: false
|
||||||
repeat: false
|
repeat: false
|
||||||
onTriggered: {
|
onTriggered: {
|
||||||
lastKeyPressValue = 0;
|
keypadRoot.lastKeyPressValue = 0;
|
||||||
indexWithNumber = -2;
|
keypadRoot.indexWithNumber = -2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,19 +135,26 @@ Rectangle {
|
||||||
}
|
}
|
||||||
spacing: units.gridUnit
|
spacing: units.gridUnit
|
||||||
|
|
||||||
|
Item {
|
||||||
|
Layout.alignment: Qt.AlignCenter
|
||||||
|
}
|
||||||
|
|
||||||
// pin dot display
|
// pin dot display
|
||||||
Item {
|
Item {
|
||||||
Layout.alignment: Qt.AlignCenter
|
Layout.alignment: Qt.AlignCenter
|
||||||
Layout.minimumHeight: units.gridUnit * 0.5
|
Layout.minimumHeight: units.gridUnit * 0.5
|
||||||
Layout.maximumWidth: parent.width
|
Layout.maximumWidth: parent.width
|
||||||
|
|
||||||
|
// label ("wrong pin", "enter pin")
|
||||||
Label {
|
Label {
|
||||||
visible: root.password.length === 0
|
visible: root.password.length === 0
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
text: pinLabel
|
text: keypadRoot.pinLabel
|
||||||
font.pointSize: 12
|
font.pointSize: 12
|
||||||
color: "#616161"
|
color: "#616161"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// dot display and letter
|
||||||
RowLayout {
|
RowLayout {
|
||||||
id: dotDisplay
|
id: dotDisplay
|
||||||
anchors.centerIn: parent
|
anchors.centerIn: parent
|
||||||
|
|
@ -131,13 +169,13 @@ Rectangle {
|
||||||
Layout.preferredHeight: Layout.preferredWidth
|
Layout.preferredHeight: Layout.preferredWidth
|
||||||
Layout.alignment: Qt.AlignVCenter
|
Layout.alignment: Qt.AlignVCenter
|
||||||
radius: width
|
radius: width
|
||||||
color: "#424242"
|
color: keypadRoot.waitingForAuth ? "#969696" : "#424242" // dim when waiting for auth
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Label { // number/letter
|
Label { // number/letter
|
||||||
visible: root.password.length-1 === indexWithNumber // hide label if no label needed
|
visible: root.password.length-1 === indexWithNumber // hide label if no label needed
|
||||||
Layout.alignment: Qt.AlignHCenter
|
Layout.alignment: Qt.AlignHCenter
|
||||||
color: "#424242"
|
color: keypadRoot.waitingForAuth ? "#969696" : "#424242"
|
||||||
text: lastKeyPressValue
|
text: lastKeyPressValue
|
||||||
font.pointSize: 12
|
font.pointSize: 12
|
||||||
}
|
}
|
||||||
|
|
@ -185,11 +223,11 @@ Rectangle {
|
||||||
onReleased: parent.color = "white"
|
onReleased: parent.color = "white"
|
||||||
onClicked: {
|
onClicked: {
|
||||||
if (modelData === "R") {
|
if (modelData === "R") {
|
||||||
backspace();
|
keypadRoot.backspace();
|
||||||
} else if (modelData === "E") {
|
} else if (modelData === "E") {
|
||||||
enter();
|
keypadRoot.enter();
|
||||||
} else {
|
} else {
|
||||||
keyPress(modelData);
|
keypadRoot.keyPress(modelData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
onPressAndHold: {
|
onPressAndHold: {
|
||||||
|
|
|
||||||
|
|
@ -234,8 +234,7 @@ PlasmaCore.ColorScope {
|
||||||
// wipe password if it is more than half way down the screen
|
// wipe password if it is more than half way down the screen
|
||||||
onContentYChanged: {
|
onContentYChanged: {
|
||||||
if (contentY < columnHeight / 2) {
|
if (contentY < columnHeight / 2) {
|
||||||
root.password = "";
|
keypad.reset();
|
||||||
keypad.pinLabel = qsTr("Enter PIN");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue