lock: use TextInput for keyboard input instead of Keys on plain Item

This commit is contained in:
Damocles 2026-04-17 14:31:37 +02:00
parent 9f0043cd23
commit 3d68d467f7
2 changed files with 30 additions and 25 deletions

View file

@ -15,26 +15,11 @@ QtObject {
signal authFailed signal authFailed
function handleKey(event) { function submit() {
if (_passwd.active || state === "max") if (_passwd.active || state === "max")
return; return;
if (buffer.length > 0)
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) { _passwd.start();
if (buffer.length > 0)
_passwd.start();
} else if (event.key === Qt.Key_Backspace) {
if (event.modifiers & Qt.ControlModifier)
buffer = "";
else
buffer = buffer.slice(0, -1);
} else if (event.key === Qt.Key_Escape) {
buffer = "";
} else if (event.text && event.text.length === 1) {
const c = event.text;
// Accept printable ASCII
if (c.charCodeAt(0) >= 32 && c.charCodeAt(0) < 127)
buffer += c;
}
} }
property PamContext _passwd: PamContext { property PamContext _passwd: PamContext {

View file

@ -139,17 +139,27 @@ WlSessionLockSurface {
} }
} }
// Keyboard input - focus lives on an Item since WlSessionLockSurface is a window. // Keyboard input via TextInput - engages Qt's full input pipeline including
// Aggressively reclaim focus: Component.onCompleted may fire before the surface // text-input protocol, which is more reliable than Keys on a plain Item in
// is configured, and other items can steal activeFocus during layout. // layer-shell/lock surfaces where raw wl_keyboard delivery can be flaky.
Item { TextInput {
id: _keyInput id: _keyInput
anchors.fill: parent anchors.fill: parent
focus: true focus: true
Keys.onPressed: event => { color: "transparent"
if (!root._unlocking) selectionColor: "transparent"
root.auth.handleKey(event); selectedTextColor: "transparent"
cursorVisible: false
enabled: !root._unlocking && root.auth.state !== "max" && root.auth.state !== "busy"
onTextChanged: root.auth.buffer = text
Keys.onReturnPressed: root.auth.submit()
Keys.onEnterPressed: root.auth.submit()
Keys.onEscapePressed: {
text = "";
} }
onActiveFocusChanged: { onActiveFocusChanged: {
if (!activeFocus) if (!activeFocus)
forceActiveFocus(); forceActiveFocus();
@ -161,6 +171,16 @@ WlSessionLockSurface {
_keyInput.forceActiveFocus(); _keyInput.forceActiveFocus();
} }
// Sync TextInput when auth clears buffer externally (PAM submit, lock reset)
Connections {
target: root.auth
function onBufferChanged() {
if (_keyInput.text !== root.auth.buffer)
_keyInput.text = root.auth.buffer;
}
}
// Unlock animation // Unlock animation
property bool _unlocking: false property bool _unlocking: false