From d5c1e6f3122902b4eb056e6ebe8fa43f6289659a Mon Sep 17 00:00:00 2001 From: Olegs Jeremejevs Date: Tue, 14 May 2019 15:24:06 +0800 Subject: [PATCH] Change scroll-step unit to percent --- resources/config | 2 +- src/modules/pulseaudio.cpp | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/resources/config b/resources/config index 69da70fc..f5349895 100644 --- a/resources/config +++ b/resources/config @@ -111,7 +111,7 @@ "format-disconnected": "Disconnected ⚠" }, "pulseaudio": { - //"scroll-step": 1, + // "scroll-step": 1, // %, can be a float "format": "{volume}% {icon}", "format-bluetooth": "{volume}% {icon}", "format-muted": "", diff --git a/src/modules/pulseaudio.cpp b/src/modules/pulseaudio.cpp index 099b1dc4..97c37936 100644 --- a/src/modules/pulseaudio.cpp +++ b/src/modules/pulseaudio.cpp @@ -77,7 +77,8 @@ bool waybar::modules::Pulseaudio::handleVolume(GdkEventScroll *e) { return false; } bool direction_up = false; - uint16_t change = config_["scroll-step"].isUInt() ? config_["scroll-step"].asUInt() * 100 : 100; + double volume_tick = (double)PA_VOLUME_NORM / 100; + pa_volume_t change = volume_tick; pa_cvolume pa_volume = pa_volume_; scrolling_ = true; if (e->direction == GDK_SCROLL_UP) { @@ -97,6 +98,11 @@ bool waybar::modules::Pulseaudio::handleVolume(GdkEventScroll *e) { } } + // isDouble returns true for integers as well, just in case + if (config_["scroll-step"].isDouble()) { + change = round(config_["scroll-step"].asDouble() * volume_tick); + } + if (direction_up) { if (volume_ + 1 < 100) { pa_cvolume_inc(&pa_volume, change);