summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClemens Ladisch <clemens@ladisch.de>2010-02-22 09:42:03 +0100
committerClemens Ladisch <clemens@ladisch.de>2010-02-22 09:42:03 +0100
commitc9b86f49a8a1a8c337bf0c1b7f12749e8be781ed (patch)
tree455d92b993cc1856c3b976499dd1598056578161
parent5a016b583b5c949253a9e791ad79f13e54f87054 (diff)
downloadalsa-utils-c9b86f49a8a1a8c337bf0c1b7f12749e8be781ed.tar.gz
alsamixer: handle out-of-range volume values
Ensure that control volume values are in their allowed range; otherwise, the displayed values could be outside the range 0..100 and mess up the layout. Signed-off-by: Clemens Ladisch <clemens@ladisch.de>
-rw-r--r--alsamixer/mixer_display.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/alsamixer/mixer_display.c b/alsamixer/mixer_display.c
index 260c9b0..20d6d6a 100644
--- a/alsamixer/mixer_display.c
+++ b/alsamixer/mixer_display.c
@@ -390,6 +390,15 @@ static void display_string_centered_in_control(int y, int col, const char *s, in
display_string_in_field(y, x, s, width, ALIGN_CENTER);
}
+static long clamp(long value, long min, long max)
+{
+ if (value < min)
+ return min;
+ if (value > max)
+ return max;
+ return value;
+}
+
static void display_control(unsigned int control_index)
{
struct control *control;
@@ -462,8 +471,10 @@ static void display_control(unsigned int control_index)
err = snd_mixer_selem_get_capture_volume_range(control->elem, &min, &max);
if (err < 0)
return;
- if (min == max)
+ if (min >= max)
max = min + 1;
+ volumes[0] = clamp(volumes[0], min, max);
+ volumes[1] = clamp(volumes[1], min, max);
if (control->flags & IS_ACTIVE)
wattrset(mixer_widget.window, 0);