Skip to content

Commit

Permalink
volume: configurable scroll sensitivity (#179)
Browse files Browse the repository at this point in the history
  • Loading branch information
NamorNiradnug authored Sep 23, 2023
1 parent a7aaf8b commit 71ba046
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
4 changes: 4 additions & 0 deletions metadata/panel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,10 @@
<default>32</default>
<min>1</min>
</option>
<option name="volume_scroll_sensitivity" type="double">
<_short>Volume Scroll Sensitivity</_short>
<default>0.05</default>
</option>
</group>
<group>
<_short>Notifications</_short>
Expand Down
23 changes: 4 additions & 19 deletions src/panel/widgets/volume.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
#include "launchers.hpp"
#include "gtk-utils.hpp"

#define INCREMENT_STEP_PC 0.05

WayfireVolumeScale::WayfireVolumeScale()
{
this->signal_draw().connect_notify(
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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 */
Expand Down
1 change: 1 addition & 0 deletions src/panel/widgets/volume.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ class WayfireVolume : public WayfireWidget

WfOption<int> icon_size{"panel/volume_icon_size"};
WfOption<double> timeout{"panel/volume_display_timeout"};
WfOption<double> scroll_sensitivity{"panel/volume_scroll_sensitivity"};

void on_volume_scroll(GdkEventScroll *event);
void on_volume_button_press(GdkEventButton *event);
Expand Down

0 comments on commit 71ba046

Please sign in to comment.