Skip to contentSkip to conversation

alsamixer: Confirm that a drastic volume change is intentional.

PATCH In review Kusanagi Kouichi 2 participants 3 messages Jan 13, 2012 – Jan 14, 2012

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 alsamixer: Confirm that a drastic volume change is intentional.

Home key has been disabled because it might at least surprise a user unless volume is already nearly full. Not only home but 9, 8 and so on might also surprise a user. So instead of disableing key, show confirmation dialog for drastic volume change.

---
 alsamixer/mixer_widget.c   |   52 ++++++++++++++++++++++++++++++++++++++------
 alsamixer/volume_mapping.c |    3 ++
 2 files changed, 48 insertions(+), 7 deletions(-)
alsamixer/mixer_widget.c +45 -7
index caaf777..d01a6ec 100644
@@ -207,6 +207,7 @@ static void show_help(void)
 		_("Up/Down    Change volume"),
 		_("+ -        Change volume"),
 		_("Page Up/Dn Change volume in big steps"),
+		_("Home       Set volume to 100%"),
 		_("End        Set volume to 0%"),
 		_("0-9        Set volume to 0%-90%"),
 		_("Q W E      Increase left/both/right volumes"),
@@ -305,9 +306,10 @@ static void change_enum_relative(struct control *control, int delta)
 			snd_mixer_selem_set_enum_item(control->elem, i, new_index);
 }
 
-static void change_volume_to_percent(struct control *control, int value, unsigned int channels)
+static int change_volume_to_percent(struct control *control, int value, unsigned int channels)
 {
 	int (*set_func)(snd_mixer_elem_t *, snd_mixer_selem_channel_id_t, double, int);
+	int err = 0;
 
 	if (!(control->flags & HAS_VOLUME_1))
 		channels = LEFT;
@@ -316,9 +318,10 @@ static void change_volume_to_percent(struct control *control, int value, unsigne
 	else
 		set_func = set_normalized_capture_volume;
 	if (channels & LEFT)
-		set_func(control->elem, control->volume_channels[0], value / 100.0, 0);
-	if (channels & RIGHT)
-		set_func(control->elem, control->volume_channels[1], value / 100.0, 0);
+		err = set_func(control->elem, control->volume_channels[0], value / 100.0, 0);
+	if (channels & RIGHT && err <= 0)
+		err = set_func(control->elem, control->volume_channels[1], value / 100.0, 0);
+	return err;
 }
 
 static double clamp_volume(double v)
@@ -371,7 +374,44 @@ static void change_control_to_percent(int value, unsigned int channels)
 	if (control->flags & TYPE_ENUM)
 		change_enum_to_percent(control, value);
 	else
-		change_volume_to_percent(control, value, channels);
+		if (change_volume_to_percent(control, -value, channels)) {
+			char buf[50];
+			const char * const text[] = { buf, "               (Y/n)" };
+			const struct widget *active_widget;
+
+			snprintf(buf, sizeof buf, "Do you really change volume to %d%%?", value);
+			show_text(text, 2, "");
+			active_widget = get_active_widget();
+			wtimeout(active_widget->window, -1);
+			while (1) {
+				switch (wgetch(active_widget->window)) {
+#ifdef KEY_RESIZE
+				case KEY_RESIZE:
+					window_size_changed();
+					continue;
+#endif
+				case 'Y':
+				case 'y':
+				case '\n':
+				case KEY_ENTER:
+					change_volume_to_percent(control, value, channels);
+					break;
+				case 'N':
+				case 'n':
+				case 27:
+				case KEY_CANCEL:
+				case KEY_CLOSE:
+				case KEY_EXIT:
+					break;
+				default:
+					continue;
+				}
+				break;
+			}
+			active_widget->handle_key(KEY_ENTER);
+		} else
+			change_volume_to_percent(control, value, channels);
+
 	display_controls();
 }
 
@@ -536,12 +576,10 @@ static void on_handle_key(int key)
 	case KEY_NPAGE:
 		change_control_relative(-5, LEFT | RIGHT);
 		break;
-#if 0
 	case KEY_BEG:
 	case KEY_HOME:
 		change_control_to_percent(100, LEFT | RIGHT);
 		break;
-#endif
 	case KEY_LL:
 	case KEY_END:
 		change_control_to_percent(0, LEFT | RIGHT);
alsamixer/volume_mapping.c +3 -0
index 1c0d7c4..bd160ed 100644
@@ -133,6 +133,9 @@ static int set_normalized_volume(snd_mixer_elem_t *elem,
 	double min_norm;
 	int err;
 
+	if (volume < 0)
+		return -volume - get_normalized_volume(elem, channel, ctl_dir) >= 0.5;
+
 	err = get_dB_range[ctl_dir](elem, &min, &max);
 	if (err < 0 || min >= max) {
 		err = get_raw_range[ctl_dir](elem, &min, &max);
Signature · 1 line
1.7.8.3
#1 lore raw
Quoted 3 lines · Kusanagi Kouichi

Home key has been disabled because it might at least surprise a user unless volume is already nearly full. Not only home but 9, 8 and so on might also surprise a user.

The surprise is not so much the amount of the resulting volume but the meaning of the key; the user might have assumed that Home jumps to the first control. If the volume is too loud after pressing 9, it's easy to press another smaller digit, but it would be more difficult to remember a volume change key if the jump to 100% happens in a situation where a volume change wasn't expected at all.

(And this would be a good reason to disable the End key, too.)

Quoted 2 lines

So instead of disableing key, show confirmation dialog for drastic volume change.

A confirmation dialog is annoying to users who know what they're doing, and still confusing to anybody else.

Instead of having commands that require confirmation, I think it's better to have only commands whose meaning is obvious.

In this case, the jump-to-100% command doesn't seem to be very worthwhile because you could just as well press PageUp a few times. Is there a reason that you need this command, other than for symmetry with the End command?

Regards,
Clemens

#2 lore raw
Quoted 23 lines · Clemens Ladisch
Quoted 3 lines · Kusanagi Kouichi

Home key has been disabled because it might at least surprise a user unless volume is already nearly full. Not only home but 9, 8 and so on might also surprise a user.

The surprise is not so much the amount of the resulting volume but the meaning of the key; the user might have assumed that Home jumps to the first control. If the volume is too loud after pressing 9, it's easy to press another smaller digit, but it would be more difficult to remember a volume change key if the jump to 100% happens in a situation where a volume change wasn't expected at all.

(And this would be a good reason to disable the End key, too.)

Quoted 2 lines

So instead of disableing key, show confirmation dialog for drastic volume change.

A confirmation dialog is annoying to users who know what they're doing, and still confusing to anybody else.

Instead of having commands that require confirmation, I think it's better to have only commands whose meaning is obvious.

Quoted 8 lines

In this case, the jump-to-100% command doesn't seem to be very worthwhile because you could just as well press PageUp a few times. Is there a reason that you need this command, other than for symmetry with the End command?

Regards,
Clemens

The reason for this patch is that there is #if 0-ed code. I thought home key is supposed to set volume to 100%. But that's not true. Please ignore this patch.