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 {
id: root
property var config: GlobalConfig {}
property SinkModel paSinkModel: SinkModel {}
// 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
readonly property string dummyOutputName: "auto_null"
// the maximum volume amount (percentage)
readonly property int maxVolumePercent: config.raiseMaximumVolume ? 150 : 100
// 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
readonly property int volumeStep: Math.round(5 * PulseAudio.NormalVolume / 100.0)
@ -42,7 +47,7 @@ QtObject {
if (!max) {
max = PulseAudio.NormalVolume;
}
return Math.round(volume / max * 100.0);
return Math.round(volume / max * maxVolumePercent);
}
function increaseVolume() {

View file

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

View file

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