Files
glassMxrph/quickshell/lock/LockState.qml
T
mxandClaude Opus 5.5 5217af4f67 Add a notch mode that splits the bar around a pocket-dots style notch
Settings → Notch switches it on. The bar becomes left and right islands
with a notch at the top centre. Super+C, Super+X and a click on the notch
open a three-column panel: dashboard pages on the left (Media,
Performance, Calendar; the wheel switches them), the Control Center tiles
and weather in the middle, and notifications on the right. The
Performance card opens the full "Your computer" view. The launcher drops
out of the notch.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-12 16:39:35 +01:00

253 lines
8.4 KiB
QML

pragma Singleton
import QtQuick
import Quickshell
import Quickshell.Io
import Quickshell.Services.Pam
import "../services"
import "../core"
// Lock screen state and authentication. Every attempt starts a fresh PAM
// conversation (the bundled pam/password.conf, or a system service when
// lock.pamService is set) and answers its password prompt.
Singleton {
id: root
readonly property var options: ConfigService.ready ? ConfigService.data.lock : ({
enabled: true,
backdrop: "wallpaper",
glass: true,
media: true,
powerButtons: true,
pamService: ""
})
property bool locked: false
// A preview runs the same UI in ordinary windows: nothing is locked and a
// correct password simply closes it. Used by Settings and for testing.
property bool previewing: false
property bool unlocking: false
property string primary: ""
property string status: ""
property bool busy: false
property int failures: 0
property string purpose: ""
property var pending: null
property string testResult: ""
property var shots: ({})
// Live lock surfaces, for diagnostics and tests.
property var surfaces: []
property string realName: ""
// Active keyboard layout and Caps Lock, read from Hyprland when the lock
// screen shows and again whenever Caps Lock is pressed.
property string layout: ""
property bool capsLock: false
readonly property bool shown: locked || previewing
readonly property string runtimeDir: (Quickshell.env("XDG_RUNTIME_DIR") || "/tmp") + "/glassMxrph"
// Glass parameters follow the desktop's HyprGlass values for a matching look.
readonly property var glass: {
const v = ConfigService.ready ? ConfigService.data.hyprglass.values : {};
const pick = (key, fallback) => Number.isFinite(v[key]) ? v[key] : fallback;
return {
refraction: pick("refraction_strength", 3) * 6,
dispersion: Math.min(0.6, pick("chromatic_aberration", 0.45) * 0.35),
fresnel: pick("fresnel_strength", 0.5),
specular: pick("specular_strength", 0.8),
edge: Math.max(10, pick("edge_thickness", 0.065) * 300),
frost: Math.min(1, pick("blur_strength", 0.45) / 1.2 + 0.25),
brightness: pick("brightness", 0.95),
saturation: pick("saturation", 1) * (1 + pick("vibrancy", 0.15))
};
}
// The dashboard goes on the largest output; the focused one breaks ties.
function mainScreen() {
const active = ScreenService.active;
let best = active || null;
for (const screen of Quickshell.screens) {
if (!best || screen.width * screen.height > best.width * best.height)
best = screen;
}
return best ? best.name : "";
}
function lock() {
if (locked || grab.running)
return;
previewing = false;
ShellState.settingsOpen = false;
ShellState.controlCenterOpen = false;
ShellState.notchOpen = false;
ShellState.launcherOpen = false;
primary = mainScreen();
status = "";
if (options.backdrop === "screenshot") {
grab.names = Quickshell.screens.map(s => s.name).filter(n => /^[\w.-]+$/.test(n));
grab.running = true;
grabTimeout.restart();
} else
locked = true;
}
function preview() {
if (locked)
return;
ShellState.settingsOpen = false;
primary = mainScreen();
status = "";
previewing = true;
}
function cancelPreview() {
if (previewing && !busy) {
previewing = false;
status = "";
}
}
function submit(password, why) {
if (busy || !password)
return false;
purpose = why || (previewing ? "preview" : "unlock");
pending = password;
busy = true;
status = "";
if (!pam.start()) {
busy = false;
pending = null;
status = "Authentication is unavailable";
if (purpose === "test")
testResult = "error";
return false;
}
return true;
}
function test(password) {
testResult = "";
return submit(password, "test");
}
function probeKeyboard() {
layoutProbe.running = false;
layoutProbe.running = true;
}
function finishUnlock() {
unlocking = true;
unlockTimer.restart();
}
Connections {
target: ShellState
function onLockRequested() {
root.lock();
}
}
PamContext {
id: pam
config: root.options.pamService || "password.conf"
configDirectory: root.options.pamService ? "/etc/pam.d" : Qt.resolvedUrl("pam")
onPamMessage: {
if (responseRequired && root.pending !== null) {
respond(root.pending);
root.pending = null;
}
}
onCompleted: result => {
root.busy = false;
root.pending = null;
const ok = result === PamResult.Success;
if (root.purpose === "test") {
root.testResult = ok ? "accepted" : "rejected";
return;
}
if (ok)
root.finishUnlock();
else {
root.failures++;
root.status = result === PamResult.Error ? "Authentication error" : "Incorrect password";
}
}
}
Timer {
id: unlockTimer
interval: 420
onTriggered: {
root.locked = false;
root.previewing = false;
root.unlocking = false;
root.status = "";
if (Object.keys(root.shots).length) {
Quickshell.execDetached(["rm", "-f"].concat(Object.values(root.shots)));
root.shots = {};
}
}
}
// Screenshot backdrops: one grim capture per output, then lock (or lock anyway after a timeout).
Process {
id: grab
property var names: []
command: ["sh", "-c", "mkdir -p \"$1\" && shift && dir=\"$1\" && shift && for name; do grim -l 0 -o \"$name\" \"$dir/lock-$name.png\" & done; wait", "sh", root.runtimeDir, root.runtimeDir].concat(names)
// Quickshell 0.3.1 omits QProcess::ExitStatus from its type metadata.
// qmllint disable signal-handler-parameters
onExited: {
grabTimeout.stop();
const shots = {};
for (const name of names)
shots[name] = root.runtimeDir + "/lock-" + name + ".png";
root.shots = shots;
root.locked = true;
}
// qmllint enable signal-handler-parameters
}
Timer {
id: grabTimeout
interval: 1500
onTriggered: {
grab.running = false;
root.locked = true;
}
}
onShownChanged: if (shown)
probeKeyboard()
Process {
id: layoutProbe
command: ["hyprctl", "devices", "-j"]
stdout: StdioCollector {
onStreamFinished: {
try {
const keyboards = JSON.parse(text).keyboards || [];
const main = keyboards.find(k => k.main) || keyboards[0];
root.layout = main && main.active_keymap ? main.active_keymap.slice(0, 2).toUpperCase() : "";
root.capsLock = keyboards.some(k => k.capsLock);
} catch (e) {
root.layout = "";
root.capsLock = false;
}
}
}
}
Process {
running: true
command: ["sh", "-c", "getent passwd \"$USER\" | cut -d: -f5 | cut -d, -f1"]
stdout: StdioCollector {
onStreamFinished: root.realName = text.trim()
}
}
IpcHandler {
target: "lock"
function lock(): void {
root.lock();
}
function preview(): void {
root.preview();
}
function closePreview(): void {
root.cancelPreview();
}
function status(): string {
return JSON.stringify({
locked: root.locked,
previewing: root.previewing,
busy: root.busy,
status: root.status,
primary: root.primary,
testResult: root.testResult
});
}
}
}