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).
![](/var/linux_magazin/storage/images/issues/2022/259/xmonad-tiling-window-manager/figure-10/804876-1-eng-US/Figure-10_large.png)
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.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.