From 71ba0464c4b943b6dcc67d376affd4d8ec5dd1bc Mon Sep 17 00:00:00 2001 From: Gundarin Roman Date: Sat, 23 Sep 2023 22:42:08 +0300 Subject: [PATCH] volume: configurable scroll sensitivity (#179) --- metadata/panel.xml | 4 ++++ src/panel/widgets/volume.cpp | 23 ++++------------------- src/panel/widgets/volume.hpp | 1 + 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/metadata/panel.xml b/metadata/panel.xml index 5846b56d..38082fb6 100644 --- a/metadata/panel.xml +++ b/metadata/panel.xml @@ -242,6 +242,10 @@ 32 1 + <_short>Notifications diff --git a/src/panel/widgets/volume.cpp b/src/panel/widgets/volume.cpp index e4252f51..7582cc6c 100644 --- a/src/panel/widgets/volume.cpp +++ b/src/panel/widgets/volume.cpp @@ -4,8 +4,6 @@ #include "launchers.hpp" #include "gtk-utils.hpp" -#define INCREMENT_STEP_PC 0.05 - WayfireVolumeScale::WayfireVolumeScale() { this->signal_draw().connect_notify( @@ -135,21 +133,8 @@ void WayfireVolume::set_volume(pa_volume_t volume, set_volume_flags_t flags) void WayfireVolume::on_volume_scroll(GdkEventScroll *event) { - int32_t current_volume = volume_scale.get_target_value(); - const int32_t adjustment_step = max_norm * INCREMENT_STEP_PC; - - /* Adjust volume on button scroll */ - if ((event->direction == GDK_SCROLL_UP) || - ((event->direction == GDK_SCROLL_SMOOTH) && (event->delta_y < 0))) - { - set_volume(std::min(current_volume + adjustment_step, (int32_t)max_norm)); - } - - if ((event->direction == GDK_SCROLL_DOWN) || - ((event->direction == GDK_SCROLL_SMOOTH) && (event->delta_y > 0))) - { - set_volume(std::max(current_volume - adjustment_step, 0)); - } + set_volume(std::clamp(volume_scale.get_target_value() - event->delta_y * max_norm * scroll_sensitivity, + 0.0, max_norm)); button->grab_focus(); check_set_popover_timeout(); @@ -238,8 +223,8 @@ void WayfireVolume::on_default_sink_changed() /* Update the scale attributes */ max_norm = gvc_mixer_control_get_vol_max_norm(gvc_control); volume_scale.set_range(0.0, max_norm); - volume_scale.set_increments(max_norm * INCREMENT_STEP_PC, - max_norm * INCREMENT_STEP_PC * 2); + volume_scale.set_increments(max_norm * scroll_sensitivity, + max_norm * scroll_sensitivity * 2); /* Finally, update the displayed volume. However, do not show the * popup */ diff --git a/src/panel/widgets/volume.hpp b/src/panel/widgets/volume.hpp index 0cddc500..69f1d9c1 100644 --- a/src/panel/widgets/volume.hpp +++ b/src/panel/widgets/volume.hpp @@ -38,6 +38,7 @@ class WayfireVolume : public WayfireWidget WfOption icon_size{"panel/volume_icon_size"}; WfOption timeout{"panel/volume_display_timeout"}; + WfOption scroll_sensitivity{"panel/volume_scroll_sensitivity"}; void on_volume_scroll(GdkEventScroll *event); void on_volume_button_press(GdkEventButton *event);