lock: add password box content timeout

This commit is contained in:
end-4
2025-07-21 10:45:33 +07:00
parent c5f8377a85
commit a7805af421
@@ -4,56 +4,64 @@ import Quickshell
import Quickshell.Services.Pam
Scope {
id: root
signal shouldReFocus()
signal unlocked()
signal failed()
id: root
signal shouldReFocus()
signal unlocked()
signal failed()
// These properties are in the context and not individual lock surfaces
// so all surfaces can share the same state.
property string currentText: ""
property bool unlockInProgress: false
property bool showFailure: false
// These properties are in the context and not individual lock surfaces
// so all surfaces can share the same state.
property string currentText: ""
property bool unlockInProgress: false
property bool showFailure: false
// Clear the failure text once the user starts typing.
onCurrentTextChanged: {
showFailure = false;
GlobalStates.screenLockContainsCharacters = currentText.length > 0;
}
Timer {
id: passwordClearTimer
interval: 10000
onTriggered: {
root.currentText = "";
}
}
function tryUnlock() {
if (currentText === "") return;
onCurrentTextChanged: {
showFailure = false; // Clear the failure text once the user starts typing.
GlobalStates.screenLockContainsCharacters = currentText.length > 0;
passwordClearTimer.restart();
}
root.unlockInProgress = true;
pam.start();
}
function tryUnlock() {
if (currentText === "") return;
PamContext {
id: pam
root.unlockInProgress = true;
pam.start();
}
// Its best to have a custom pam config for quickshell, as the system one
// might not be what your interface expects, and break in some way.
// This particular example only supports passwords.
configDirectory: "pam"
config: "password.conf"
PamContext {
id: pam
// pam_unix will ask for a response for the password prompt
onPamMessage: {
if (this.responseRequired) {
this.respond(root.currentText);
}
}
// Its best to have a custom pam config for quickshell, as the system one
// might not be what your interface expects, and break in some way.
// This particular example only supports passwords.
configDirectory: "pam"
config: "password.conf"
// pam_unix won't send any important messages so all we need is the completion status.
onCompleted: result => {
if (result == PamResult.Success) {
root.unlocked();
} else {
root.showFailure = true;
}
// pam_unix will ask for a response for the password prompt
onPamMessage: {
if (this.responseRequired) {
this.respond(root.currentText);
}
}
root.currentText = "";
root.unlockInProgress = false;
}
}
// pam_unix won't send any important messages so all we need is the completion status.
onCompleted: result => {
if (result == PamResult.Success) {
root.unlocked();
} else {
root.showFailure = true;
}
root.currentText = "";
root.unlockInProgress = false;
}
}
}