diff options
author | Moritz Bruder <[email protected]> | 2017-04-28 09:50:52 +0200 |
---|---|---|
committer | Moritz Bruder <[email protected]> | 2017-04-28 13:21:23 +0200 |
commit | b005276f2bb281b1bc2d1ef4ba18cdd43294d58f (patch) | |
tree | 965304428145d3b6283ba53feb34f7846ff3a0bd /mate-volume-control | |
parent | ba5147eb0b08f19bfd55fe8d348c0cb2409fe26f (diff) | |
download | mate-media-b005276f2bb281b1bc2d1ef4ba18cdd43294d58f.tar.bz2 mate-media-b005276f2bb281b1bc2d1ef4ba18cdd43294d58f.tar.xz |
applet: fix minor rounding mistakes
The chosen volume step increment isn't necessarily an integer. The
volume however is stored as integer. Whenever the volume is synced back
from the mixer decimal digits may be cut off behind the dot. This
commit tries to counteract the effect by rounding to hundreths of the
maximum volume when syncing back from the mixer.
As the volume is shown in percent the new behavior should be more
reasonable to the user. There are no more irregular jumps and there
is no additional 99% step.
Diffstat (limited to 'mate-volume-control')
-rw-r--r-- | mate-volume-control/gvc-channel-bar.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/mate-volume-control/gvc-channel-bar.c b/mate-volume-control/gvc-channel-bar.c index 912eaa6..c4c85b5 100644 --- a/mate-volume-control/gvc-channel-bar.c +++ b/mate-volume-control/gvc-channel-bar.c @@ -381,11 +381,18 @@ update_adjustment_value (GvcChannelBar *bar) else value = mate_mixer_stream_control_get_volume (bar->priv->control); + gdouble maximum = gtk_adjustment_get_upper (bar->priv->adjustment); + gdouble minimum = gtk_adjustment_get_lower (bar->priv->adjustment); + gdouble range = maximum - minimum; + + /* round value to nearest hundreth of the range */ + gdouble new_value = minimum + round (((value - minimum) / range) * 100) * (range / 100); + g_signal_handlers_block_by_func (G_OBJECT (bar->priv->adjustment), on_adjustment_value_changed, bar); - gtk_adjustment_set_value (bar->priv->adjustment, value); + gtk_adjustment_set_value (bar->priv->adjustment, new_value); g_signal_handlers_unblock_by_func (G_OBJECT (bar->priv->adjustment), on_adjustment_value_changed, @@ -861,6 +868,7 @@ gvc_channel_bar_scroll (GvcChannelBar *bar, GdkScrollDirection direction) } gtk_adjustment_set_value (bar->priv->adjustment, value); + return TRUE; } |