import QtQuick import Quickshell import Quickshell.Wayland import Quickshell.Services.Pam import Quickshell.Services.UPower import "../Shared" // The one surface in this shell that owns a real wlr-session-lock-v1 object // instead of being a PanelWindow toggled by IpcHandler: `locked` is the // actual lock state (the compositor keeps the session locked even if this // process dies), and unlocking only ever happens via a successful PamContext // result - there is no external "unlock" IPC call by design. // // PamContext lives INSIDE the `surface` content tree (see below), not as a // direct child of this WlSessionLock. A PamContext declared directly under // WlSessionLock never worked reliably in testing: not just sibling-id // references from outside it, but even PamContext's OWN Component.onCompleted // never fired. WlSessionLock is a `Reloadable` or Quickshell C++ type with // unusual object-graph handling for reload support; a plain QObject child // declared directly under it doesn't get normal QML construction/binding // behavior. The surface's content tree, in contrast, is a perfectly ordinary // Item tree (proven extensively: every `sessionLock.xxx` reference from // deep inside it - the password field, hint bar, shake animation - has // always worked reliably), so PamContext lives there instead, created fresh // each time the surface itself is created (i.e. each time the screen locks). WlSessionLock { id: sessionLock property string password: "" property string errorText: "" property bool awaitingResponse: false property bool responseVisible: false function lock() { reset(); locked = true; } function reset() { sessionLock.password = ""; sessionLock.errorText = ""; sessionLock.awaitingResponse = false; } surface: Component { WlSessionLockSurface { id: lockSurface color: Theme.colors.background property QtObject battery: UPower.displayDevice PamContext { id: authCtx config: "hyprlock" // reuse the PAM service that already exists for hyprlock Component.onCompleted: authCtx.start() // NOTE: PamContext's "onMessage" that shows up in tooling is // a private C++ slot wired internally to the pam // conversation object - declaring `function onMessage(...)` // here does NOT override it and is silently never called. // The real public signal is `pamMessage()` (no args); read // the message/response properties off this object after it // fires. onPamMessage: { sessionLock.errorText = authCtx.messageIsError ? authCtx.message : ""; sessionLock.awaitingResponse = authCtx.responseRequired; sessionLock.responseVisible = authCtx.responseVisible; } onCompleted: (result) => { if (result === PamResult.Success) { sessionLock.locked = false; } else { sessionLock.errorText = "Incorrect password"; sessionLock.password = ""; sessionLock.awaitingResponse = false; authCtx.start(); } } onError: (error) => { sessionLock.errorText = "Authentication error"; sessionLock.password = ""; sessionLock.awaitingResponse = false; authCtx.start(); } } SystemClock { id: clock precision: SystemClock.Seconds } Column { anchors.centerIn: parent spacing: Theme.geometry.spacing * 3 Column { anchors.horizontalCenter: parent.horizontalCenter spacing: Theme.geometry.spacing Text { anchors.horizontalCenter: parent.horizontalCenter text: Qt.formatDateTime(clock.date, "hh:mm") color: Theme.colors.text font.family: Theme.font.family font.bold: true font.pixelSize: 96 } Text { anchors.horizontalCenter: parent.horizontalCenter text: Qt.formatDateTime(clock.date, "dddd, d MMMM") color: Theme.colors.textMuted font.family: Theme.font.family font.pixelSize: Theme.type.title } } Row { anchors.horizontalCenter: parent.horizontalCenter spacing: Theme.geometry.spacing / 2 visible: lockSurface.battery.isPresent Text { text: { let p = lockSurface.battery.percentage; if (p >= 0.9) return ""; // nf-fa-battery_full if (p >= 0.65) return ""; // nf-fa-battery_three_quarters if (p >= 0.4) return ""; // nf-fa-battery_half if (p >= 0.15) return ""; // nf-fa-battery_quarter return ""; // nf-fa-battery_empty } font.family: Theme.font.family font.pixelSize: Theme.type.body color: { let p = lockSurface.battery.percentage; if (p >= 0.5) return Theme.colors.success; if (p >= 0.2) return Theme.colors.warning; return Theme.colors.alert; } } Text { text: Math.round(lockSurface.battery.percentage * 100) + "%" font.family: Theme.font.family font.pixelSize: Theme.type.body color: Theme.colors.textMuted } } Column { anchors.horizontalCenter: parent.horizontalCenter spacing: Theme.geometry.spacing Item { id: passwordShake width: 320 height: passwordField.height anchors.horizontalCenter: parent.horizontalCenter SequentialAnimation { id: shakeAnim NumberAnimation { target: passwordShake; property: "x"; to: -8; duration: 40 } NumberAnimation { target: passwordShake; property: "x"; to: 8; duration: 40 } NumberAnimation { target: passwordShake; property: "x"; to: -6; duration: 40 } NumberAnimation { target: passwordShake; property: "x"; to: 0; duration: 40 } } Connections { target: sessionLock function onErrorTextChanged() { if (sessionLock.errorText.length > 0) shakeAnim.start(); } function onPasswordChanged() { if (sessionLock.password.length === 0) passwordField.text = ""; } } TextField { id: passwordField width: parent.width placeholder: "Password" echoMode: sessionLock.responseVisible ? TextInput.Normal : TextInput.Password onVisibleChanged: { if (visible) focusInput(); } onTextChanged: sessionLock.password = text onReturnPressed: { if (!sessionLock.awaitingResponse) return; authCtx.respond(sessionLock.password); sessionLock.awaitingResponse = false; } } } Text { anchors.horizontalCenter: parent.horizontalCenter text: sessionLock.errorText visible: sessionLock.errorText.length > 0 color: Theme.colors.alert font.family: Theme.font.family font.pixelSize: Theme.type.caption } HintBar { anchors.horizontalCenter: parent.horizontalCenter hints: [ { key: "↵", label: "Unlock" } ] } } } onVisibleChanged: { if (visible) passwordField.focusInput(); } } } }