From c3c1f29df01977288c92f36a5db16b4583c1c5d7 Mon Sep 17 00:00:00 2001 From: Johannes Kresner Date: Sat, 29 Aug 2026 22:11:43 +0200 Subject: [PATCH] feat: add quickshell lock screen --- mutable_config/hypr/hypridle.conf | 2 +- mutable_config/hypr/hyprland.lua | 2 +- .../components/LockScreen/LockScreen.qml | 218 ++++++++++++++++++ .../components/Shared/TextField.qml | 1 + .../quickshell/components/Shared/Theme.qml | 16 +- mutable_config/quickshell/shell.qml | 14 ++ 6 files changed, 243 insertions(+), 10 deletions(-) create mode 100644 mutable_config/quickshell/components/LockScreen/LockScreen.qml diff --git a/mutable_config/hypr/hypridle.conf b/mutable_config/hypr/hypridle.conf index ef053f6..3ba017a 100644 --- a/mutable_config/hypr/hypridle.conf +++ b/mutable_config/hypr/hypridle.conf @@ -1,5 +1,5 @@ general { - lock_cmd = hyprlock + lock_cmd = qs ipc call lockScreen lock before_sleep_cmd = loginctl lock-session after_sleep_cmd = hyprctl dispatch dpms on } diff --git a/mutable_config/hypr/hyprland.lua b/mutable_config/hypr/hyprland.lua index 7acf894..c65d18f 100644 --- a/mutable_config/hypr/hyprland.lua +++ b/mutable_config/hypr/hyprland.lua @@ -26,7 +26,7 @@ local terminal = "ghostty" local fileManager = "nemo" local menu = "quickshell ipc call commandPalette toggle" local clipboard = "qs ipc call clipboardPicker open" -local lock = "hyprlock" +local lock = "qs ipc call lockScreen lock" ----------------- diff --git a/mutable_config/quickshell/components/LockScreen/LockScreen.qml b/mutable_config/quickshell/components/LockScreen/LockScreen.qml new file mode 100644 index 0000000..93838bc --- /dev/null +++ b/mutable_config/quickshell/components/LockScreen/LockScreen.qml @@ -0,0 +1,218 @@ +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(); + } + } + } +} diff --git a/mutable_config/quickshell/components/Shared/TextField.qml b/mutable_config/quickshell/components/Shared/TextField.qml index e433174..517b947 100644 --- a/mutable_config/quickshell/components/Shared/TextField.qml +++ b/mutable_config/quickshell/components/Shared/TextField.qml @@ -10,6 +10,7 @@ Rectangle { id: field property alias text: input.text + property alias echoMode: input.echoMode property string placeholder: "" signal escapePressed() diff --git a/mutable_config/quickshell/components/Shared/Theme.qml b/mutable_config/quickshell/components/Shared/Theme.qml index 838f6e6..3314102 100644 --- a/mutable_config/quickshell/components/Shared/Theme.qml +++ b/mutable_config/quickshell/components/Shared/Theme.qml @@ -13,14 +13,14 @@ QtObject { property color surfaceHover: "#f2313244" property color overlay: "#6011111b" - property color primary: "#cba6f7" - property color secondary: "#f5c2e7" - property color tertiary: "#89b4fa" - property color accent: "#cba6f7" + property color primary: "#74c7ec" + property color secondary: "#cba6f7" + property color tertiary: "#a6e3a1" + property color accent: "#74c7ec" - property color primaryContainer: "#24cba6f7" - property color secondaryContainer: "#24f5c2e7" - property color tertiaryContainer: "#2489b4fa" + property color primaryContainer: "#2474c7ec" + property color secondaryContainer: "#24cba6f7" + property color tertiaryContainer: "#24a6e3a1" property color alert: "#f38ba8" property color alertContainer: "#24f38ba8" @@ -35,7 +35,7 @@ QtObject { property color textMuted: "#a6adc8" property color textOnAccent: "#e611111b" - property color border: "#1acba6f7" + property color border: "#1a74c7ec" } // GENERATED:COLORS:END diff --git a/mutable_config/quickshell/shell.qml b/mutable_config/quickshell/shell.qml index b58199b..50f07e2 100644 --- a/mutable_config/quickshell/shell.qml +++ b/mutable_config/quickshell/shell.qml @@ -10,6 +10,7 @@ import "components/LogoutMenu" import "components/ClipboardManager" import "components/Notifications" import "components/WallpaperPicker" +import "components/LockScreen" ShellRoot { id: root @@ -133,4 +134,17 @@ ShellRoot { Showcase { id: showcase } + + // No unlock/toggle exposed here on purpose: unlocking only ever happens + // through a successful PamContext result inside LockScreen.qml. + IpcHandler { + target: "lockScreen" + function lock() { + lockScreen.locked = true; + } + } + + LockScreen { + id: lockScreen + } }