blob: e7b7b6730e4b93f328794149c44f59572fa3acd5 (
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
import Quickshell
import Quickshell.Io
import Quickshell.Services.Pipewire
import Quickshell.Services.Mpris
import qs.Services
import Custom as Custom
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 if (command.Brightness)
root.onCommandBrightness(command.Brightness);
else if (command.LockSession)
Custom.Systemd.lockSession();
else if (command.Suspend)
Custom.Systemd.suspend();
else if (command.Hibernate)
Custom.Systemd.hibernate();
else if (command.Mpris)
root.onCommandMpris(command.Mpris);
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;
}
function onCommandBrightness(command) {
if (command === "up")
Brightness.currBrightness += 0.02
if (command === "down")
Brightness.currBrightness -= 0.02
}
function onCommandMpris(command) {
if (command.PauseAll)
Array.from(MprisProxy.players).forEach(player => {
if (player.canPause && player.isPlaying)
player.pause();
});
}
}
|