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).

Figure 2: Opening the first application will cover the entire screen.

To open up yet another terminal window, repeat the previous steps of pressing mod+Shift+Return (Figure 3).

Figure 3: Opening the second application will split the entire screen.

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.

Figure 4: dmenu in action.

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.

Figure 5: Opening the third application.

Let us say that you do not like the current tiling layout. Pressing mod+Space will throw the windows into widescreen mode (Figure 6).

Figure 6: All of the applications displayed in widescreen mode.

Or if you wish for the current active tile to be full screen, pressing mod+Space again will do just that (Figure 7).

Figure 7: The active application displayed in fullscreen mode.

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:

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).

Figure 8: The new background.

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
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).

Figure 9: From this point on, you will forever know the time and date inside XMonad.

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).

Figure 10: Xmobar displaying the download and upload speeds on the preferred Ethernet interface port.

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         }


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.


  1. XMonad: https://XMonad.org/
  2. dmenu project page: https://tools.suckless.org/dmenu/
  3. xmobar GitHub repository: https://github.com/jaor/xmobar

The Author

Petros Koutoupis is currently a senior performance software engineer at Cray (now HPE) for its Lustre High Performance File System division. He is also the creator and maintainer of the RapidDisk Project (http://www.rapiddisk.org). Petros has worked in the data storage industry for well over a decade and has helped pioneer the many technologies unleashed in the wild today.

Buy this article as PDF

Express-Checkout as PDF
Price $2.95
(incl. VAT)

Buy Linux Magazine

Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content

  • Tiling Desktops

    Tiling desktops have been experiencing a resurgence in popularity. Here are a few options that can help keep your desktop better organized.

  • Introduction

    This month in Linux Voice.

  • KDE Tiling Solutions

    If you want to reap the benefits of tiling desktops on KDE Plasma, check out these KWin script extensions.

  • Pop!_OS

    Pop!_OS, known for its innovation, customization, and user-friendliness, features one of the easiest tiling desktop options available.

  • Tutorials – WM Tiling

    Regular window managers are so 2016 – install a tiling WM and work faster, smarter, and cooler.

comments powered by Disqus
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.