From the Arch Wiki: awesome is a highly configurable, next generation framework window manager for Xorg. It is very fast and extensible. It is primarily targeted at power users, developers and any people dealing with every day computing tasks and who want to have fine-grained control on its graphical environment.
Personally, what really made me want to try Awesome is the fact its configuration file is written with an actual programming language and not just a configuration language like with i3, and by the fact it works with tags and not workspaces which makes window management much more flexible.
This document was written in Emacs with Org-mode and is both the documentation and source code of my configuration file which can be extracted to ~$HOME/.config/awesome/rc.lua~ through a call to ~org-babel-tangle~.
First of all, some initialization is needed, and this initialization is about math randomness. So, let’s initialize the ~random~ method of the ~math~ library:
#+BEGIN_SRC lua
math.randomseed(os.time())
#+END_SRC
In order to be able to load libraries properly, I first need to make sure LuaRocks is installed, so I can also make sure the packages our configuration depends on installed through it can be found. If LuaRocks is not installed, then do nothing.
This code checks if Awesome encountered an error during startup and fell back to another config. This code will only ever execute for the fallback config.
With Awesome, it is possible to load or write custom themes in order to give Awesome a special look that fits the user. I am currently using a custom theme that is not yet included in my dotfiles. I will add it later, along with the images used for the theme.
The two following variables are set so that I don’t need to go over my whole config file in order to modify which terminal or text editor I use, not that I do it often though.
The following declares the default Modkey. Usually, ~Mod4~ is the Super key, situated between the Ctrl key and the Alt key with a logo (usually Windows’). Another usual value for this is ~Mod1~, which is the Alt key, but it has greater chances of interfering with other software. I also defined some other obvious variables in order to make my code cleaner later on.
This function sets a random wallpaper from the directory =~/Pictures/Wallpapers=, see [[file:bin.org::#pape-update-bdecbadf][pape-update]] in my custom scripts. This depends on [[https://github.com/l3ib/nitrogen/][Nitrogen]].
The top bar in Awesome is declared thanks to a ~wibar~ widget fro the ~awful~ library. It is comprised of several buttons and widgets that will be declared below.
It is possible to create actual menus in Awesome, including the one available at the top-left corner of the screen. First, let’s declare a menu related to Awesome:
For now it only has two entries: the Awesome menu and opening a terminal, I will add some more later probably. Let’s specify it as being our main launcher:
In order to create the taglist (an equivalent to workspaces, but better), we need to create first a local variable that will hold the widget. It will be declared as you can see below:
#+BEGIN_SRC lua :tangle no
local tasklist_buttons = gears.table.join(
-- configuration goes here
)
#+END_SRC
~gears.table.join()~ joins several tables together, as described [[https://awesomewm.org/doc/api/libraries/gears.table.html][here]], which will be useful since all its arguments will be tables generated by the ~awful.button~ method which will be useful in order to manage what clicks on the tags should do. First, let’s manage left clicks.
Left clicks in general are dedicated to tag visibility. A simple left click on a tag should switch this tag as the only visible tag, no matter how many of them were visible beforehand.
However, left clicks combined with the modkey will add the clicked tag to the list of visible tags, which allows the user to see windows from several tags at once.
#+NAME: tag-mod-left-click
#+BEGIN_SRC lua :tangle no
awful.button({ modkey }, 1, awful.tag.viewtoggle)
#+END_SRC
Right clicks are dedicated to window tagging. A simple right click will untag the currently focused window and tag it again with the clicked tag, moving it effectively from one tag to another.
#+NAME: tag-simple-right-click
#+BEGIN_SRC lua :tangle no
awful.button({ }, 3, function(t)
if client.focus then
client.focus:move_to_tag(t)
end
end)
#+END_SRC
However, a right click combined with the modkey will add the clicked tag to the currently focused window, making it visible to both tags.
#+NAME: tag-mod-right-click
#+BEGIN_SRC lua :tangle no
awful.button({ modkey }, 3, function(t)
if client.focus then
client.focus:toggle_tag(t)
end
end)
#+END_SRC
The scroll wheel is treated as clicks just as any right or left clicks and can be interpreted by Awesome. They can prove useful when it comes to tags. If a scroll up is detected over tags, then Awesome will display the previous tag.
Similarly to the tag list, the task list can display some special behavior depending on the clicks it receives. These clicks are set like so:
#+BEGIN_SRC lua :tangle no
local tasklist_buttons = gears.table.join(
-- List of clicks
)
#+END_SRC
A left click on a task in the taskbar will simply focus and raise the window linked to it if it is not focused. Otherwise, if the window is focused, the window will be minimized.
#+NAME: task-simple-left-click
#+BEGIN_SRC lua :tangle no
awful.button({ }, 1, function (c)
if c == client.focus then
c.minimized = true
else
c:emit_signal(
"request::activate",
"tasklist",
{raise = true}
)
end
end)
#+END_SRC
If the right click is detected, then a list of all the opened clients is invoked so we can switch to another (and if needed switch visible tag). The width of this list will be 250px.
When a screen’s geometry changes (e.g. when a different resolution is applied), the signal ~property::geometry~ is sent. When this is the case, the wallpaper should be redisplayed since it won’t necessarily fit the new geometry of the screen. And remember, I have a [[#Custom_functions-Wallpaper-related_functions-Restore_previous_wallpaper-8b5bc08c][function that does exactly that]]! Let’s connect this function to the geometry change signal:
If a new screen gets connected, it will need to get a new wallpaper. A lot needs to be done, and all the following lines of code will be inside a block like this:
#+BEGIN_SRC lua :tangle no
awful.screen.connect_for_each_screen(function(s)
-- Code to be executed goes here
end)
#+END_SRC
So, due the code block above, if you see any reference to ~s~ in the code blocks below, it will refer to the screen being set up by the function.
First, let’s set its wallpaper:
#+NAME: screen-set-pape
#+BEGIN_SRC lua :tangle no
set_wallpaper()
#+END_SRC
Next, let’s build a list of tags for the screen. *Be aware that each screen has its own tag table!* The default layout will be the first refered to in
Next, let’s create the taglist widget. It will use the ~taglist_buttons~ [[#Top_bar-Tag_list-d43dbb62][declared above]] in order to handle clicks on tags, and due to the filter, all tags will be displayed in the tagbar ([[https://awesomewm.org/apidoc/widgets/awful.widget.taglist.html#List_filters][more about tag filters]]).
#+NAME: screen-taglist-widget
#+BEGIN_SRC lua :tangle no
s.taglist = awful.widget.taglist {
screen = s,
filter = awful.widget.taglist.filter.all,
buttons = taglist_buttons
}
#+END_SRC
A tasklist widget will also get created thanks with the ~tasklist_button~ [[#Top_bar-Tag_list-d43dbb62][declared above]] that will handle clicks on tasks. Contrarily to the taglist widget above, the tasklist will only display the screen’s current tags thanks to its filter.
Then, Let’s create an imagebox widget in which will be contained an icon indicating which layout is being used. We need one per screen. We will also make it clickable: if there is a left click or a scroll up detected above it, the next layout will be loaded; otherwise if a right click or a scroll down is detected, the previous layout will be loaded.
#+NAME: screen-layout-indicator
#+BEGIN_SRC lua :tangle no
s.layoutbox = awful.widget.layoutbox(s)
s.layoutbox:buttons(gears.table.join(
awful.button({ }, 1, function () awful.layout.inc( 1) end),
awful.button({ }, 3, function () awful.layout.inc(-1) end),
awful.button({ }, 4, function () awful.layout.inc( 1) end),
awful.button({ }, 5, function () awful.layout.inc(-1) end)))
#+END_SRC
Now it is time to create the widget, a ~wibox~ that will contain our bar.
#+NAME: screen-wibox-widget
#+BEGIN_SRC lua :tangle no
s.wibox = awful.wibar({ position = "top", screen = s })
#+END_SRC
Finally, let’s set up our bar. Since it is a horizontal bar, its layout will be horizontal too. Our launcher, taglist and promptbox will be part of the left widgets, while the tasklist will be at the center, and the keyboard indicator, the system tray, the clock and the layout indicator will be on the right.
It is possible with Awesome to bind some shortcuts to mouse events when the mouse is above Awesome itself (not above some client). Only one is set: the right click opens the Awesome menu.
Keybindings allow the user to execute some Lua code all across Awesome. They all bear at least a list of modifier keys, the actual key to be pressed, the action they keybinding should yield, a description, and a group. The latter two will be useful for the keybindings help window which will display them all, sorted by group and with the description displayed next to the keybinding itself.
Here are some keybindings related to Awesome itself. Most of them will be described in tables, but due to some limitations from Org-mode (the Emacs mode used to write this document and generate my Awesome configuration), a few of them will be directly written as Lua code.
Here is a description of the tables displayed below:
- Key :: key which toggles the shortcut
- Modifiers :: modifier keys that are required to toggle the shortcut
- Lambda? :: whether or not the ~Action~ should be nested in a lambda function. Possible values are:
- ~no~ :: The value is a Lua function to be executed as is
- ~yes~ :: The value is to be inserted into a lambda
- ~spawn~ :: The value is to be inserted in an ~awful.spawn~ call in a lambda
- ~shell~ :: The value is to be inserted in an ~awful.spawn.with_shell~ call in a lambda
- Action :: code to be executed by the shortcut
- What it does :: short description of the shortcut’s action
- Group :: group in which the shortcut will appear in Awesome’s help window
- Clientkey? :: whether this should be a global shortcut or a shortcut only aimed at clients (value is ~yes~ or ~no~)
Most of these keybindings are available at root-level of Awesome and will be declared in the ~globalkeys~ variable, which will be added then to ~root.keys~ (see [[https://awesomewm.org/doc/api/libraries/root.html#keys]]).
| Escape | modkey | no | awful.tag.history.restore | go back | tag |
| t | modkey, control | no | awful.tag.viewprev | view prev | tag |
| s | modkey, control | no | awful.tag.viewnext | view next | tag |
Another set of shortcuts is linked to the number row on the keyboard that allow the manipulation of the default tags that range from ~1~ to ~10~ (the latter is displayed as ~0~). Here is what the possible actions are:
#+NAME: sc-tag-num
| Key | Modifiers | Action | What it does | Group |
In this category you will find other keybindings that do not fit in other categories. For now, the only keybinding that is in this category is for toggling the touchpad’s tapping ability. This is linked to a special script I wrote [[file:bin.org::#Toggle_touchpad_tapping-23348b00][here]].
#+NAME: sc-misc
| Key | Modifiers | Lambda? | Action | What it does | Group |
With ~awful.rules~, users are able to describe some rules for window clients when the latter spawn, such as their placement, their properties or even execute a script. A rule can be applied through the ~manage~ signal, and they are all stored in ~awful.rules.rules~, the global rules table, as follows:
#+BEGIN_SRC lua :tangle no
awful.rules.rules = {
-- Rules here
}
#+END_SRC
# Block for exporting rules from below
#+BEGIN_SRC lua :exports none
awful.rules.rules = {
<<rules-universal>>,
<<rules-floating>>,
<<rules-titlebars>>,
<<rules-default-tags>>
}
#+END_SRC
For more documentation on rules and their syntax, you can read the [[https://awesomewm.org/doc/api/libraries/awful.rules.html][official documentation]].
When a new client is created, the ~manage~ signal is emited. When so, the following snippet ensures this new client is not off the screen, unless its position was deliberately set by a program or by the user. It will also spawn the new client where the mouse currently is.
It is possible for Awesome to send request signals, such as the request to create titlebar (generally for new clients). The following snippet handles this titlebar creation if titlebar creation was set to ~true~ in the [[#Rules-c6142cdf][rules]]. For a detailed explanation of the code, see below.
The function has two main parts: the creation of the titlebar buttons (mouse handling on the titlebar), and the creation of the titlebar itself. The creation of the button is done by creating a local variable ~buttons~ which will be a table created by the library ~gears~, in which will be buttons created by the user.
#+BEGIN_SRC lua :tangle no
local buttons = gears.table.join(
-- Buttons declared here
)
#+END_SRC
You can see a left click will enable the user to raise the window, but also it will enable the user to move the window (if it is floating of course).
Next comes the actual creation of the titlebar for the client ~c~. For that, we call ~awful.titlebar()~, tell it where the titlebar should be relative to the client and what its setup should be. The full call should look like so:
In the setup, I need to repeat to Awesome the titlebar should be on the left of the client, and I also tell it the layout alignment of the titlebar will be vertical, because I like vertial titlebars. I also first send it three tables:
- The top or left elements of the titlebar (here the top)
- The middle elements of the titlebar
- The bottom or right elements of the titlebar (here the bottom)
You can notice in the setup’s code below that I haven’t included anything in the middle elements, the only elements I am interested in are the top and bottom elements. In the top elements, I have (top to bottom):
- A close button
- A maximize button
- A minimize button
- And an indication to Awesome these elements should be vertically aligned
To make Awesome happy, I also must indicate that the middle elements are vertically aligned, and then I can declare my bottom elements:
- A button for toggling client floating
- And again the indication to Awesome these elements should be vertically aligned
The default Awesome configuration enables the following snippet of code that makes windows hovered by the user’s mouse focused. Just for completeness’ sake, I included it in this document, but be aware this won’t be tangled into my configuration file and focus will not follow my mouse.
It is also possible to change the color of the borders based on client focus. While my clients don’t have any border, they do have a titlebar which color changes based on the client’s focus. This is handled by the following code snippet:
By simply adding a line requesting to spawn a command, it is possible to create some autolaunch. All of my autolaunched apps are launch through a custom script which you can [[file:~/org/config/bin.org::#Autostart-a99e99e7][find here]]. The command gets called with ~awful.spawn.with_shell()~, as you can see below.