pragma ComponentBehavior: Bound import QtQuick import Quickshell import Quickshell.Io import Quickshell.Wayland import Quickshell.Services.Pam import qs.HyprChrome.Widgets.Greeter // ext-session-lock screen: the greeter's panel on every output, so whichever // one Hyprland gives the keyboard has a field. Runs as its own instance // (lock.qml) so a reload of the main shell cannot drop the lock; exits once // unlocked. Scope { id: root readonly property string userName: Quickshell.env("USER") ?? "" readonly property string hostName: hostFile.text().trim() || "localhost" // Typed password, held until PAM's first secret prompt arrives. property string pendingSecret: "" // PAM asked a follow-up (OTP etc.) that the user must answer directly. property bool awaitingResponse: false property bool busy: false property bool unlocking: false property string message: "" property bool messageIsError: false property bool failed: false property string inputPrompt: "" property bool responseVisible: false property date now: new Date() // Each surface keeps its own field; this resets all of them. signal resetSecret function setMessage(text, isError) { root.message = text; root.messageIsError = isError; } function resetToPassword() { root.pendingSecret = ""; root.awaitingResponse = false; root.busy = false; root.inputPrompt = ""; root.responseVisible = false; root.resetSecret(); } function submit(secret) { root.failed = false; if (root.awaitingResponse) { root.awaitingResponse = false; root.busy = true; root.resetSecret(); pam.respond(secret); return; } if (pam.active) return; root.setMessage("", false); root.pendingSecret = secret; root.busy = true; if (!pam.start()) { root.resetToPassword(); root.setMessage("pam failed to start", true); } } FileView { id: hostFile path: "/etc/hostname" blockLoading: true } PamContext { id: pam // security.pam.services.hyprchrome-lock (services/desktop/desktop-hyprland.nix). config: "hyprchrome-lock" user: root.userName onPamMessage: { if (!pam.responseRequired) { root.setMessage(pam.message, pam.messageIsError); return; } // First hidden prompt is the password already typed. if (root.pendingSecret !== "" && !pam.responseVisible) { const secret = root.pendingSecret; root.pendingSecret = ""; pam.respond(secret); return; } root.busy = false; root.awaitingResponse = true; root.inputPrompt = pam.message.replace(/:\s*$/, ""); root.responseVisible = pam.responseVisible; root.resetSecret(); } onCompleted: result => { if (result === PamResult.Success) { root.setMessage("unlocked", false); root.unlocking = true; return; } root.resetToPassword(); root.failed = true; root.setMessage(result === PamResult.MaxTries ? "too many attempts" : "authentication failed", true); } onError: error => { root.resetToPassword(); root.setMessage(PamError.toString(error), true); } } // Fade out, then release the outputs. The quit is deferred so the unlock // request is flushed before the connection closes; exiting while still // locked would leave Hyprland's "lock app died" screen up. Timer { running: root.unlocking interval: 220 onTriggered: { lock.locked = false; quitTimer.start(); } } Timer { id: quitTimer interval: 100 onTriggered: Qt.quit() } Timer { running: true repeat: true interval: 1000 triggeredOnStart: true onTriggered: root.now = new Date() } WlSessionLock { id: lock locked: true WlSessionLockSurface { color: "transparent" LockBackdrop { anchors.fill: parent } LoginContent { id: content width: 640 anchors.horizontalCenter: parent.horizontalCenter y: Math.max(32, Math.round(parent.height * 0.42 - height / 2)) + (1 - opacity) * 12 opacity: root.unlocking ? 0 : 1 Behavior on opacity { NumberAnimation { duration: 200; easing.type: Easing.OutCubic } } title: "LOCKED // " + root.hostName.toUpperCase() panelId: "LCK" meta: "PAM" submitLabel: "UNLOCK" userEditable: false showPower: false hostName: root.hostName sessionName: "hyprland" user: root.userName now: root.now busy: root.busy || root.unlocking message: root.message messageIsError: root.messageIsError failed: root.failed inputPrompt: root.inputPrompt responseVisible: root.responseVisible onSubmitted: (user, secret) => root.submit(secret) Component.onCompleted: content.focusSecret() Connections { target: root function onResetSecret() { content.clearSecret(); content.focusSecret(); } } } } } }