summaryrefslogtreecommitdiff
path: root/accounts/gkleen@skadhi/shell/quickshell/UnixIPC.qml
diff options
context:
space:
mode:
Diffstat (limited to 'accounts/gkleen@skadhi/shell/quickshell/UnixIPC.qml')
-rw-r--r--accounts/gkleen@skadhi/shell/quickshell/UnixIPC.qml106
1 files changed, 106 insertions, 0 deletions
diff --git a/accounts/gkleen@skadhi/shell/quickshell/UnixIPC.qml b/accounts/gkleen@skadhi/shell/quickshell/UnixIPC.qml
new file mode 100644
index 00000000..3d950031
--- /dev/null
+++ b/accounts/gkleen@skadhi/shell/quickshell/UnixIPC.qml
@@ -0,0 +1,106 @@
1import Quickshell
2import Quickshell.Io
3import Quickshell.Services.Pipewire
4import Quickshell.Services.Mpris
5import qs.Services
6import Custom as Custom
7import QtQml
8
9Scope {
10 id: root
11
12 SocketServer {
13 active: true
14 path: `${Quickshell.env("XDG_RUNTIME_DIR")}/shell.sock`
15 handler: Socket {
16 parser: SplitParser {
17 onRead: line => {
18 const command = (() => {
19 try {
20 return JSON.parse(line);
21 } catch (e) {
22 console.warn("UnixIPC: Failed to parse command:", line, e);
23 }
24 })();
25 if (!command)
26 return;
27
28 if (command.Volume)
29 root.onCommandVolume(command.Volume);
30 else if (command.Brightness)
31 root.onCommandBrightness(command.Brightness);
32 else if (command.LockSession)
33 Custom.Systemd.lockSession();
34 else if (command.Suspend)
35 Custom.Systemd.suspend();
36 else if (command.Hibernate)
37 Custom.Systemd.hibernate();
38 else if (command.Mpris)
39 root.onCommandMpris(command.Mpris);
40 else if (command.Notifications)
41 root.onCommandNotifications(command.Notifications);
42 else if (command.ScreenRecord)
43 root.onCommandScreenRecord(command.ScreenRecord);
44 else
45 console.warn("UnixIPC: Command not handled:", JSON.stringify(command));
46 }
47 }
48
49 onError: e => {
50 if (e == 1)
51 return;
52 console.warn("QLocalSocket::LocalSocketError", e);
53 }
54 }
55 }
56
57 PwObjectTracker {
58 objects: [ Pipewire.defaultAudioSink, Pipewire.defaultAudioSource ]
59 }
60 function onCommandVolume(command) {
61 if (command.muted === "toggle")
62 Pipewire.defaultAudioSink.audio.muted = !Pipewire.defaultAudioSink.audio.muted;
63 if (command.volume === "up")
64 Pipewire.defaultAudioSink.audio.volume += 0.02;
65 if (command.volume === "down")
66 Pipewire.defaultAudioSink.audio.volume -= 0.02;
67
68 if (command["mic-muted"] === "toggle")
69 Pipewire.defaultAudioSource.audio.muted = !Pipewire.defaultAudioSource.audio.muted;
70 }
71
72 function onCommandBrightness(command) {
73 if (command === "up")
74 Brightness.currBrightness += 0.02
75 if (command === "down")
76 Brightness.currBrightness -= 0.02
77 }
78
79 function onCommandMpris(command) {
80 if (command.PauseAll)
81 Array.from(MprisProxy.players).forEach(player => {
82 if (player.canPause && player.isPlaying)
83 player.pause();
84 });
85 }
86 Component.onCompleted: { (_ => {})(MprisProxy.players); }
87
88 function onCommandNotifications(command) {
89 if (command.DismissGroup && NotificationManager.active) {
90 if (NotificationManager.groups.length > 0)
91 for (const notif of [...NotificationManager.groups[0]])
92 notif.dismiss();
93 }
94 if (command.DismissAll && NotificationManager.active) {
95 for (const notif of [...NotificationManager.trackedNotifications.values])
96 notif.dismiss();
97 }
98 }
99
100 function onCommandScreenRecord(command) {
101 if (command.Toggle)
102 ScreenRecord.active = !ScreenRecord.active;
103 else
104 console.warn("UnixIPC.ScreenRecord: Command not handled:", JSON.stringify(command));
105 }
106}