From 74f5181315401e5a2bb1a635ef3bc2ca9e51328a Mon Sep 17 00:00:00 2001 From: gm10 <13855078+gm10@users.noreply.github.com> Date: Thu, 25 Jul 2019 21:14:55 +0200 Subject: Scroll volume in configurable steps same as media-keys and don't hardcode default value --- mate-volume-control/gvc-channel-bar.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'mate-volume-control') diff --git a/mate-volume-control/gvc-channel-bar.c b/mate-volume-control/gvc-channel-bar.c index ad05abf..72ec40b 100644 --- a/mate-volume-control/gvc-channel-bar.c +++ b/mate-volume-control/gvc-channel-bar.c @@ -21,6 +21,8 @@ #include "config.h" +#include + #include #include #include @@ -817,6 +819,7 @@ gvc_channel_bar_scroll (GvcChannelBar *bar, GdkScrollDirection direction) gdouble minimum; gdouble maximum; gdouble scrollstep; + GSettings *settings; g_return_val_if_fail (GVC_IS_CHANNEL_BAR (bar), FALSE); @@ -843,18 +846,23 @@ gvc_channel_bar_scroll (GvcChannelBar *bar, GdkScrollDirection direction) minimum = gtk_adjustment_get_lower (bar->priv->adjustment); maximum = gtk_adjustment_get_upper (bar->priv->adjustment); - scrollstep = maximum / 100.0 * 5.0; + /* Use the same setting for `scrollstep` as used by the media keys plugin */ + settings = g_settings_new ("org.mate.SettingsDaemon.plugins.media-keys"); + scrollstep = g_settings_get_int (settings, "volume-step"); + if (scrollstep <= 0 || scrollstep > 100) { + GVariant *variant = g_settings_get_default_value (settings, "volume-step"); + scrollstep = g_variant_get_int32 (variant); + g_variant_unref (variant); + } + g_object_unref (settings); + + /* Scale the volume step size accordingly to the range used by the control */ + scrollstep = (maximum - minimum) * scrollstep / 100; if (direction == GDK_SCROLL_UP) { - if (value + scrollstep > maximum) - value = maximum; - else - value = value + scrollstep; + value = MIN (value + scrollstep, maximum); } else if (direction == GDK_SCROLL_DOWN) { - if (value - scrollstep < minimum) - value = minimum; - else - value = value - scrollstep; + value = MAX (value - scrollstep, minimum); } gtk_adjustment_set_value (bar->priv->adjustment, value); -- cgit v1.2.1