Route session locking through Panama
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
|
||||
general {
|
||||
# `pidof` guard prevents stacking lockers if this fires twice.
|
||||
lock_cmd = pidof hyprlock || hyprlock
|
||||
lock_cmd = pidof hyprlock || ~/.config/quickshell/scripts/panama-lock run
|
||||
before_sleep_cmd = loginctl lock-session
|
||||
after_sleep_cmd = hyprctl dispatch 'hl.dsp.dpms({ action = "on" })'
|
||||
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import QtQuick
|
||||
|
||||
import qs.config
|
||||
import qs.services
|
||||
|
||||
ShellRoot {
|
||||
IpcHandler {
|
||||
target: "lock-screen-test"
|
||||
|
||||
function status(): string {
|
||||
return JSON.stringify({
|
||||
generated: LockScreen.generated,
|
||||
path: LockScreen.path,
|
||||
fallback: LockScreen.fallback,
|
||||
lastError: LockScreen.lastError,
|
||||
busy: LockScreen.busy
|
||||
});
|
||||
}
|
||||
|
||||
function burst(): void {
|
||||
DesktopPreferences.set("lockBlurLevel", 1);
|
||||
DesktopPreferences.set("lockBlurLevel", 2);
|
||||
DesktopPreferences.set("lockBlurLevel", 4);
|
||||
}
|
||||
|
||||
function refresh(): void {
|
||||
LockScreen.refresh();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ generate() {
|
||||
printf '# The shipped defaults live in the Panama repo at config/dot/hypr/hypridle.conf.\n\n'
|
||||
|
||||
printf 'general {\n'
|
||||
printf ' lock_cmd = pidof hyprlock || hyprlock\n'
|
||||
printf ' lock_cmd = pidof hyprlock || ~/.config/quickshell/scripts/panama-lock run\n'
|
||||
if [[ "$lock_on_sleep" == "true" ]]; then
|
||||
printf ' before_sleep_cmd = loginctl lock-session\n'
|
||||
fi
|
||||
|
||||
@@ -0,0 +1,132 @@
|
||||
pragma Singleton
|
||||
|
||||
// Generated lock-screen state. Visual preferences are coalesced into one
|
||||
// helper invocation, while the last valid status remains visible if a helper
|
||||
// response is malformed.
|
||||
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import QtQuick
|
||||
|
||||
import qs.config
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
|
||||
readonly property string helperPath: Quickshell.shellDir + "/scripts/panama-lock"
|
||||
|
||||
property bool generated: false
|
||||
property string path: ""
|
||||
property bool fallback: true
|
||||
property string lastError: ""
|
||||
property string watchedSignature: ""
|
||||
property bool regenerateAfterCurrent: false
|
||||
|
||||
readonly property bool busy: generateProcess.running || statusProcess.running
|
||||
|
||||
function preferenceSignature(): string {
|
||||
DesktopPreferences.revision;
|
||||
return JSON.stringify([
|
||||
DesktopPreferences.get("lockBackgroundMode"),
|
||||
DesktopPreferences.get("lockBlurLevel"),
|
||||
DesktopPreferences.get("lockShowClock"),
|
||||
DesktopPreferences.get("lockShowDate"),
|
||||
DesktopPreferences.get("lockShowUser"),
|
||||
DesktopPreferences.get("lockFadeOnEmpty"),
|
||||
DesktopPreferences.get("use24Hour"),
|
||||
DesktopPreferences.get("colorScheme"),
|
||||
DesktopPreferences.get("wallpaperPath"),
|
||||
DesktopPreferences.get("wallpaperMode"),
|
||||
DesktopPreferences.get("wallpaperPerMonitor")
|
||||
]);
|
||||
}
|
||||
|
||||
function applyStatus(text: string): void {
|
||||
try {
|
||||
const state = JSON.parse(text);
|
||||
if (!state || typeof state.generated !== "boolean"
|
||||
|| typeof state.path !== "string" || state.path.length === 0)
|
||||
throw new Error("invalid lock status");
|
||||
root.generated = state.generated;
|
||||
root.path = state.path;
|
||||
root.fallback = state.fallback === true;
|
||||
root.lastError = typeof state.error === "string" ? state.error : "";
|
||||
} catch (error) {
|
||||
root.lastError = "The lock-screen configuration could not be read.";
|
||||
}
|
||||
}
|
||||
|
||||
function refresh(): void {
|
||||
if (!statusProcess.running)
|
||||
statusProcess.exec([root.helperPath, "status"]);
|
||||
}
|
||||
|
||||
function regenerate(): void {
|
||||
if (generateProcess.running) {
|
||||
root.regenerateAfterCurrent = true;
|
||||
return;
|
||||
}
|
||||
generateProcess.exec([root.helperPath, "generate"]);
|
||||
}
|
||||
|
||||
Process {
|
||||
id: statusProcess
|
||||
|
||||
property bool parsed: false
|
||||
|
||||
onRunningChanged: {
|
||||
if (running)
|
||||
parsed = false;
|
||||
}
|
||||
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
statusProcess.parsed = true;
|
||||
root.applyStatus(this.text);
|
||||
}
|
||||
}
|
||||
|
||||
onExited: (exitCode, exitStatus) => {
|
||||
if (exitCode !== 0 && !statusProcess.parsed)
|
||||
root.lastError = "The lock-screen configuration could not be read.";
|
||||
}
|
||||
}
|
||||
|
||||
Process {
|
||||
id: generateProcess
|
||||
|
||||
onExited: (exitCode, exitStatus) => {
|
||||
if (exitCode !== 0)
|
||||
root.lastError = "The lock-screen configuration could not be generated.";
|
||||
root.refresh();
|
||||
if (root.regenerateAfterCurrent) {
|
||||
root.regenerateAfterCurrent = false;
|
||||
regenerateTimer.restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: DesktopPreferences
|
||||
|
||||
function onRevisionChanged(): void {
|
||||
const signature = root.preferenceSignature();
|
||||
if (signature === root.watchedSignature)
|
||||
return;
|
||||
root.watchedSignature = signature;
|
||||
regenerateTimer.restart();
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: regenerateTimer
|
||||
interval: 250
|
||||
onTriggered: root.regenerate()
|
||||
}
|
||||
|
||||
Component.onCompleted: {
|
||||
root.watchedSignature = root.preferenceSignature();
|
||||
root.refresh();
|
||||
regenerateTimer.restart();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user