From bef5359702c6300fda097f56681e5d2820d62613 Mon Sep 17 00:00:00 2001 From: Robin Seger Date: Tue, 23 Sep 2025 10:04:21 +0200 Subject: audio: audio device changed toasts (#684) * Added toast notifications for audio device changes * rename to toasts * moved into audio service * fixes --------- Co-authored-by: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> --- README.md | 6 +++++- config/UtilitiesConfig.qml | 6 ++++++ services/Audio.qml | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 71aedbf..f72ecdc 100644 --- a/README.md +++ b/README.md @@ -567,7 +567,11 @@ default, you must create it manually. }, "utilities": { "enabled": true, - "maxToasts": 4 + "maxToasts": 4, + "toasts": { + "audioOutputChanged": true, + "audioInputChanged": true + } } } ``` diff --git a/config/UtilitiesConfig.qml b/config/UtilitiesConfig.qml index d9d4ed5..c1bad2a 100644 --- a/config/UtilitiesConfig.qml +++ b/config/UtilitiesConfig.qml @@ -5,8 +5,14 @@ JsonObject { property int maxToasts: 4 property Sizes sizes: Sizes {} + property Toasts toasts: Toasts {} component Sizes: JsonObject { property int width: 430 } + + component Toasts: JsonObject { + property bool audioOutputChanged: true + property bool audioInputChanged: true + } } diff --git a/services/Audio.qml b/services/Audio.qml index 95990c5..bc87d46 100644 --- a/services/Audio.qml +++ b/services/Audio.qml @@ -2,12 +2,17 @@ pragma Singleton import qs.config import Caelestia.Services +import Caelestia import Quickshell import Quickshell.Services.Pipewire +import QtQuick Singleton { id: root + property string previousSinkName: "" + property string previousSourceName: "" + readonly property var nodes: Pipewire.nodes.values.reduce((acc, node) => { if (!node.isStream) { if (node.isSink) @@ -74,6 +79,35 @@ Singleton { Pipewire.preferredDefaultAudioSource = newSource; } + onSinkChanged: { + if (!sink?.ready) + return; + + const newSinkName = sink.description || sink.name || qsTr("Unknown Device"); + + if (previousSinkName && previousSinkName !== newSinkName && Config.utilities.toasts.audioOutputChanged) + Toaster.toast(qsTr("Audio output changed"), qsTr("Now using: %1").arg(newSinkName), "volume_up"); + + previousSinkName = newSinkName; + } + + onSourceChanged: { + if (!source?.ready) + return; + + const newSourceName = source.description || source.name || qsTr("Unknown Device"); + + if (previousSourceName && previousSourceName !== newSourceName && Config.utilities.toasts.audioInputChanged) + Toaster.toast(qsTr("Audio input changed"), qsTr("Now using: %1").arg(newSourceName), "mic"); + + previousSourceName = newSourceName; + } + + Component.onCompleted: { + previousSinkName = sink?.description || sink?.name || qsTr("Unknown Device"); + previousSourceName = source?.description || source?.name || qsTr("Unknown Device"); + } + PwObjectTracker { objects: [...root.sinks, ...root.sources] } -- cgit v1.2.3-freya