feat: add quickshell lock screen
This commit is contained in:
1 parent
e818b1c1ea
commit
0d00efc465
6 files changed
+243
-10
No files matched your search
@@ -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
|
||||
}
|
||||
|
||||
@@ -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"
|
||||
|
||||
|
||||
-----------------
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ Rectangle {
|
||||
id: field
|
||||
|
||||
property alias text: input.text
|
||||
property alias echoMode: input.echoMode
|
||||
property string placeholder: ""
|
||||
|
||||
signal escapePressed()
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user