Skip to contentSkip to conversation

vi-like key bindings for alsamixer

PATCH New Simon Hengel 4 participants 7 messages Apr 1, 2009 – Apr 20, 2009

lore
Share & tools
lore
#0 lore raw

Hello List,
I realized that 'j' and 'k' are not used nor reserved for future use with alsamixer. So I decided to use them as aliases for 'up' and 'down'. Is this deemed suitable for the masses?

Cheers,
Simon Hengel

#1 lore raw

PATCH 1/1 Added vi-like key bindings to alsamixer.

* Added 'j' as an alias for KEY_DOWN
* Added 'k' as an alias for KEY_UP

alsamixer/alsamixer.c +4 -0
index 414033e..c65c22d 100644
@@ -2113,11 +2113,13 @@ mixer_iteration (void)
 	mixer_hscroll_delta -= 1;
 	break;
       case KEY_UP:
+      case 'k':
       case 'w':
       case 'W':
 	mixer_vscroll_delta -= 1;
 	break;
       case KEY_DOWN:
+      case 'j':
       case 'x':
       case 'X':
 	mixer_vscroll_delta += 1;
@@ -2179,12 +2181,14 @@ mixer_iteration (void)
 	break;
       case 'w':
       case KEY_UP:
+      case 'k':
         mixer_set_delta(1);
       case 'W':
         mixer_add_delta(1);
 	break;
       case 'x':
       case KEY_DOWN:
+      case 'j':
         mixer_set_delta(-1);
       case 'X':
         mixer_add_delta(-1);
Signature · 1 line
1.5.6.3
#2 lore raw
In reply to Simon Hengel
Quoted 2 lines · Simon Hengel

I realized that 'j' and 'k' are not used nor reserved for future use with alsamixer. So I decided to use them as aliases for 'up' and 'down'.

But 'h' and 'l' are already used for other purposes, so these keys cannot be used to give a consistent vi-like behaviour.

Quoted 1 line

Is this deemed suitable for the masses?

_Undocumented_ commands certainly aren't. ;-)

Best regards,
Clemens

#3 lore raw
Quoted 3 lines · Clemens Ladisch
Quoted 1 line

Is this deemed suitable for the masses?

_Undocumented_ commands certainly aren't. ;-)

This is certainly true.

While working on documentation I realized that '+' and KEY_UP, contrary to what is documented, do different things.

'+' increases volume by 1% whereas KEY_UP increases volume by 2%.

So actually it is like:

W | +           increase volume by 1%
w | KEY_UP      increase volume by 2%
X | -           decrease volume by 1%
x | KEY_DOWN    decrease volume by 2%

Still this makes no difference with my hardware, as the granularity is > 3% (e.g. snd_mixer_selem_get_playback_volume_range gives {0, 31} or {0, 15} for {min, max}).

I wonder if it would be a good idea to unify it. Consequently one could do the same for left & right levels.

#4 lore raw

PATCH 1/2 alsamixer - unified behavior of volume control keys.

Contrary to what is documented '+' and KEY_UP did not the same thing. The behavior was as follows:

W | +           increase volume by 1%
w | KEY_UP      increase volume by 2%
X | -           decrease volume by 1%
x | KEY_DOWN    decrease volume by 2%

Now all of them change the volume by only 1%.

alsamixer/alsamixer.c +3 -18
index 414033e..554326f 100644
@@ -1916,15 +1916,6 @@ mixer_set_delta(int delta)
     mixer_volume_delta[grp] = delta;
 }
 
-static void
-mixer_add_delta(int delta)
-{
-  int grp;
-  
-  for (grp = 0; grp < 2; grp++)
-    mixer_volume_delta[grp] += delta;
-}
-
 static int
 mixer_iteration (void)
 {
@@ -2172,22 +2163,16 @@ mixer_iteration (void)
         mixer_set_delta(-100);
 	break;
       case '+':
-        mixer_set_delta(1);
-	break;
-      case '-':
-        mixer_set_delta(-1);
-	break;
       case 'w':
+      case 'W':
       case KEY_UP:
         mixer_set_delta(1);
-      case 'W':
-        mixer_add_delta(1);
 	break;
+      case '-':
       case 'x':
+      case 'X':
       case KEY_DOWN:
         mixer_set_delta(-1);
-      case 'X':
-        mixer_add_delta(-1);
 	break;
       case '0':
       case '1':
Signature · 1 line
1.5.6.3
#5 lore raw

PATCH 2/2 alsamixer - unified behavior of volume keys for left & right levels.

Contrary to what is documented 'q', 'e', 'z' and 'c' did different things as there upper case counterparts. The lower case versions changed volume by 2%, whereas the upper case commands changed volume by 1%.

Now all of them change the volume by only 1%.

alsamixer/alsamixer.c +4 -8
index 554326f..51cd97e 100644
@@ -2187,26 +2187,22 @@ mixer_iteration (void)
 	mixer_volume_absolute = 10 * (key - '0');
 	break;
       case 'q':
-	mixer_volume_delta[MIXER_CHN_LEFT] = 1;
       case 'Q':
-	mixer_volume_delta[MIXER_CHN_LEFT] += 1;
+	mixer_volume_delta[MIXER_CHN_LEFT] = 1;
 	break;
       case 'y':
       case 'z':
-	mixer_volume_delta[MIXER_CHN_LEFT] = -1;
       case 'Y':
       case 'Z':
-	mixer_volume_delta[MIXER_CHN_LEFT] += -1;
+	mixer_volume_delta[MIXER_CHN_LEFT] = -1;
 	break;
       case 'e':
-	mixer_volume_delta[MIXER_CHN_RIGHT] = 1;
       case 'E':
-	mixer_volume_delta[MIXER_CHN_RIGHT] += 1;
+	mixer_volume_delta[MIXER_CHN_RIGHT] = 1;
 	break;
       case 'c':
-	mixer_volume_delta[MIXER_CHN_RIGHT] = -1;
       case 'C':
-	mixer_volume_delta[MIXER_CHN_RIGHT] += -1;
+	mixer_volume_delta[MIXER_CHN_RIGHT] = -1;
 	break;
       case 'm':
       case 'M':
Signature · 1 line
1.5.6.3
#6 lore raw

Re: [PATCH - alsa-utils 1/2] alsamixer - unified behavior of volume control keys.

In reply to Simon Hengel

At Thu, 2 Apr 2009 18:05:29 +0200,

Quoted 10 lines · Simon Hengel

Contrary to what is documented '+' and KEY_UP did not the same thing. The behavior was as follows:

W | +           increase volume by 1%
w | KEY_UP      increase volume by 2%
X | -           decrease volume by 1%
x | KEY_DOWN    decrease volume by 2%

Now all of them change the volume by only 1%.

Then rather fix the man page?

Takashi