Skip to content
Search

Xmonad

lastmod 2025-08-09created 2020-06-2262 edits

xmonad is a dynamically tiling X11 window manager that is written and configured in Haskell. In a normal WM, you spend half your time aligning and searching for windows. xmonad makes work easier, by automating this.

Categories

Plugins

To review

Utilities

  • feh: Image preview, setting background images, etc.
  • maim: Screenshots

Installation

If you use xmonad, install it as follows.

$ sudo pacman -S xmonad xmonad-contrib

Note

After upgrading, you must run the xmonad --recompile command. Otherwise, there may be problems finding shared libraries.

Starting

Run xmonad with xinit.

# .xsession

xrdb -merge .Xresources
xpmroot ~/background.xpm &

$HOME/bin/xmonad

Bar/Tray

Compositing window manager

Flags

The flags are as follows:

--recompile
Recompiles the configuration in ~/.xmonad/xmonad.hs.
--restart
Restarts the currently running xmonad process.
--replace
Replaces the current window manager with xmonad.
--version
Display the xmonad version
--verbose-version
Display the detailed xmonad version

Key binding

Xmbindings.png
Xmonad_cheatsheet.png

Default keyboard bindings

mod-shift-return
Launch the default terminal
mod-p
Launch dmenu
mod-shift-p
Launch gmrun
mod-shift-c
Close the currently focused window.
mod-space
Rotate windows through the available layout algorithms.
mod-shift-space
Reset the layout of the current workspace to the default.
mod-n
Resize viewed windows to the correct size
mod-tab
Move focus to the next window
mod-shift-tab
Move focus to the previous window
mod-j
Move focus to the next window
mod-k
Move focus to the previous window
mod-m
Move focus to the master window
mod-return
Swap the focused window and the master window
mod-shift-j
Swap the focused window with the next window
mod-shift-k
Swap the focused window with the previous window
mod-h
Shrink the master area
mod-l
Expand the master area
mod-t
Puts the window back into tiling. Use it when you want to tile a floating window again.
mod-comma
Increment the number of windows in the master area
mod-period
Deincrement the number of windows in the master area
mod-shift-q
Quit xmonad
mod-q
Restart xmonad
mod-shift-slash
Run xmessage with a summary of the default keybindings (useful for beginners)
mod-[1..9]
Switch to workspace N
mod-shift-[1..9]
Move client to workspace N
mod-{w,e,r}
Switch to physical/Xinerama screens 1, 2, or 3
mod-shift-{w,e,r}
Move client to screen 1, 2, or 3
mod-button1
Set the window to floating mode and move by dragging
mod-button2
Raise the window to the top of the stack
mod-button3
Set the window to floating mode and resize by dragging

Customization

xmonad is customized in ~/.xmonad/xmonad.hs, and then restarting with mod-q.

You can find many extensions to the core feature set in the xmonad- contrib package, available through your package manager or from xmonad.org.

Modular Configuration

As of xmonad-0.9, any additional Haskell modules may be placed in ~/.xmonad/lib/ are available in GHC's searchpath. Hierarchical modules are supported: for example, the file ~/.xmonad/lib/XMonad/Stack/MyAdditions.hs could contain:

module XMonad.Stack.MyAdditions (function1) where
    function1 = error "function1: Not implemented yet!"

Your xmonad.hs may then import XMonad.Stack.MyAdditions as if that module was contained within xmonad or xmonad-contrib.

List of Tiling window manager

Troubleshooting

Xmonad freezing problem

Xmonad takes the output of windows and writes it to a pipe for logging, and it was blocking because the pipe had filled up. That is why it would block once every few days if I worked steadily in a single window (emacs, etc.), and freeze before long if I switched back and forth between several windows. Meanwhile, xmobar, the status bar of Xmonad, had been configured with StdinReader, which reads stdin and prints it on screen. The problem was that this StdinReader had died.

Looking further into why StdinReader dies, it turns out that hGetLine() cannot handle UTF8 code. Online sources say handling it with System.IO.UTF8.hGetLine fixes it, but when I actually tried it, it still died. After trying various things, I ended up setting the handle to latin1 encoding in xmobar's StdinReader handling code. After that it no longer dies. In the test code below, assuming bar.txt contains a UTF8 string, it kept raising the error hGetLine: invalid argument (Invalid or .... multibyte or wide character) until x was set to latin1.

import IO
import System.IO
import System.IO.UTF8

main = do x <- openFile "/tmp/bar.txt" ReadMode
          hSetEncoding x System.IO.latin1
          y <- System.IO.UTF8.hGetLine x
          IO.putStr y

GNOME with xmonad

The simplest solution to this problem for me was to use

import XMonad
import XMonad.Config.Gnome

main = do
    xmonad $ gnomeConfig

instead of defaultConfig in my ~/.xmonad/xmonad.hs file.

FullScreen SDL Game

I don't play games on my xmonad machines, but maybe this will help. Does SDL use the EWMH fullscreen hint?

I import XMonad.Hooks.EwmhDesktops and then have this in my manage hooks:

isFullscreen --> doFullFloat

I also create an ewmh config object:

ewmhConfig = ewmh defaultConfig

And then I compose ewmhConfig into my manage hooks, layout hooks, and event hooks (ewmhDesktopsEventHook). Oh, and I put the fullscreenEventHook also in with the event hooks.

See also

Favorite site

Guide

author Zer0 sitemap