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.qml108
1 files changed, 108 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..483a60c6
--- /dev/null
+++ b/accounts/gkleen@skadhi/shell/quickshell/UnixIPC.qml
@@ -0,0 +1,108 @@
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.Sleep)
35 Custom.Systemd.sleep();
36 else if (command.Suspend)
37 Custom.Systemd.suspend();
38 else if (command.Hibernate)
39 Custom.Systemd.hibernate();
40 else if (command.Mpris)
41 root.onCommandMpris(command.Mpris);
42 else if (command.Notifications)
43 root.onCommandNotifications(command.Notifications);
44 else if (command.ScreenRecord)
45 root.onCommandScreenRecord(command.ScreenRecord);
46 else
47 console.warn("UnixIPC: Command not handled:", JSON.stringify(command));
48 }
49 }
50
51 onError: e => {
52 if (e == 1)
53 return;
54 console.warn("QLocalSocket::LocalSocketError", e);
55 }
56 }
57 }
58
59 PwObjectTracker {
60 objects: [ Pipewire.defaultAudioSink, Pipewire.defaultAudioSource ]
61 }
62 function onCommandVolume(command) {
63 if (command.muted === "toggle")
64 Pipewire.defaultAudioSink.audio.muted = !Pipewire.defaultAudioSink.audio.muted;
65 if (command.volume === "up")
66 Pipewire.defaultAudioSink.audio.volume += 0.02;
67 if (command.volume === "down")
68 Pipewire.defaultAudioSink.audio.volume -= 0.02;
69
70 if (command["mic-muted"] === "toggle")
71 Pipewire.defaultAudioSource.audio.muted = !Pipewire.defaultAudioSource.audio.muted;
72 }
73
74 function onCommandBrightness(command) {
75 if (command === "up")
76 Brightness.currBrightness += 0.02
77 if (command === "down")
78 Brightness.currBrightness -= 0.02
79 }
80
81 function onCommandMpris(command) {
82 if (command.PauseAll)
83 Array.from(MprisProxy.players).forEach(player => {
84 if (player.canPause && player.isPlaying)
85 player.pause();
86 });
87 }
88 Component.onCompleted: { (_ => {})(MprisProxy.players); }
89
90 function onCommandNotifications(command) {
91 if (command.DismissGroup && NotificationManager.active) {
92 if (NotificationManager.groups.length > 0)
93 for (const notif of [...NotificationManager.groups[0]])
94 notif.dismiss();
95 }
96 if (command.DismissAll && NotificationManager.active) {
97 for (const notif of [...NotificationManager.trackedNotifications.values])
98 notif.dismiss();
99 }
100 }
101
102 function onCommandScreenRecord(command) {
103 if (command.Toggle)
104 ScreenRecord.active = !ScreenRecord.active;
105 else
106 console.warn("UnixIPC.ScreenRecord: Command not handled:", JSON.stringify(command));
107 }
108}