diff --git a/applet/contents/ui/ListItemBase.qml b/applet/contents/ui/ListItemBase.qml --- a/applet/contents/ui/ListItemBase.qml +++ b/applet/contents/ui/ListItemBase.qml @@ -173,10 +173,6 @@ Volume = value; Muted = value == 0; - if (type == "sink") { - playFeedback(CardIndex); - } - if (!pressed) { updateTimer.restart(); } 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 @@ -71,7 +71,6 @@ sinkModel.preferredSink.muted = percent == 0; sinkModel.preferredSink.volume = volume; osd.show(percent); - playFeedback(); } function decreaseVolume() { @@ -83,7 +82,6 @@ sinkModel.preferredSink.muted = percent == 0; sinkModel.preferredSink.volume = volume; osd.show(percent); - playFeedback(); } function muteVolume() { @@ -93,7 +91,6 @@ var toMute = !sinkModel.preferredSink.muted; sinkModel.preferredSink.muted = toMute; osd.show(toMute ? 0 : volumePercent(sinkModel.preferredSink.volume, maxVolumeValue)); - playFeedback(); } function increaseMicrophoneVolume() { @@ -148,16 +145,6 @@ sinkViewHeader.visible = true; } - function playFeedback(sinkIndex) { - if (!volumeFeedback) { - return; - } - if (!sinkIndex) { - sinkIndex = sinkModel.preferredSink.cardIndex; - } - feedback.play(sinkIndex); - } - Plasmoid.compactRepresentation: PlasmaCore.IconItem { source: plasmoid.icon active: mouseArea.containsMouse @@ -259,6 +246,25 @@ id: feedback } + Instantiator { + active: volumeFeedback + model: sinkModel + + QtObject { + property bool firstChange: true + readonly property int volume: Volume + + onVolumeChanged: { + // Don't play feedback after instantiating this object + if (firstChange) { + firstChange = false; + return; + } + feedback.play(Index); + } + } + } + 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",