summaryrefslogtreecommitdiff
path: root/kde-plasma/plasma-pa/files/plasma-pa-5.27.6-make-setGenericVolume-keep-balance.patch
blob: 2067a4fd97429e64d33468a52f242c6616726e02 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
From ffe6a4f4b6f56296165cea8651f35563d168ac89 Mon Sep 17 00:00:00 2001
From: Quinten Kock <quintenkock@gmail.com>
Date: Wed, 21 Jun 2023 20:51:11 +0200
Subject: [PATCH] Make setGenericVolume keep balance between channels

Previously setGenericVolume would apply the same amount of difference
on all channels, making e.g. 100%/50% -> 80%/30%.

This commit changes it to keep the ratios equal instead, so that the
resulting volume would be 80%/40%, keeping the balance the same.

BUG: 435840
FIXED-IN: 5.27.7


(cherry picked from commit cfe4a360f2640d7bd4e2d936804b100a299b268a)
---
 src/context.h | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/src/context.h b/src/context.h
index 3d1f7525..969fa13b 100644
--- a/src/context.h
+++ b/src/context.h
@@ -123,9 +123,12 @@ public:
         newVolume = qBound<qint64>(0, newVolume, PA_VOLUME_MAX);
         pa_cvolume newCVolume = cVolume;
         if (channel == -1) { // -1 all channels
-            const qint64 diff = newVolume - pa_cvolume_max(&cVolume);
+            const qint64 orig = pa_cvolume_max(&cVolume);
+            const qint64 diff = newVolume - orig;
             for (int i = 0; i < newCVolume.channels; ++i) {
-                newCVolume.values[i] = qBound<qint64>(0, newCVolume.values[i] + diff, PA_VOLUME_MAX);
+                const qint64 channel = newCVolume.values[i];
+                const qint64 channelDiff = orig == 0 ? diff : diff * channel / orig;
+                newCVolume.values[i] = qBound<qint64>(0, newCVolume.values[i] + channelDiff, PA_VOLUME_MAX);
             }
         } else {
             Q_ASSERT(newCVolume.channels > channel);
-- 
GitLab