awesome global shortcut

Mon 04 January 2016

[caption id="" align="alignright" width="200" class="zemanta-img"]Multimedia keyboard Multimedia keyboard (Photo credit: Wikipedia)[/caption]

The awesome window manager does not provide GUI configuration tool.

Here is a litte how to to provide a feature using global shortcut, illustrated with wolume control.

Defining and identifying the feature and the shortcut

The wanted feature is usually accessible via the CLI. For example, to modify the sound, the alsa provides the amixer command (via the alsa-utils package in archlinux):

amixer set Master 40%     # put Master level to 40%
amixer set Master 9%+     # increase Master level by 9%
amixer set Master 9%-     # decrease Master level by 9%
amixer sset Master toggle # toggle Mute on Master

The shortcut can be a combination of keys including the modkey. You may also use some of the Xfree86 key binding[1. here is a list]  if your keyboard provides use some multimedia keys.

For sound control, the symbols of interest are XF86AudioRaiseVolume, XF86AudioLowerVolume and XF86AudioMute.

Modifying configuration files

I don't fully understand the functionning of the `awful.key <http://awesome.naquadah.org/doc/api/modules/awful.key.html>`__ function. It allows to execute a command when pressing some keys. Those keys are sepcified in the first two parameters, and the lua function executed in the last parameter. Several example can be found on the awesome wiki.

To enable a global keybinding, this awful.key() function must be placed inside the `global.keys() <https://awesome.naquadah.org/wiki/Global_Keybindings>`__ function.

The configuration file to modify is the rc.lua whose default location is inside the $XDG_CONFIG_HOME/awesome/ directory (~/.config/awesome/ in my case).

For the sound configuration, modify the globalkeys adding the three wanted features:

globalkeys = awful.util.table.join(
...
    awful.key({ }, "XF86AudioRaiseVolume", function () awful.util.spawn("amixer set Master 2%+") end),
    awful.key({ }, "XF86AudioLowerVolume", function () awful.util.spawn("amixer set Master 2%-") end),
    awful.key({ }, "XF86AudioMute", function () awful.util.spawn("amixer sset Master toggle") end),
...
)

(Non-)Related articles

Related articles (or not):

Category: how to Tagged: alsa ArchLinux awesome Configuration file FAQs Help and Tutorials Unix window manager tools