Change scroll-step unit to percent (#316)

Change scroll-step unit to percent
This commit is contained in:
Alex 2019-05-17 09:44:34 +02:00 committed by GitHub
commit cddee2626a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 2 deletions

View File

@ -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": "",

View File

@ -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);