Exploring the XMonad tiling window manager
General Usage
It is important that you remember your mod key. I will be referencing this button a lot in this guide. On a traditional keyboard, this will be your Alt key (unless it is remapped), but if you are on a Macintosh-style keyboard, it will be your Option key. Alt is the default, and I will show how to remap this later in this article. Now, launch a first terminal window by pressing mod+Shift+Return. Viola! A terminal window will suddenly appear and completely cover the screen (Figure 2).
To open up yet another terminal window, repeat the previous steps of pressing mod+Shift+Return (Figure 3).
Each new tile (sometimes referred to as window pane) secures its location to the left while the previous one(s) get shifted toward the right.
But what if you do not want a terminal? This is where dmenu
comes into the picture. Press mod+P to invoke the dmenu
. It will be located at the very top of your screen in its own panel (Figure 4). dmenu
supports autocompletion which can and probably will come in handy in the future, but for now I will launch the Firefox web browser.
As one would expect, the result will showcase three tiled application windows (Figure 5). Note: The application or tile in focus will be highlighted in red. A newly opened tile will hold the focus and remain active until you either move your mouse cursor to the desired pane or you press mod+K or mod+J to move focus down or up in your workspace.
Let us say that you do not like the current tiling layout. Pressing mod+Space will throw the windows into widescreen mode (Figure 6).
Or if you wish for the current active tile to be full screen, pressing mod+Space again will do just that (Figure 7).
XMonad supports multiple workspaces (nine in total), and you can repeat the previous exercises across all of them by using mod+1 for workspace one, mod+2 for workspace two, and so forth.
Customizing XMonad
I will now shift the focus to customizing the desktop environment. Who wants to log into a machine and be greeted by a black screen as empty as my soul? In order to accomplish this, you will need to leverage the magic workings of the lightweight image viewer package called feh
. To install feh
type:
$ sudo apt install feh
And using a text editor, create the file ~/.xsessionrc
. Add the following contents to that file:
#!/bin/bash feh --bg-scale /usr/share/backgrounds/Sunset_of_Pelopononnesus_by_Simos_Xenitellis.jpg &
Note: You can replace the image and its path with one of your choosing (Figure 8).
If the ~/.xsessionrc
file already exists, then append the second line from the above example to that file.
You can immediately run this configuration by typing:
$ source ~/.xsessionrc
Or you can log out (mod+Shift+Q) and log back in.
By now, you may have come to the conclusion that XMonad is a bit lacking in the system information department. For instance, what time is it? What is the date? Where is my battery life at, or where can I obtain network statistics on my connected Ethernet interface port? Yes, you can obtain all these answers from the command line, but if one can configure a way to have it all displayed in a panel or menubar, wouldn't that be even better?
Here is where things get really exciting. Xmobar [3] will fill in the gaps here. It is a minimalist text-based status bar, and you install it with:
$ sudo apt install xmobar
I will start with a simple time and date display in the status bar. In order to format xmobar, I need to create (or modify) the ~/.xmobarrc
file in the home directory and place the contents of Listing 1 in that file.
Listing 1
Place in .xmobarrc
01 Config { font = "-*-Fixed-Bold-R-Normal-*-13-*-*-*-*-*-*-*" 02 , borderColor = "black" 03 , border = TopB 04 , bgColor = "black" 05 , fgColor = "grey" 06 , lowerOnStart = False 07 , hideOnStart = False 08 , allDesktops = True 09 , position = TopW L 100 10 , overrideRedirect = False 11 , commands = [ Run Date "%a %b %_d %Y %H:%M:%S" "date" 10 12 ] 13 , sepChar = "%" 14 , alignSep = "}{" 15 , template = " }{ <fc=#ee9a00>%date%</fc> " 16 }
It is especially important to include the following three lines as they will prevent xmobar from disappearing as soon as you open new application tiles:
, lowerOnStart = False , hideOnStart = False , allDesktops = True
The following lines run and format the output of the date
command:
, commands = [ Run Date "%a %b %_d %Y %H:%M:%S" "date" 10 ]
The template
lines format the placement, style, and color of the generated output:
, template = " }{ <fc=#ee9a00>%date%</fc> " }
Next, tell XMonad to load xmobar at the startup (i.e., login) of the desktop environment. In order to do this, modify the ~/.XMonad/XMonad.hs
Haskell file (Listing 2). Most of what you find in Listing 2 is your standard template for loading xmobar.
Listing 2
Loading xmobar
01 import XMonad 02 import XMonad.Hooks.DynamicLog 03 import XMonad.Hooks.ManageDocks 04 import XMonad.Util.Run(spawnPipe) 05 import XMonad.Util.EZConfig(additionalKeys) 06 import System.IO 07 08 main = do 09 xmproc <- spawnPipe "/usr/bin/xmobar /home/petros/.xmobarrc" 10 XMonad $ defaultConfig 11 { manageHook = manageDocks <+> manageHook defaultConfig 12 , layoutHook = avoidStruts $ layoutHook defaultConfig 13 , handleEventHook = handleEventHook defaultConfig <+> docksEventHook 14 , logHook = dynamicLogWithPP xmobarPP 15 { ppOutput = hPutStrLn xmproc 16 , ppTitle = xmobarColor "green" "" . shorten 50 17 , ppHiddenNoWindows = xmobarColor "grey" "" 18 } 19 , modMask = mod4Mask -- Rebind Mod to the Windows key 20 } `additionalKeys` 21 [ ((mod4Mask .|. shiftMask, xK_z), spawn "xscreensaver-command -lock") 22 , ((controlMask, xK_Print), spawn "sleep 0.2; scrot -s") 23 , ((0, xK_Print), spawn "scrot") 24 ]
It is especially important to include the lines
, handleEventHook = handleEventHook defaultConfig <+> docksEventHook
immediately after:
{ manageHook = manageDocks <+> manageHook defaultConfig , layoutHook = avoidStruts $ layoutHook defaultConfig
This too will help prevent xmobar from disappearing as soon as the applications launch.
You will also notice that your mod key is now remapped to your Super (or Windows) key. This will probably be more convenient for most.
Now that the files are created or modified, you will need to log out of and back into the desktop environment. As soon as you do, the Haskell file will recompile and you should immediately notice an informative panel at the top of the screen (Figure 9).
We will add more information to xmobar. Revisit the original ~/.xmobarrc
file and modify the commands
field to register the following:
, commands = [ Run Network "enp0s3" ["-L","0","-H","32","-normal","green","--high","red"] 10 , Run Date "%a %b %_d %Y %H:%M:%S" "date" 10 ]
And modify the template
field with:
, template = " }{ %enp0s3% | <fc=#ee9a00>%date%</fc> " }
As soon as you reload xmobar, a new field showcasing the network speeds on interface enp0s3
will be noticeably present (Figure 10).

If this were a laptop and you also wanted to add battery life status, only a couple modifications would need to be made to the updated ~/.xmobarrc
file (Listing 3).
Listing 3
.xmobarrc Updates
01 Config { font = "-*-Fixed-Bold-R-Normal-*-13-*-*-*-*-*-*-*" 02 , borderColor = "black" 03 , border = TopB 04 , bgColor = "black" 05 , fgColor = "grey" 06 , lowerOnStart = False 07 , hideOnStart = False 08 , allDesktops = True 09 , position = TopW L 100 10 , overrideRedirect = False 11 , commands = [ Run Network "enp0s3" ["-L","0","-H","32","--normal","green","--high","red"] 10 12 , Run BatteryP ["BATC"] 13 ["-t", "<acstatus><watts> (<left>%)", 14 "-L", "10", "-H", "80", "-p", "3", 15 "--", "-O", "<fc=green>On</fc> - ", "-o", "", 16 "-L", "-15", "-H", "-5", 17 "-l", "red", "-m", "blue", "-h", "green"] 18 600 19 , Run Date "%a %b %_d %Y %H:%M:%S" "date" 10 20 ] 21 , sepChar = "%" 22 , alignSep = "}{" 23 , template = " }{ %battery% | %enp0s3% | <fc=#ee9a00>%date%</fc> " 24 }
Conclusion
This article described the different types of window managers for graphical desktop environments and also focused on the very powerful and lightweight tiling manager, XMonad. Once you get used to the various aspects and functions of a tiling graphical environment, your fingers never have to leave the keyboard, and your productivity is never limited. Besides, you can even expand more on xmobar and add more information relevant to you and your operating environment. It does not need to end here.
Infos
- XMonad: https://XMonad.org/
- dmenu project page: https://tools.suckless.org/dmenu/
- xmobar GitHub repository: https://github.com/jaor/xmobar
« Previous 1 2
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.
News
-
elementary OS 7.1 Now Available for Download
The team behind elementary OS has released the latest version of its operating system with a focus on personalization, inclusivity, accessibility, and privacy.
-
The GNU Project Celebrates Its 40th Birthday
September 27 marks the 40th anniversary of the GNU Project, and it was celebrated with a hacker meeting in Biel/Bienne, Switzerland.
-
Linux Kernel Reducing Long-Term Support
LTS support for the Linux kernel is about to undergo some serious changes that will have a considerable impact on the future.
-
Fedora 39 Beta Now Available for Testing
For fans and users of Fedora Linux, the first beta of release 39 is now available, which is a minor upgrade but does include GNOME 45.
-
Fedora Linux 40 to Drop X11 for KDE Plasma
When Fedora 40 arrives in 2024, there will be a few big changes coming, especially for the KDE Plasma option.
-
Real-Time Ubuntu Available in AWS Marketplace
Anyone looking for a Linux distribution for real-time processing could do a whole lot worse than Real-Time Ubuntu.
-
KSMBD Finally Reaches a Stable State
For those who've been looking forward to the first release of KSMBD, after two years it's no longer considered experimental.
-
Nitrux 3.0.0 Has Been Released
The latest version of Nitrux brings plenty of innovation and fresh apps to the table.
-
Linux From Scratch 12.0 Now Available
If you're looking to roll your own Linux distribution, the latest version of Linux From Scratch is now available with plenty of updates.
-
Linux Kernel 6.5 Has Been Released
The newest Linux kernel, version 6.5, now includes initial support for two very exciting features.