lock: use TextInput for keyboard input instead of Keys on plain Item
This commit is contained in:
parent
9f0043cd23
commit
3d68d467f7
2 changed files with 30 additions and 25 deletions
|
|
@ -15,26 +15,11 @@ QtObject {
|
|||
|
||||
signal authFailed
|
||||
|
||||
function handleKey(event) {
|
||||
function submit() {
|
||||
if (_passwd.active || state === "max")
|
||||
return;
|
||||
|
||||
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -139,17 +139,27 @@ WlSessionLockSurface {
|
|||
}
|
||||
}
|
||||
|
||||
// Keyboard input - focus lives on an Item since WlSessionLockSurface is a window.
|
||||
// Aggressively reclaim focus: Component.onCompleted may fire before the surface
|
||||
// is configured, and other items can steal activeFocus during layout.
|
||||
Item {
|
||||
// Keyboard input via TextInput - engages Qt's full input pipeline including
|
||||
// text-input protocol, which is more reliable than Keys on a plain Item in
|
||||
// layer-shell/lock surfaces where raw wl_keyboard delivery can be flaky.
|
||||
TextInput {
|
||||
id: _keyInput
|
||||
anchors.fill: parent
|
||||
focus: true
|
||||
Keys.onPressed: event => {
|
||||
if (!root._unlocking)
|
||||
root.auth.handleKey(event);
|
||||
color: "transparent"
|
||||
selectionColor: "transparent"
|
||||
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: {
|
||||
if (!activeFocus)
|
||||
forceActiveFocus();
|
||||
|
|
@ -161,6 +171,16 @@ WlSessionLockSurface {
|
|||
_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
|
||||
property bool _unlocking: false
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue