1
0
Fork 0
mirror of https://github.com/polybar/polybar.git synced 2025-02-03 15:35:58 -05:00

pulseaudio: Preserve channel balance (#3169)

Instead of preserving the proportions of PulseAudio channels, we now preserve the balance between the channels. This mirrors pulsemixer's approach.
This commit is contained in:
Nolan Prochnau 2024-10-19 11:35:33 -04:00 committed by GitHub
parent 2d00384046
commit 552d81dd56
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 22 additions and 10 deletions

View file

@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
by [@stringlapse](https://github.com/stringlapse).
### Changed
- `internal/pulseaudio`: Volume adjustments now preserve balance instead of volume ratios ([`#3123`](https://github.com/polybar/polybar/issues/3123), [`#3169`](https://github.com/polybar/polybar/pull/3169)) by [`@parmort`](https://github.com/parmort)
- When the `-r` flag is provided, and RandR reports zero connected active screens, polybar will not restart. This fixes polybar dying on some laptops when the lid is closed. ([`#3078`](https://github.com/polybar/polybar/pull/3078))).
## [3.7.2] - 2024-08-17

View file

@ -195,18 +195,29 @@ void pulseaudio::set_volume(float percentage) {
void pulseaudio::inc_volume(int delta_perc) {
pa_threaded_mainloop_lock(m_mainloop);
pa_volume_t vol = math_util::percentage_to_value<pa_volume_t>(abs(delta_perc), PA_VOLUME_NORM);
if (delta_perc > 0) {
pa_volume_t current = pa_cvolume_max(&cv);
if (current + vol <= m_max_volume) {
pa_cvolume_inc(&cv, vol);
} else if (current < m_max_volume) {
// avoid rounding errors and set to m_max_volume directly
pa_cvolume_scale(&cv, m_max_volume);
} else {
m_log.notice("pulseaudio: maximum volume reached");
for (int i = 0; i < cv.channels; i++) {
if (cv.values[i] + vol <= m_max_volume) {
cv.values[i] += vol;
} else if (cv.values[i] < m_max_volume) {
cv.values[i] = m_max_volume;
} else {
m_log.notice("pulseaudio: maximum volume reached on channel %d", i);
}
}
} else
pa_cvolume_dec(&cv, vol);
} else {
for (int i = 0; i < cv.channels; i++) {
if (cv.values[i] > vol) {
cv.values[i] -= vol;
} else if (cv.values[i] > 0) {
cv.values[i] = 0;
} else {
m_log.notice("pulseaudio: minimum volume reached on channel %d", i);
}
}
}
pa_operation* op = pa_context_set_sink_volume_by_index(m_context, m_index, &cv, simple_callback, this);
wait_loop(op, m_mainloop);
if (!success)