Difference between revisions of "Xmonad"

From ArchWiki
Jump to navigation Jump to search
m (Example configurations)
m (Other Resources)
Line 386: Line 386:
[[dmenu]] - Dynamic X menu for the quick launching of programs
[[dmenu]] - Dynamic X menu for the quick launching of programs
[[Comparison of Tiling Window Managers]] - Arch wiki article providing an overview of mainstream tiling window managers

Revision as of 15:17, 28 May 2011

This template has only maintenance purposes. For linking to local translations please use interlanguage links, see Help:i18n#Interlanguage links.

Local languages: Català – Dansk – English – Español – Esperanto – Hrvatski – Indonesia – Italiano – Lietuviškai – Magyar – Nederlands – Norsk Bokmål – Polski – Português – Slovenský – Česky – Ελληνικά – Български – Русский – Српски – Українська – עברית – العربية – ไทย – 日本語 – 正體中文 – 简体中文 – 한국어

External languages (all articles in these languages should be moved to the external wiki): Deutsch – Français – Română – Suomi – Svenska – Tiếng Việt – Türkçe – فارسی

xmonad is a tiling window manager for X. Windows are arranged automatically to tile the screen without gaps or overlap, maximizing screen use. Window manager features are accessible from the keyboard: a mouse is optional.

xmonad is written, configured and extensible in Haskell. Custom layout algorithms, key bindings and other extensions may be written by the user in config files.

Layouts are applied dynamically, and different layouts may be used on each workspace. Xinerama is fully supported, allowing windows to be tiled on several physical screens.

For more information, please visit the xmonad website: http://xmonad.org/


xmonad and xmonad-contrib is currently available in the community repo. A build for the current development snapshot (darcs) is in the aur. The following instructions are for xmonad-darcs, the development snapshot.

Development version (xmonad-darcs)

The xmonad-darcs development version can be installed from the AUR, with some additional dependencies in [community]. Install them in the following order:


Starting xmonad

To start xmonad automatically, simply add the command exec xmonad to your startup script (e.g. ~/.xinitrc). GDM and KDM users can create a new session file and then select xmonad from the appropriate Session menu.

Recently, users in #xmonad have stated that the exec is not required; simply adding xmonad as the last line in your startup script is the proper way to start this WM. Please use whichever method works for you. If using ck-launch-session, the exec is probably still required.

Note: By default, xmonad does not set an X cursor, therefore the "cross" cursor is usually displayed which can be confusing for new users (thinking that xmonad has not launched correctly). To set the expected left-pointer, add the following to your startup file (e.g. ~/.xinitrc):

xsetroot -cursor_name left_ptr

Also, xmonad defaults to the U.S. keyboard layout, so if you want e. g. the German one, add:

 setxkbmap -layout de

Example .xinitrc :

 # set the cursor
 xsetroot -cursor_name left_ptr
 # set German keyboard layout
 setxkbmap -layout de
 # start xmonad
 exec ck-launch-session xmonad

If for some reason XMonad doesn't start, check if you have an .xmonad dir in your home dir else create it

 mkdir ~/.xmonad

Configuring xmonad

xmonad users can modify, override or extend the default settings with the ~/.xmonad/xmonad.hs configuration file. Recompiling is done on the fly, with the Mod+q shortcut.

If you find you do not have a directory at ~/.xmonad, run xmonad --recompile to create it.

The "default config" for xmonad is quite usuable and it is achieved by simply running without an xmonad.hs entirely. Therefore, even after you run --recompile you will most likely not have an ~/.xmonad/xmonad.hs file. If you would like to start tweaking things, simply create the file and edit it as described below.

Because the xmonad configuration file is written in Haskell, non-programmers may have a difficult time adjusting settings. For detailed HOWTO's and example configs, we refer you to the following resources:

The best approach is to only place your changes and customizations in ~/.xmonad/xmonad.hs and write it such that any unset parameters are picked up from the built-in defaultConfig.

This is achieved by writing an xmonad.hs like this:

 import XMonad
 main = do
   xmonad $ defaultConfig
     { terminal    = "urxvt"
     , modMask     = mod4Mask
     , borderWidth = 3

This simply overrides the default terminal and borderwidth while leaving all other settings at their defaults (inherited from the function defaultConfig).

As things get more complicated, it can be handy to call configuration options by function name inside the main function, and define these separately in their own sections of your xmonad.hs. This makes large customizations like your layout and manage hooks easier to visualize and maintain.

The above simple xmonad.hs could have been written like this:

 import XMonad
 main = do
   xmonad $ defaultConfig
     { terminal    = myTerminal
     , modMask     = myModMask
     , borderWidth = myBorderWidth
 -- yes, these are functions; just very simple ones
 -- that accept no input and return static values
 myTerminal    = "urxvt"
 myModMask     = mod4Mask -- Win key or Super_L
 myBorderWidth = 3

Also, order at top level (main, myTerminal, myModMask etc.), or within the {} does not matter in Haskell, as long as imports come first.

The following is taken from the 0.9 config file template found here. It is an example of the most common functions one might want to define in their main do block.

   terminal           = myTerminal,
   focusFollowsMouse  = myFocusFollowsMouse,
   borderWidth        = myBorderWidth,
   modMask            = myModMask,
   -- numlockMask deprecated in 0.9.1
   -- numlockMask        = myNumlockMask,
   workspaces         = myWorkspaces,
   normalBorderColor  = myNormalBorderColor,
   focusedBorderColor = myFocusedBorderColor,

   -- key bindings
   keys               = myKeys,
   mouseBindings      = myMouseBindings,
   -- hooks, layouts
   layoutHook         = myLayout,
   manageHook         = myManageHook,
   handleEventHook    = myEventHook,
   logHook            = myLogHook,
   startupHook        = myStartupHook

Exiting xmonad

To end the current xmonad session, press Mod+SHIFT+q (Mod being ALT by default).

Tips and tricks

Complementary applications

There are number of complementary utilities that work well with xmonad. The most common of these include:

Making room for conky or tray apps

Wrap your layouts with avoidStruts from XMonad.Hooks.ManageDocks for automatic dock/panel/trayer spacing:

 import XMonad
 import XMonad.Hooks.ManageDocks
   xmonad $ defaultConfig
     { ...
     , layoutHook=avoidStruts $ Tall ||| Wide ||| Full
     , manageHook=manageHook defaultConfig <+> manageDocks
     , ...

If you ever want to toggle the gaps, this action can be added to your key bindings:

,((modMask x, xK_b     ), sendMessage ToggleStruts)

Using xmobar with xmonad

xmobar is a light and minimalistic text based bar, designed to work with xmonad.
To use xmobar with xmonad, you will need two packages in addition to the xmonad package, these are xmonad-contrib from [community] and xmobar or xmobar-darcs from aur.

Here we will start xmobar from within xmonad, which reloads xmobar whenever you reload xmonad.

Open up ~/.xmonad/xmonad.hs in your favorite editor, and choose one of the two following options:

Option 1: Quick, less flexible

Note: there is also a dzen which you can substitute for xmobar in either case.

Common imports:

import XMonad
import XMonad.Hooks.DynamicLog

The xmobar action starts xmobar and returns a modified config that includes all the options described in the xmonad:Option2: More configurable choice.

main=xmonad=<< xmobar myConfig
myConfig=defaultConfig { modMask=mod4Mask, -- or any other configurations here ... }

Option 2: More Configurable

As of xmonad(-contrib) 0.9, there is a new statusBar function in XMonad.Hooks.DynamicLog. It allows you to use your own configuration for:

  • The command used to execute the bar
  • The PP that determines what's being written to the bar
  • The keybinding to toggle the gap for the bar

Following is an example of how to use it: Template:File

Verify XMobar Config

The template and default xmobarrcs contains this.

At last, open up ~/.xmobarrc and make sure you got StdinReader in the template and run the plugin. E.g.


Now, all you should have to do is either to start, or restart xmonad.

Controlling xmonad with external scripts

Although there is no direct way to interact with xmonad via scripts, you can simulate keypress events using xdotool or other such programs, see this Ubuntu forums thread. This command would simulate the keypress "Super+n":

xdotool key Super+n

Launching another window manager within xmonad

If you are using xmonad darcs, as of January of 2011, you can restart to another window manager from within xmonad. You just need to write a small script, and add stuff to your xmonad.hs. Here is the script.


And here are the modifications you need to add to your xmonad.hs


You also need to add the following keybinding


Just remember to add a comma before or after and change the path to your actual script path.Now just mod-q (restart xmonad to refresh the config), and than hit mod-shift-o and you should have openbox running with the same windows open as in xmonad. To return to xmonad you should just exit openbox. Here is a link to adamvo's xmonad.hs which uses this setup Adamvo's Xmonad.hs

Example configurations

Below are some example configurations from fellow xmonad users. Feel free to add links to your own.


GNOME 3 and Xmonad

With the release of GNOME 3, some additional steps are necessary to make GNOME play nice with Xmonad.

First, add an Xmonad session file for use by gnome-session (/usr/share/gnome-session/sessions/xmonad.session):

[GNOME Session]
Name=Xmonad session

Now create a desktop file for GDM (/usr/share/xsessions/xmonad-gnome-session.desktop):

[Desktop Entry]
Name=Xmonad GNOME
Comment=Tiling window manager
Exec=gnome-session --session=xmonad

Xmonad should now appear in the list of GDM sessions and also play nicely with gnome-session itself.

GDM 2.x/KDM can not find xmonad

You can force GDM to launch xmonad by creating the file xmonad.desktop in the /usr/share/xsessions directory and add the contents:

[Desktop Entry]
Comment=This session starts xmonad

Now xmonad will show in your GDM session menu. Thanks to Santanu Chatterjee for the hint.

For KDM you will need to create the file here as /usr/share/apps/kdm/sessions/xmonad.desktop

Official Doc's are here: Haskell Doc Page

Missing xmonad-i386-linux

Xmonad should automatically create the xmonad-i386-linux file (in $HOME/.xmonad/). If this it not the case you can grab a cool looking config file from the xmonad wiki or create your own. Put the .hs and all others files in .xmonad/ and run the command from the folder:

xmonad --recompile

Now you should see the file.

Problems with Java applications

The standard Java gui toolkit has a hardcoded list of "non-reparenting" window managers. Since XMonad is not in that list, there can be some problems with running some java applications. One of the most common problems is "grey blobs", when the java application renders as a plain grey box instead of rendering the gui.

There is several thing that can help:

  • If you are using openjdk6, you can export _JAVA_AWT_WM_NONREPARENTING=1 .
  • If you are using Sun JRE/JDK, the best solution is usually to use SetWMName. However, its effect may be nullified if one also uses XMonad.Hooks.EwmhDesktops, in which case
 >> setWMName "LG3D"

added to the LogHook may help.

For more details about the problem, refer to the XMonad FAQ.

Large gray areas at the bottom of gvim windows

This problem was mentioned in the forums.

A solution is to make a more pleasing background color: just put the following lines in Template:Filename:

style "vimfix" {
  bg[NORMAL] = "#242424" # this matches my gvim theme 'Normal' bg color.
widget "vim-main-window.*GtkForm" style "vimfix"

Another possible solution would be to first include this in Template:Filename:

import XMonad.Layout.LayoutHints
, layoutHook = layoutHints $ mylayout

where "mylayout" is your layout. Then pressing your macro key plus "n" will adjust the window. To do this automatically, install xdotool from community and start gvim this way:

, ((modm, xK_v), spawn "gvim; xdotool key Super+n")

Replace "Super" (the windows key) with your own macro key, and replace "xK_v" with your own shortcut (xdotool is a way to simulate keyboard events).

Chromium/Chrome won't go fullscreen

If Chrome fails to go fullscreen when F11 is pressed, you can use the XMonad.Hooks.EwmhDesktops extension found in the xmonad-contrib package. Simply add the import statement to your xmonad.hs:

import XMonad.Hooks.EwmhDesktops

and then add handleEventHook = fullscreenEventHook to the appropriate place; for example:

        xmonad $ defaultConfig 
            { modMask            = mod4Mask
            , handleEventHook    = fullscreenEventHook


After a recompile/restart of Xmonad, Chromium should now repond to F11 (fullscreen) as expected.

Other Resources

xmonad - The official xmonad website

xmonad.hs - Template xmonad.hs

xmonad: a guided tour

dzen - General purpose messaging and notification program

dmenu - Dynamic X menu for the quick launching of programs

Comparison of Tiling Window Managers - Arch wiki article providing an overview of mainstream tiling window managers