2023-03-16 07:21:01 +00:00
|
|
|
// SPDX-FileCopyrightText: 2023 Devin Lin <devin@kde.org>
|
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
|
2023-10-19 17:39:03 +00:00
|
|
|
pragma Singleton
|
|
|
|
|
|
2023-03-16 07:21:01 +00:00
|
|
|
import QtQuick
|
|
|
|
|
|
|
|
|
|
import org.kde.plasma.private.volume
|
2025-09-13 12:54:11 +00:00
|
|
|
import org.kde.plasma.private.mobileshell as MobileShell
|
2023-03-16 07:21:01 +00:00
|
|
|
|
|
|
|
|
QtObject {
|
2023-03-20 04:10:14 +00:00
|
|
|
id: root
|
|
|
|
|
|
2023-10-17 11:42:33 +00:00
|
|
|
property var config: GlobalConfig {}
|
|
|
|
|
|
2023-03-16 07:21:01 +00:00
|
|
|
property SinkModel paSinkModel: SinkModel {}
|
|
|
|
|
|
|
|
|
|
// whether the audio icon should be visible in the status bar
|
2024-06-24 23:43:43 +00:00
|
|
|
readonly property bool isVisible: PreferredDevice.sink
|
2023-03-16 07:21:01 +00:00
|
|
|
|
|
|
|
|
// the icon that should be displayed in the status bar
|
2024-06-24 23:43:43 +00:00
|
|
|
readonly property string icon: PreferredDevice.sink && !isDummyOutput(PreferredDevice.sink)
|
|
|
|
|
? iconName(PreferredDevice.sink.volume, PreferredDevice.sink.muted)
|
2023-03-16 07:21:01 +00:00
|
|
|
: iconName(0, true)
|
|
|
|
|
|
|
|
|
|
// the name of the audio device when it isn't valid
|
|
|
|
|
readonly property string dummyOutputName: "auto_null"
|
|
|
|
|
|
2023-10-17 11:42:33 +00:00
|
|
|
// the maximum volume amount (percentage)
|
|
|
|
|
readonly property int maxVolumePercent: config.raiseMaximumVolume ? 150 : 100
|
|
|
|
|
|
2023-03-16 07:21:01 +00:00
|
|
|
// the maximum volume amount
|
2023-10-17 11:42:33 +00:00
|
|
|
readonly property int maxVolumeValue: maxVolumePercent * PulseAudio.NormalVolume / 100
|
2023-03-16 07:21:01 +00:00
|
|
|
|
2023-03-20 04:10:14 +00:00
|
|
|
// The current audio volume (updated by connecting to sinks)
|
2025-09-13 23:39:51 +00:00
|
|
|
readonly property int volumeValue: PreferredDevice.sink ? (PreferredDevice.sink.volume / PulseAudio.NormalVolume) * 100 : 0
|
2023-03-20 04:10:14 +00:00
|
|
|
|
2023-03-16 07:21:01 +00:00
|
|
|
function isDummyOutput(output) {
|
|
|
|
|
return output && output.name === dummyOutputName;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function iconName(volume, muted, prefix) {
|
|
|
|
|
if (!prefix) {
|
|
|
|
|
prefix = "audio-volume";
|
|
|
|
|
}
|
|
|
|
|
var icon = null;
|
|
|
|
|
var percent = volume / maxVolumeValue;
|
|
|
|
|
if (percent <= 0.0 || muted) {
|
|
|
|
|
icon = prefix + "-muted";
|
|
|
|
|
} else if (percent <= 0.25) {
|
|
|
|
|
icon = prefix + "-low";
|
|
|
|
|
} else if (percent <= 0.75) {
|
|
|
|
|
icon = prefix + "-medium";
|
|
|
|
|
} else {
|
|
|
|
|
icon = prefix + "-high";
|
|
|
|
|
}
|
|
|
|
|
return icon;
|
|
|
|
|
}
|
|
|
|
|
}
|