lock: add placeholder + manual focus

This commit is contained in:
2 * r + 2 * t 2025-08-10 19:37:34 +10:00
parent 56ca1632c5
commit 31cc51b6e9
2 changed files with 104 additions and 58 deletions

View file

@ -110,6 +110,15 @@ ColumnLayout {
Keys.onPressed: event => root.lock.pam.handleKey(event) Keys.onPressed: event => root.lock.pam.handleKey(event)
StateLayer {
hoverEnabled: false
cursorShape: Qt.IBeamCursor
function onClicked(): void {
parent.forceActiveFocus();
}
}
RowLayout { RowLayout {
id: input id: input
@ -122,14 +131,21 @@ ColumnLayout {
text: "lock" text: "lock"
} }
Item {
Layout.fillWidth: true
Layout.fillHeight: true
ListView { ListView {
id: passwordList id: passwordList
Layout.fillWidth: true anchors.left: parent.left
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
implicitHeight: Appearance.font.size.normal implicitHeight: Appearance.font.size.normal
orientation: Qt.Horizontal orientation: Qt.Horizontal
clip: true clip: true
interactive: false
spacing: Appearance.spacing.small / 2 spacing: Appearance.spacing.small / 2
highlightRangeMode: ListView.StrictlyEnforceRange highlightRangeMode: ListView.StrictlyEnforceRange
preferredHighlightBegin: 0 preferredHighlightBegin: 0
@ -179,6 +195,22 @@ ColumnLayout {
} }
} }
StyledText {
anchors.centerIn: parent
text: qsTr("Enter your password")
color: Colours.palette.m3outline
font.pointSize: Appearance.font.size.normal
font.family: Appearance.font.family.mono
opacity: root.lock.pam.buffer ? 0 : 1
Behavior on opacity {
Anim {}
}
}
}
StyledRect { StyledRect {
implicitWidth: implicitHeight implicitWidth: implicitHeight
implicitHeight: enterIcon.implicitHeight + Appearance.padding.small * 2 implicitHeight: enterIcon.implicitHeight + Appearance.padding.small * 2

View file

@ -1,8 +1,9 @@
import Quickshell
import Quickshell.Wayland import Quickshell.Wayland
import Quickshell.Services.Pam import Quickshell.Services.Pam
import QtQuick import QtQuick
PamContext { Scope {
id: root id: root
required property WlSessionLock lock required property WlSessionLock lock
@ -11,11 +12,11 @@ PamContext {
property string buffer: "" property string buffer: ""
function handleKey(event: KeyEvent): void { function handleKey(event: KeyEvent): void {
if (active) if (passwd.active)
return; return;
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
start(); passwd.start();
} else if (event.key === Qt.Key_Backspace) { } else if (event.key === Qt.Key_Backspace) {
if (event.modifiers & Qt.ControlModifier) { if (event.modifiers & Qt.ControlModifier) {
buffer = ""; buffer = "";
@ -28,23 +29,36 @@ PamContext {
} }
} }
PamContext {
id: passwd
onResponseRequiredChanged: { onResponseRequiredChanged: {
if (!responseRequired) if (!responseRequired)
return; return;
respond(buffer); respond(root.buffer);
buffer = ""; root.buffer = "";
} }
onCompleted: res => { onCompleted: res => {
if (res === PamResult.Success) if (res === PamResult.Success)
return lock.unlock(); return root.lock.unlock();
if (res === PamResult.Error) if (res === PamResult.Error)
state = "error"; root.state = "error";
else if (res === PamResult.MaxTries) else if (res === PamResult.MaxTries)
state = "max"; root.state = "max";
else if (res === PamResult.Failed) else if (res === PamResult.Failed)
state = "fail"; root.state = "fail";
stateReset.restart();
}
}
Timer {
id: stateReset
interval: 4000
onTriggered: root.state = "none"
} }
} }