summaryrefslogtreecommitdiff
path: root/accounts/gkleen@skadhi/shell/quickshell/Lockscreen.qml
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/gkleen@skadhi/shell/quickshell/Lockscreen.qml')
-rw-r--r--accounts/gkleen@skadhi/shell/quickshell/Lockscreen.qml128
1 files changed, 128 insertions, 0 deletions
diff --git a/accounts/gkleen@skadhi/shell/quickshell/Lockscreen.qml b/accounts/gkleen@skadhi/shell/quickshell/Lockscreen.qml
new file mode 100644
index 00000000..0b4a68b2
--- /dev/null
+++ b/accounts/gkleen@skadhi/shell/quickshell/Lockscreen.qml
@@ -0,0 +1,128 @@
1import Quickshell
2import Quickshell.Wayland
3import Quickshell.Io
4import Quickshell.Services.Pam
5import Quickshell.Services.Mpris
6import Custom as Custom
7import qs.Services
8import QtQml
9
10Scope {
11 id: lockscreen
12
13 property string currentText: ""
14
15 PamContext {
16 id: pam
17
18 property list<var> messages: []
19
20 config: "quickshell"
21 onCompleted: result => {
22 if (result === PamResult.Success) {
23 lock.locked = false;
24 }
25 }
26 onPamMessage: {
27 messages = Array.from(messages).concat([{ "text": pam.message, "error": pam.messageIsError }])
28 }
29 onActiveChanged: {
30 messages = [];
31 }
32 }
33
34 Connections {
35 target: Custom.Systemd
36 function onSleep(before: bool) {
37 console.log(`received prepare for sleep ${before}`);
38 if (before) {
39 lock.locked = true;
40 if (pam.active)
41 pam.abort();
42 }
43 }
44 function onLock() { lock.locked = true; }
45 function onUnlock() { lock.locked = false; }
46 }
47
48 IdleMonitor {
49 id: idleMonitor
50 enabled: !lock.secure && !InhibitorState.lockscreenInhibited
51 timeout: 600
52 respectInhibitors: true
53
54 onIsIdleChanged: {
55 if (idleMonitor.isIdle)
56 lock.locked = true;
57 }
58 }
59
60 Custom.SystemdInhibitor {
61 enabled: !lock.secure
62
63 what: Custom.SystemdInhibitorParams.Sleep
64 who: "quickshell"
65 why: "Lock session"
66 mode: Custom.SystemdInhibitorParams.Delay
67 }
68
69 Binding {
70 target: NotificationManager
71 property: "lockscreenActive"
72 value: lock.locked
73 }
74
75 WlSessionLock {
76 id: lock
77
78 onLockStateChanged: {
79 if (!locked && pam.active)
80 pam.abort();
81
82 if (locked) {
83 NiriService.sendCommand({ "Action": { "PowerOffMonitors": {} } }, _ => {});
84 Custom.KeePassXC.lockAllDatabases();
85 Array.from(MprisProxy.players).forEach(player => {
86 if (player.canPause && player.isPlaying)
87 player.pause();
88 });
89 // Custom.Systemd.stopUserUnit("gpg-agent.service", "replace");
90 GpgAgent.reloadAgent();
91 }
92 }
93 Component.onCompleted: { (_ => {})(MprisProxy.players); }
94
95 onSecureStateChanged: Custom.Systemd.lockedHint = lock.secure
96
97 WlSessionLockSurface {
98 id: lockSurface
99
100 color: "black"
101
102 LockSurface {
103 id: surfaceContent
104
105 onResponse: responseText => pam.respond(responseText)
106 onAuthRunningChanged: {
107 if (authRunning)
108 pam.start();
109 }
110 Connections {
111 target: pam
112 function onMessagesChanged() { surfaceContent.messages = pam.messages; }
113 function onResponseRequiredChanged() { surfaceContent.responseRequired = pam.responseRequired; }
114 function onActiveChanged() { surfaceContent.authRunning = pam.active; }
115 }
116 onCurrentTextChanged: lockscreen.currentText = currentText
117 Connections {
118 target: lockscreen
119 function onCurrentTextChanged() { surfaceContent.currentText = lockscreen.currentText; }
120 }
121 Connections {
122 target: lockSurface
123 function onScreenChanged() { surfaceContent.screen = lockSurface.screen; }
124 }
125 }
126 }
127 }
128}