diff --git a/applet/contents/ui/main.qml b/applet/contents/ui/main.qml --- a/applet/contents/ui/main.qml +++ b/applet/contents/ui/main.qml @@ -18,7 +18,7 @@ along with this program. If not, see . */ -import QtQuick 2.0 +import QtQuick 2.2 import QtQuick.Layouts 1.0 import org.kde.plasma.core 2.0 as PlasmaCore @@ -155,7 +155,7 @@ if (sinkIndex == undefined) { sinkIndex = sinkModel.preferredSink.index; } - feedback.play(sinkIndex); + feedback.sinkIndex = sinkIndex; } Plasmoid.compactRepresentation: PlasmaCore.IconItem { @@ -257,8 +257,26 @@ VolumeFeedback { id: feedback + property int sinkIndex: -1 } + Instantiator { + active: volumeFeedback + model: sinkModel + + QtObject { + readonly property int volume: Volume + + onVolumeChanged: { + if (Index == feedback.sinkIndex) { + feedback.play(Index); + feedback.sinkIndex = -1; + } + } + } + } + + PlasmaComponents.TabBar { id: tabBar diff --git a/src/qml/volumefeedback.cpp b/src/qml/volumefeedback.cpp --- a/src/qml/volumefeedback.cpp +++ b/src/qml/volumefeedback.cpp @@ -53,25 +53,14 @@ return; } - int playing = 0; - const int cindex = 2; // Note "2" is simply the index we've picked. It's somewhat irrelevant. - ca_context_playing(m_context, cindex, &playing); - - // NB Depending on how this is desired to work, we may want to simply - // skip playing, or cancel the currently playing sound and play our - // new one... for now, let's do the latter. - if (playing) { - ca_context_cancel(m_context, cindex); - } - char dev[64]; snprintf(dev, sizeof(dev), "%lu", (unsigned long) sinkIndex); ca_context_change_device(m_context, dev); // Ideally we'd use something like ca_gtk_play_for_widget()... ca_context_play( m_context, - cindex, + 2, // Note "2" is simply the index we've picked. It's somewhat irrelevant. CA_PROP_EVENT_DESCRIPTION, "Volume Control Feedback Sound", CA_PROP_EVENT_ID, "audio-volume-change", CA_PROP_CANBERRA_CACHE_CONTROL, "permanent",