From ae9a80c1f012686c1f65fce7ce76fdd1b77b0b71 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Wed, 23 Sep 2026 21:08:35 +0200 Subject: ... --- .../gkleen@skadhi/shell/quickshell/UnixIPC.qml | 106 +++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 accounts/gkleen@skadhi/shell/quickshell/UnixIPC.qml (limited to 'accounts/gkleen@skadhi/shell/quickshell/UnixIPC.qml') diff --git a/accounts/gkleen@skadhi/shell/quickshell/UnixIPC.qml b/accounts/gkleen@skadhi/shell/quickshell/UnixIPC.qml new file mode 100644 index 00000000..3d950031 --- /dev/null +++ b/accounts/gkleen@skadhi/shell/quickshell/UnixIPC.qml @@ -0,0 +1,106 @@ +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 if (command.ScreenRecord) + root.onCommandScreenRecord(command.ScreenRecord); + 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.active) { + if (NotificationManager.groups.length > 0) + for (const notif of [...NotificationManager.groups[0]]) + notif.dismiss(); + } + if (command.DismissAll && NotificationManager.active) { + for (const notif of [...NotificationManager.trackedNotifications.values]) + notif.dismiss(); + } + } + + function onCommandScreenRecord(command) { + if (command.Toggle) + ScreenRecord.active = !ScreenRecord.active; + else + console.warn("UnixIPC.ScreenRecord: Command not handled:", JSON.stringify(command)); + } +} -- cgit v1.2.3