Change scroll-step unit to percent

pull/316/head
Olegs Jeremejevs 2019-05-14 15:24:06 +08:00
parent a1ffa7fa9f
commit d5c1e6f312
2 changed files with 8 additions and 2 deletions

View File

@ -111,7 +111,7 @@
"format-disconnected": "Disconnected ⚠" "format-disconnected": "Disconnected ⚠"
}, },
"pulseaudio": { "pulseaudio": {
//"scroll-step": 1, // "scroll-step": 1, // %, can be a float
"format": "{volume}% {icon}", "format": "{volume}% {icon}",
"format-bluetooth": "{volume}% {icon}", "format-bluetooth": "{volume}% {icon}",
"format-muted": "", "format-muted": "",

View File

@ -77,7 +77,8 @@ bool waybar::modules::Pulseaudio::handleVolume(GdkEventScroll *e) {
return false; return false;
} }
bool direction_up = 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_; pa_cvolume pa_volume = pa_volume_;
scrolling_ = true; scrolling_ = true;
if (e->direction == GDK_SCROLL_UP) { 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 (direction_up) {
if (volume_ + 1 < 100) { if (volume_ + 1 < 100) {
pa_cvolume_inc(&pa_volume, change); pa_cvolume_inc(&pa_volume, change);