[ltp] T420s volume controls
Ole Langbehn
linux-thinkpad@linux-thinkpad.org
Wed, 13 Mar 2013 12:34:57 +0100
This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
------enig2TJICUTQXJJCXQBELEANW
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable
Hi David,
On 13.03.2013 02:32, David Woodfall wrote:
> I notice that when I upgraded from my T42 to a T420s the volume and
> mute keys generate Xorg key events. This would be great but I prefer
> it to do hardware mixing, same as my old T42.
on my t520, my mute key is still wired in hardware, i guess. Only the
up/down keys are software.
I've set it up so that while in X, the keys control alsa. Here's a page
that describes how to map keys to commands in different DEs:
https://wiki.archlinux.org/index.php/Extra_Keyboard_Keys_in_Xorg
I've written a small script that I've mapped to the keys:
#!/usr/bin/env bash
function getCurrentVolume {
amixer -- sget Master playback|egrep -e "^ (Mono|Front)"|sed
's/^[^]]*\[\([^]]*\)%\].*$/\1/g'|sort -u
}
function getStepForVolume {
DIFF=3D$((100-$1))
echo "define min(x,y){if(y>x){return y} else{return
x}};min(1,l(${DIFF})/l(2)*2)+0.51" | bc -l| xargs printf "%1.0f\n"
}
fold -w1 <<< $1 | while read token; do
echo $token
case $token in
"-"|"+" )
CUR=3D$(getCurrentVolume)
STEP=3D$(getStepForVolume $CUR)
amixer -- sset Master playback ${STEP}%${1}
notify-send "Changed volume" "from $CUR to $(getCurrentVolume)"
;;
* )
notify-send Error "wrong argument: \"$1\""
;;
esac
done
the math in getStepForVolume can be adjusted to your liking for
bigger/smaller increments.
can be called with any number of +/- chars as arguments, e.g.
~/bin/volume "---"
to turn down the volume three steps
And now I can do wonderful stuff like mapping single
increments/decrements to the volume keys without modifier, and mapping
bigger steps to the volume keys with shift/ctrl as modifier.
hth,
Ole
------enig2TJICUTQXJJCXQBELEANW
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.19 (GNU/Linux)
iEYEARECAAYFAlFAZGcACgkQoxgU3D8/uhHYmQCeM46Jw9ywU6oZX8jnXW6ATk8j
XxAAn1Ob/OwBEwTpTuQkkv7jJdb/L8fX
=eN/8
-----END PGP SIGNATURE-----
------enig2TJICUTQXJJCXQBELEANW--