Commit b0f7cfcc authored by Nate Graham's avatar Nate Graham 🔩
Browse files

Round volume to avoid increasing or decreasing by more than stepSize

Sometimes when you increase or decrease the volume using the key on your
keyboard or a global shortcut, it will change by more than the stepSize.
For example when you're at 40% volume and go up when a stepSize of 5%,
sometimes it will change to 46% volume, not 45%.

The reason for this is that the Volume number we get from PulseAudio and
then manipulate is a float. So we have to round it down to avoid
accumulating errors over time. The percentage display function already
rounds, so let's do the same thing in the functions to increase and
decrease the volume.

We should also use Math.floor() rather than Math.round() to ensure
consistency in the values we're using.

BUG: 434769
FIXED-IN: 5.21.4

(cherry picked from commit 52cb6b0e)
parent b5313226
......@@ -83,11 +83,11 @@ Item {
function boundVolume(volume) {
return Math.max(PulseAudio.MinimalVolume, Math.min(volume, currentMaxVolumeValue));
return Math.max(PulseAudio.MinimalVolume, Math.min(Math.floor(volume), currentMaxVolumeValue));
function volumePercent(volume) {
return Math.round(volume / PulseAudio.NormalVolume * 100.0);
return Math.floor(volume / PulseAudio.NormalVolume * 100.0);
function increaseVolume() {
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment