diff options
Diffstat (limited to 'accounts/gkleen@sif/shell/quickshell/UnixIPC.qml')
-rw-r--r-- | accounts/gkleen@sif/shell/quickshell/UnixIPC.qml | 59 |
1 files changed, 59 insertions, 0 deletions
diff --git a/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml b/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml new file mode 100644 index 00000000..742ef4f5 --- /dev/null +++ b/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml | |||
@@ -0,0 +1,59 @@ | |||
1 | import Quickshell | ||
2 | import Quickshell.Io | ||
3 | import Quickshell.Services.Pipewire | ||
4 | import qs.Services | ||
5 | |||
6 | Scope { | ||
7 | id: root | ||
8 | |||
9 | SocketServer { | ||
10 | active: true | ||
11 | path: `${Quickshell.env("XDG_RUNTIME_DIR")}/shell.sock` | ||
12 | handler: Socket { | ||
13 | parser: SplitParser { | ||
14 | onRead: line => { | ||
15 | try { | ||
16 | const command = JSON.parse(line); | ||
17 | |||
18 | if (command.Volume) | ||
19 | root.onCommandVolume(command.Volume); | ||
20 | else if (command.Brightness) | ||
21 | root.onCommandBrightness(command.Brightness); | ||
22 | else | ||
23 | console.warn("UnixIPC: Command not handled:", JSON.stringify(command)); | ||
24 | } catch (e) { | ||
25 | console.warn("UnixIPC: Failed to parse command:", line, e); | ||
26 | } | ||
27 | } | ||
28 | } | ||
29 | |||
30 | onError: e => { | ||
31 | if (e == 1) | ||
32 | return; | ||
33 | console.warn("QLocalSocket::LocalSocketError", e); | ||
34 | } | ||
35 | } | ||
36 | } | ||
37 | |||
38 | PwObjectTracker { | ||
39 | objects: [ Pipewire.defaultAudioSink, Pipewire.defaultAudioSource ] | ||
40 | } | ||
41 | function onCommandVolume(command) { | ||
42 | if (command.muted === "toggle") | ||
43 | Pipewire.defaultAudioSink.audio.muted = !Pipewire.defaultAudioSink.audio.muted; | ||
44 | if (command.volume === "up") | ||
45 | Pipewire.defaultAudioSink.audio.volume += 0.02; | ||
46 | if (command.volume === "down") | ||
47 | Pipewire.defaultAudioSink.audio.volume -= 0.02; | ||
48 | |||
49 | if (command["mic-muted"] === "toggle") | ||
50 | Pipewire.defaultAudioSource.audio.muted = !Pipewire.defaultAudioSource.audio.muted; | ||
51 | } | ||
52 | |||
53 | function onCommandBrightness(command) { | ||
54 | if (command === "up") | ||
55 | Brightness.currBrightness += 0.02 | ||
56 | if (command === "down") | ||
57 | Brightness.currBrightness -= 0.02 | ||
58 | } | ||
59 | } | ||