Friday, May 1, 2020

Using Lenovo X1 Carbon volume/brightness keys under a bare X11

This is going to be a quick post.

When you don't use a fancy Window Manager (I'm using i3), there are many things which don't come out of the box. Well i3 supports keyboard bindings, but I'm not sure about special keys like volume/brightness. You may ask "but what are you using this then?", well it's another topic but I'll just say that I like its lightweightness.

Anyway, I'm sure there's more than one way to do this but one pretty neat method I found and like is using xbindkeys(1). Here is the relevant snippet of my $HOME/.xbindkeyrc:

"xterm"
  control + b:2

# Increase backlight
"xbacklight -inc 5"
  XF86MonBrightnessUp

# Decrease backlight
"xbacklight -dec 5"
  XF86MonBrightnessDown

# Increase volume
"amixer set Master 5%+"
  XF86AudioRaiseVolume

# Decrease volume
"amixer set Master 5%-"
  XF86AudioLowerVolume

# Mute
"amixer set Master toggle"
  XF86AudioMute

I let you figure out what this does, but that shouldn't be too hard...

Note that of other XF86 symbols, you can visit this page: http://wiki.linuxquestions.org/wiki/XF86_keyboard_symbols. You can also use xev(1) to figure out which code is emitted when one key is pressed.

Finally, xbindkeys(1) is a daemon which needs to be started, so just add this to your $HOME/.xinitrc:

xbindkeys

Have fun!