import Quickshell import Quickshell.Io import Quickshell.Services.Pipewire import Quickshell.Services.Mpris import qs.Services import Custom as Custom import QtQml Scope { id: root SocketServer { active: true path: `${Quickshell.env("XDG_RUNTIME_DIR")}/shell.sock` handler: Socket { parser: SplitParser { onRead: line => { const command = (() => { try { return JSON.parse(line); } catch (e) { console.warn("UnixIPC: Failed to parse command:", line, e); } })(); if (!command) return; 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 if (command.Notifications) root.onCommandNotifications(command.Notifications); else console.warn("UnixIPC: Command not handled:", JSON.stringify(command)); } } 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(); }); } Component.onCompleted: { (_ => {})(MprisProxy.players); } function onCommandNotifications(command) { if (command.DismissGroup && !NotificationManager.displayInhibited) { if (NotificationManager.groups.length > 0) for (const notif of [...NotificationManager.groups[0]]) notif.dismiss(); } if (command.DismissAll && !NotificationManager.displayInhibited) { for (const notif of [...NotificationManager.trackedNotifications.values]) notif.dismiss(); } } }