mirror of
https://github.com/alsa-project/alsa-utils
synced 2024-12-22 08:26:31 +01:00
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>
This commit is contained in:
parent
5a016b583b
commit
c9b86f49a8
1 changed files with 12 additions and 1 deletions
|
@ -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);
|
||||
|
|
Loading…
Reference in a new issue