65 lines
1.6 KiB
QML
65 lines
1.6 KiB
QML
import Quickshell
|
|
import Quickshell.Wayland
|
|
import Quickshell.Services.Pam
|
|
import QtQuick
|
|
|
|
Scope {
|
|
id: root
|
|
|
|
required property WlSessionLock lock
|
|
|
|
readonly property bool active: passwd.active
|
|
property string state
|
|
property string buffer
|
|
|
|
function handleKey(event: KeyEvent): void {
|
|
if (passwd.active)
|
|
return;
|
|
|
|
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
|
|
passwd.start();
|
|
} else if (event.key === Qt.Key_Backspace) {
|
|
if (event.modifiers & Qt.ControlModifier) {
|
|
buffer = "";
|
|
} else {
|
|
buffer = buffer.slice(0, -1);
|
|
}
|
|
} else if (" abcdefghijklmnopqrstuvwxyz1234567890`~!@#$%^&*()-_=+[{]}\\|;:'\",<.>/?".includes(event.text.toLowerCase())) {
|
|
// No illegal characters (you are insane if you use unicode in your password)
|
|
buffer += event.text;
|
|
}
|
|
}
|
|
|
|
PamContext {
|
|
id: passwd
|
|
|
|
onResponseRequiredChanged: {
|
|
if (!responseRequired)
|
|
return;
|
|
|
|
respond(root.buffer);
|
|
root.buffer = "";
|
|
}
|
|
|
|
onCompleted: res => {
|
|
if (res === PamResult.Success)
|
|
return root.lock.unlock();
|
|
|
|
if (res === PamResult.Error)
|
|
root.state = "error";
|
|
else if (res === PamResult.MaxTries)
|
|
root.state = "max";
|
|
else if (res === PamResult.Failed)
|
|
root.state = "fail";
|
|
|
|
stateReset.restart();
|
|
}
|
|
}
|
|
|
|
Timer {
|
|
id: stateReset
|
|
|
|
interval: 4000
|
|
onTriggered: root.state = ""
|
|
}
|
|
}
|