For those who find Gnome and KDE to be boring, try i3. i3 is a tiling window manager, which means it tries to use 100% of your screen realestate for your windows. I switched to i3 a few months ago when there was a pretty large bug in Gnome 3, and I didn't have time to wait for a fix.

Today I wanted to get a few things working in i3, that just hadn't before. The first (and arguably the most important) was volume control. I use a Lenovo ThinkPad T430. It has dedicated volume buttons. They however had no effect on the volume of my laptop speakers. So I wanted to fix that. So, how do you do that? Simple, you configure you i3 to bind the key and then run a command to adjust the volume. Easy right? Not really. Here is what was really envolved in such a task.

Configure i3: keybinding

Adding key bindings to i3 is simple, in your config file (either ~/.i3/config or ~/.config/i3) you add something like this

bindsym XF86AudioRaiseVolume exec amixer -c 0 set Speaker 5+

Let's talk about what that all means!

bindsym tells i3 to bind the key that follows. So we tell it to bind XF86AudioRaiseVolume to a exec, which executes a command.

But, where did we get the XF86AudioRaiseVolume value? From xev.

xev: x event viewer

Ok, I am honestly guessing at what the v means, but it is good guess.

If you open up a terminal and type xev into the cli you will get a couple things. The first is your cli will dump lots of data at you, the other is a mostly blank window. Move your mouse around in the white window, or press keys while your mouse is over that window and your cli will fly with changes. Press your volume up button and you should get some stuff that looks like this:

KeyPress event, serial 32, sythetic NO, window 0x1a00001, root 0x251, subw 0x0, time 1926937, (99,532), root:(1170,552), state 0x0, keycode 123 (keysum 0x1008ff13, XF86AudioRaiseVolume), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False

KeyPress event, serial 32, sythetic NO, window 0x1a00001, root 0x251, subw 0x0, time 1926937, (99,532), root:(1170,552), state 0x0, keycode 123 (keysum 0x1008ff13, XF86AudioRaiseVolume), same_screen YES, XLookupString gives 0 bytes: XmbLookupString gives 0 bytes: XFilterEvent returns: False

Here we can see the keysum 0x1008ff13, XF86AudioRaiseVolume, that tells the symbolic link to our key. Congratulations you can now identify key events in X!

amixer

So what is this amixer business? Well, that is bit harder to explain, but I will do my best.

The command we issue is:

amixer -c 0 set Speaker 5+

amixer is the commandline tool for adjusting alsamixer (Advanced Linux Sound Architecture).

First you need to identify your cards. Honestly, I need to learn this more, but the jist is this:

amixer -c 0 will show you all the mixer controls for card 0, depending on your setup your main soundcard might be a different number. Specifically I am looking for the Speaker control for my card. I know this from adjusting things in alsamixer. I will have to research more how to figure this out from the cli.

So the full command works like this:

amixer -c 0 set Speaker 5+

amixer, on card 0, set Speaker to whatever it is, plus 5 (I believe that is 5% more).

Volume down

I tied the other button (volume down) to the same command but backwards

amixer -c 0 set Speaker 5-

then I bind that to the appropriate key:

bindsym XF86AudioLowerVolume exec amixer -c 0 set Speaker 5-

More fun with sound control

I still need to figure out how this will work with headphones plugged in and compensate. I also need to make the mute button work. Wish me luck.