summaryrefslogtreecommitdiff
path: root/accounts/gkleen@sif/shell/quickshell/UnixIPC.qml
blob: 7b308ec04587c4fc497b5e3b7aea798469610d93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import Quickshell
import Quickshell.Io
import Quickshell.Services.Pipewire

Scope {
  id: root

  SocketServer {
    active: true
    path: `${Quickshell.env("XDG_RUNTIME_DIR")}/shell.sock`
    handler: Socket {
      parser: SplitParser {
        onRead: line => {
	  try {
	    const command = JSON.parse(line);

	    if (command.Volume)
	      root.onCommandVolume(command.Volume);
	    else
	      console.warn("UnixIPC: Command not handled:", JSON.stringify(command));
	  } catch (e) {
	    console.warn("UnixIPC: Failed to parse command:", line, e);
	  }
	}
      }

      onError: e => {
        if (e == 1)
	  return;
        console.warn("QLocalSocket::LocalSocketError", e);
      }
    }
  }

  PwObjectTracker {
    objects: [ Pipewire.defaultAudioSink, Pipewire.defaultAudioSource ]
  }
  function onCommandVolume(command) {
    if (command.muted === "toggle")
      Pipewire.defaultAudioSink.audio.muted = !Pipewire.defaultAudioSink.audio.muted;
    if (command.volume === "up")
      Pipewire.defaultAudioSink.audio.volume += 0.02;
    if (command.volume === "down")
      Pipewire.defaultAudioSink.audio.volume -= 0.02;

    if (command["mic-muted"] === "toggle")
      Pipewire.defaultAudioSource.audio.muted = !Pipewire.defaultAudioSource.audio.muted;
  }
}