volumeosd: fix maximum volume behaviour

This commit is contained in:
Yari Polla 2023-10-17 13:42:33 +02:00
parent a762e136ea
commit e6ddb4f3c4
3 changed files with 17 additions and 16 deletions

View file

@ -8,6 +8,8 @@ import org.kde.plasma.private.volume
QtObject { QtObject {
id: root id: root
property var config: GlobalConfig {}
property SinkModel paSinkModel: SinkModel {} property SinkModel paSinkModel: SinkModel {}
// whether the audio icon should be visible in the status bar // whether the audio icon should be visible in the status bar
@ -21,8 +23,11 @@ QtObject {
// the name of the audio device when it isn't valid // the name of the audio device when it isn't valid
readonly property string dummyOutputName: "auto_null" readonly property string dummyOutputName: "auto_null"
// the maximum volume amount (percentage)
readonly property int maxVolumePercent: config.raiseMaximumVolume ? 150 : 100
// the maximum volume amount // the maximum volume amount
readonly property int maxVolumeValue: Math.round(100 * PulseAudio.NormalVolume / 100.0) readonly property int maxVolumeValue: maxVolumePercent * PulseAudio.NormalVolume / 100
// step that increments when adjusting the volume // step that increments when adjusting the volume
readonly property int volumeStep: Math.round(5 * PulseAudio.NormalVolume / 100.0) readonly property int volumeStep: Math.round(5 * PulseAudio.NormalVolume / 100.0)
@ -42,7 +47,7 @@ QtObject {
if (!max) { if (!max) {
max = PulseAudio.NormalVolume; max = PulseAudio.NormalVolume;
} }
return Math.round(volume / max * 100.0); return Math.round(volume / max * maxVolumePercent);
} }
function increaseVolume() { function increaseVolume() {

View file

@ -22,7 +22,7 @@ import "../dataproviders" as DataProviders
NanoShell.FullScreenOverlay { NanoShell.FullScreenOverlay {
id: window id: window
required property int volume required property var audioInfo
// used by context menus opened in the applet to not autoclose the osd // used by context menus opened in the applet to not autoclose the osd
property bool suppressActiveClose: false property bool suppressActiveClose: false
@ -64,10 +64,6 @@ NanoShell.FullScreenOverlay {
} }
} }
DataProviders.AudioInfo {
id: audioInfo
}
Flickable { Flickable {
id: flickable id: flickable
anchors.fill: parent anchors.fill: parent
@ -108,8 +104,8 @@ NanoShell.FullScreenOverlay {
anchors.rightMargin: Kirigami.Units.smallSpacing anchors.rightMargin: Kirigami.Units.smallSpacing
PlasmaComponents.ToolButton { PlasmaComponents.ToolButton {
icon.name: !audioInfo.paSinkModel.preferredSink || audioInfo.paSinkModel.preferredSink.muted ? "audio-volume-muted" : "audio-volume-high" icon.name: !window.audioInfo.paSinkModel.preferredSink || window.audioInfo.paSinkModel.preferredSink.muted ? "audio-volume-muted" : "audio-volume-high"
text: !audioInfo.paSinkModel.preferredSink || audioInfo.paSinkModel.preferredSink.muted ? i18n("Unmute") : i18n("Mute") text: !window.audioInfo.paSinkModel.preferredSink || window.audioInfo.paSinkModel.preferredSink.muted ? i18n("Unmute") : i18n("Mute")
display: Controls.AbstractButton.IconOnly display: Controls.AbstractButton.IconOnly
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
Layout.preferredWidth: Kirigami.Units.iconSizes.medium Layout.preferredWidth: Kirigami.Units.iconSizes.medium
@ -123,9 +119,9 @@ NanoShell.FullScreenOverlay {
Layout.fillWidth: true Layout.fillWidth: true
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
Layout.rightMargin: Kirigami.Units.smallSpacing * 2 Layout.rightMargin: Kirigami.Units.smallSpacing * 2
value: window.volume value: window.audioInfo.volumeValue
from: 0 from: 0
to: 100 to: window.audioInfo.maxVolumePercent
Behavior on value { NumberAnimation { duration: Kirigami.Units.shortDuration } } Behavior on value { NumberAnimation { duration: Kirigami.Units.shortDuration } }
} }
@ -143,7 +139,7 @@ NanoShell.FullScreenOverlay {
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
Layout.rightMargin: Kirigami.Units.smallSpacing Layout.rightMargin: Kirigami.Units.smallSpacing
level: 3 level: 3
text: i18nc("Percentage value", "%1%", window.volume) text: i18nc("Percentage value", "%1%", window.audioInfo.volumeValue)
// Display a subtle visual indication that the volume might be // Display a subtle visual indication that the volume might be
// dangerously high // dangerously high
@ -151,9 +147,9 @@ NanoShell.FullScreenOverlay {
// Keep this in sync with the copies in plasma-pa:ListItemBase.qml // Keep this in sync with the copies in plasma-pa:ListItemBase.qml
// and plasma-pa:VolumeSlider.qml // and plasma-pa:VolumeSlider.qml
color: { color: {
if (volumeSlider.value <= 100) { if (window.audioInfo.volumeValue <= 100) {
return Kirigami.Theme.textColor return Kirigami.Theme.textColor
} else if (volumeSlider.value > 100 && volumeSlider.value <= 125) { } else if (window.audioInfo.volumeValue > 100 && window.audioInfo.volumeValue <= 125) {
return Kirigami.Theme.neutralTextColor return Kirigami.Theme.neutralTextColor
} else { } else {
return Kirigami.Theme.negativeTextColor return Kirigami.Theme.negativeTextColor
@ -208,7 +204,7 @@ NanoShell.FullScreenOverlay {
Layout.alignment: Qt.AlignHCenter Layout.alignment: Qt.AlignHCenter
Layout.preferredWidth: cards.width Layout.preferredWidth: cards.width
audioInfo: audioInfo audioInfo: window.audioInfo
opacity: window.showFullApplet ? 1 : 0 opacity: window.showFullApplet ? 1 : 0
visible: opacity !== 0 visible: opacity !== 0

View file

@ -39,7 +39,7 @@ QtObject {
} }
property var osd: VolumeOSD { property var osd: VolumeOSD {
volume: component.audioInfo.volumeValue audioInfo: component.audioInfo
} }
property var actionCollection: VolumeLib.GlobalActionCollection { property var actionCollection: VolumeLib.GlobalActionCollection {