Difference between revisions of "Xmonad"

From ArchWiki
Jump to: navigation, search
m (Controlling xmonad with external scripts: Clarified wording)
(Problems with Java applications: added Pkg formatting; added line for jre7-openjdk and /etc/profile.d/jre7.sh)
Line 326: Line 326:
===Problems with Java applications===
===Problems with Java applications===
The standard Java GUI toolkit has a hard-coded 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.
The standard Java GUI toolkit has a hard-coded 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 "gray blobs", when the Java application renders as a plain gray box instead of rendering the GUI.
There are several things that may help:
There are several things that may help:
* If you are using openjdk6, you can export {{Codeline|_JAVA_AWT_WM_NONREPARENTING<nowiki>=</nowiki>1}} in {{Filename|/etc/profile.d/openjdk6.sh}}.
* If you are using {{Pkg|openjdk6}}, you can export {{Codeline|_JAVA_AWT_WM_NONREPARENTING<nowiki>=</nowiki>1}} in {{Filename|/etc/profile.d/openjdk6.sh}}.
* If you are using Oracle JRE/JDK, the best solution is usually to use [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-SetWMName.html SetWMName.] However, its effect may be nullified if one also uses XMonad.Hooks.EwmhDesktops, in which case
* If you are using {{Pkg|jre7-openjdk}}, you can export {{Codeline|_JAVA_AWT_WM_NONREPARENTING<nowiki>=</nowiki>1}} in {{Filename|/etc/profile.d/jre7.sh}}.
* If you are using Oracle's JRE/JDK, the best solution is usually to use [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-SetWMName.html SetWMName.] However, its effect may be nullified if one also uses XMonad.Hooks.EwmhDesktops, in which case
   >> setWMName "LG3D"
   >> setWMName "LG3D"
added to the LogHook may help.
added to the LogHook may help.

Revision as of 02:08, 29 October 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/


Template:Package Official and Template:Package Official are currently available in the Official Repositories. A build for the current development snapshot (darcs) is in the AUR. The following instructions are for Template:Package AUR, the development snapshot.

Development version (xmonad-darcs)

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


Starting xmonad

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

Note: Recently, users in #xmonad have stated that Template:Codeline is not required before Template:Codeline; simply adding Template:Codeline 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 Template:Codeline, the Template:Codeline 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. Template:Filename):

Also, xmonad defaults to the U.S. keyboard layout, so if you want, for example, the German keyboard layout, add the following to Template:Filename or read more about setting keyboard layouts here:

 setxkbmap -layout de

Example Template:Filename:

 # 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 does not start, check if you have an Template:Filename directory in your home directory. If not, create it:

 mkdir ~/.xmonad

Configuring xmonad

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

If you find you do not have a directory at Template:Filename, run Template:Codeline to create it.

The "default config" for xmonad is quite usable and it is achieved by simply running without an Template:Filename entirely. Therefore, even after you run Template:Codeline you will most likely not have an Template:Filename 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 Template:Filename and write it such that any unset parameters are picked up from the built-in defaultConfig.

This is achieved by writing an Template:Filename 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 Template:Filename. This makes large customizations like your layout and manage hooks easier to visualize and maintain.

The simple Template:Filename from above 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 Template:Keypress+Template:Keypress+Template:Keypress. By default, Template:Keypress is the Template:Keypress key.

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 $ layoutHook defaultConfig
     , 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 Template:Package Official package. These packages are Template:Package Official and Template:Package Official from the Official Repositories, or you can use Template:Package AUR from the AUR instead of the official xmobar.

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

Open Template:Filename in your favorite editor, and choose one of the two following options:

Option 1: Quick, less flexible

Note: There is also Template:Package Official which you can substitute for Template:Codeline 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 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 is 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 xmobarrc contains this.

At last, open up Template:Filename and make sure you have 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

There are at least two ways to do this.

Firstly, you can use the following Xmonad extension, XMonad.Hooks.ServerMode.

Secondly, you can simulate keypress events using Template:Package Official or similar programs. See this Ubuntu forums thread. The following command would simulate the keypress Template:Keypress+Template:Keypress:

xdotool key Super+n

Launching another window manager within xmonad

If you are using Template:Package AUR, 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 Template:Filename. Here is the script.


And here are the modifications you need to add to your Template:Filename:


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 Template:Keypress+Template:Keypress (restart xmonad to refresh the config), and than hit Template:Keypress+Template:Keypress+Template:Keypress 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 Template:Filename 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.

  • brisbin33 :: complex and simpler branches, importable dzen and scratchpad modules, very readable :: config screenshot
  • jelly :: Configuration with prompt, different layouts, twinview with xmobar :: xmonad.hs
  • MrElendig :: Simple configuration, with xmobar :: xmonad.hs, .xmobarrc, screenshot.
  • thayer :: A minimal mouse-friendly config ideal for netbooks :: configs screenshot
  • vicfryzel :: Beautiful and usable xmonad configuration, along with xmobar configuration, xinitrc, dmenu, and other scripts that make xmonad more usable. :: git repository, screenshot.
  • vogt :: Check out adamvo's config and many others in the official Xmonad/Config archive


GNOME 3 and xmonad

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

First, add an xmonad session file for use by gnome-session (Template:Filename):

[GNOME Session]
Name=Xmonad session

Now create a desktop file for GDM (Template:Filename):

[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 cannot find xmonad

You can force GDM to launch xmonad by creating the file Template:Filename in the Template:Filename 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 Template:Filename

Official documentation can be found here: Haskell Documentation Page

Missing xmonad-i386-linux or xmonad-x86_64-linux

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

xmonad --recompile

Now you should see the file.

Note: A reason you may get an error message saying that xmonad-x86_64-linux is missing is that Template:Package Official is not installed.

Problems with Java applications

The standard Java GUI toolkit has a hard-coded 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 "gray blobs", when the Java application renders as a plain gray box instead of rendering the GUI.

There are several things that may help:

 >> setWMName "LG3D"

added to the LogHook may help.

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

Empty space at the bottom of gvim or terminals

See Vim#Empty space at the bottom of gvim windows for a solution which makes the area match the background color.

For rxvt-unicode, you can use Template:Package AUR.

You can also configure xmonad to respect size hints, but this will leave a gap instead. See the documentation on Xmonad.Layout.LayoutHints.

Chromium/Chrome will not go fullscreen

If Chrome fails to go fullscreen when Template:Keypress is pressed, you can use the XMonad.Hooks.EwmhDesktops extension found in the Template:Package Official package. Simply add the Template:Codeline statement to your Template:Filename:

import XMonad.Hooks.EwmhDesktops

and then add Template:Codeline to the appropriate place; for example:

        xmonad $ defaultConfig
            { modMask            = mod4Mask
            , handleEventHook    = fullscreenEventHook


After a recompile/restart of Xmonad, Chromium should now respond to Template:Keypress (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