From d22fd3bbd1b09809cc025ca6b5b50015fba8acbd Mon Sep 17 00:00:00 2001 From: Evyatar Stalinsky Date: Tue, 6 Jun 2023 11:42:02 +0300 Subject: [PATCH] Use a minimum step as provided by wireplubmer; Default step to 1 --- include/modules/wireplumber.hpp | 2 +- src/modules/wireplumber.cpp | 13 +++++++------ 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/include/modules/wireplumber.hpp b/include/modules/wireplumber.hpp index 81b2e68d..9bbf4d46 100644 --- a/include/modules/wireplumber.hpp +++ b/include/modules/wireplumber.hpp @@ -38,7 +38,7 @@ class Wireplumber : public ALabel { uint32_t pending_plugins_; bool muted_; double volume_; - double step_; + double min_step_; uint32_t node_id_{0}; std::string node_name_; }; diff --git a/src/modules/wireplumber.cpp b/src/modules/wireplumber.cpp index 1d8d1f8d..cd02d42e 100644 --- a/src/modules/wireplumber.cpp +++ b/src/modules/wireplumber.cpp @@ -15,7 +15,7 @@ waybar::modules::Wireplumber::Wireplumber(const std::string& id, const Json::Val pending_plugins_(0), muted_(false), volume_(0.0), - step_(0.0), + min_step_(0.0), node_id_(0) { wp_init(WP_INIT_PIPEWIRE); wp_core_ = wp_core_new(NULL, NULL); @@ -103,7 +103,7 @@ void waybar::modules::Wireplumber::updateVolume(waybar::modules::Wireplumber* se } g_variant_lookup(variant, "volume", "d", &self->volume_); - g_variant_lookup(variant, "step", "d", &self->step_); + g_variant_lookup(variant, "step", "d", &self->min_step_); g_variant_lookup(variant, "mute", "b", &self->muted_); g_clear_pointer(&variant, g_variant_unref); @@ -324,15 +324,16 @@ bool waybar::modules::Wireplumber::handleScroll(GdkEventScroll* e) { } } double max_volume = 1; - double step = step_; - // isDouble returns true for integers as well, just in case + double step = 1.0 / 100.0; if (config_["scroll-step"].isDouble()) { step = config_["scroll-step"].asDouble() / 100.0; } - if (config_["max-volume"].isInt()) { - max_volume = config_["max-volume"].asInt() / 100.0; + if (config_["max-volume"].isDouble()) { + max_volume = config_["max-volume"].asDouble() / 100.0; } + if (step < min_step_) step = min_step_; + double new_vol = volume_; if (dir == SCROLL_DIR::UP) { if (volume_ < max_volume) {