Xmonad/Using xmonad in Gnome

From HaskellWiki
< Xmonad
Revision as of 03:32, 8 December 2009 by Sereven (talk | contribs) (Setting up Gnome to use Xmonad)

Jump to: navigation, search



A screenshot of xmonad cooperating with gnome

Xmonad makes an excellent drop-in replacement for Gnome's default window manager (metacity) giving you a slick tiling window manager. This guide will help you set up Gnome to use Xmonad 0.9.

This is an update to the previous page on Xmonad/Using xmonad in Gnome/0.6.

Setting up Gnome to use Xmonad

Overall most people on a variety of distros seem to get best results by using an applications/xmonad.desktop file and telling gnome to use xmonad instead of metacity by running:

# gconftool-2 -s /desktop/gnome/session/required_components/windowmanager xmonad --type string
Doing this from inside a full gnome session will replace metacity with xmonad and continue to run all the other gnome daemons and apps. See below to set up a separate customized xmonad or ~/.xsession based session separate from your gnome one.

For xmonad to start automatically on login you need an applications/xmonad.desktop file on your system. If your distro doesn't provide it, create the following file:

$ cat /usr/share/applications/xmonad.desktop
[Desktop Entry]

To run a separate xmonad session in addition to gnome session(s) you need an xsessions/xmonad.desktop file. To start a minimal xmonad session from gdm (see notes* below to run more than just xmonad on login), create the following file:

$ cat /usr/share/xsessions/xmonad.desktop 
[Desktop Entry]
Comment=Lightweight tiling window manager

Your display manager must also be able to find the xmonad executable. If you are not using your distro package manager to install xmonad, for best results configure your build to install xmonad to a location in the system environment like /usr/local/bin/.

*NOTE: Using an xsessions/xmonad.desktop file that runs a custom script xmonad.start instead of just plain xmonad is also how to add other startup actions to the gdm xmonad.desktop startup, such as starting gnome daemons, apps, etc. See arjuna's blog for more details. (simono says: Creating /usr/share/xsessions/xmonad.desktop and /usr/local/bin/xmonad.start files is the preferred method for configuring an alternative window manager. The applications/xmonad.desktop file is still required.) However, see the xsession section below to continue using the classic ~/.xsession method to run a custom session.

Ubuntu Karmic

Follow the above general instructions. Most people will probably want to use the custom start script discussed in arjuna's blog, or use gconftool to replace metacity in a full gnome session running all the other supporting gnome apps. You may also wish to install xterm if you don't already have it, since it's the terminal used by the default xmonad setup, at least till you get the gnomeConfig up and running as discussed in later sections.

using xsession under karmic

*NOTE:Ubuntu Karmic Koala users still can use their ~/.xsession scripts to run xmonad. For this, you need:

1. sudo mkdir /etc/X11/sessions

2. put into /etc/X11/sessions/Xsessions.desktop:

[Desktop Entry]
Comment=This runs ~/.xsession

3. Than Xsession entry will appear in gdm, and will work as it worked for many years.

WINDOW_MANAGER variable looks still working, you can use smth like:

export WINDOW_MANAGER="/path/to/xmonad"
exec gnome-session 

in your ~/.xsession

For more info on this, check gdm bug description at launchpad [1].

Ubuntu Jaunty

At least 3 XMonad users have found that the ~/.gnomerc will not work on Jaunty Ubuntu when one is upgrading from Intrepid; apparently the ~/.gconf/ directory is incompatible or something, so Gnome/Ubuntu will not read .gnomerc and any settings in it will be ignored.

The work-around is essentially to remove .gconf entirely. On the next login, a fresh default .gconf will be created and .gnomerc will be read. This of course implies that one's settings and preferences will also be removed, and one will have to redo them. (Copying over selected directories from the old .gconf to the new one may or may not work.)

Or alternatively, the following worked for me (without touching .gconf or .gnomerc or exports): Add an xmonad launcher in the gnome-session-properties and then execute:

   $ gconftool -t string -s /desktop/gnome/applications/window_manager/current xmonad
   $ gconftool -t string -s /desktop/gnome/session/required_components/windowmanager xmonad
   $ killall metacity; xmonad &

Also make sure to add the /usr/share/applications/xmonad.desktop file shown above, if it's not already present. This lets gnome know that xmonad is a windowmanager and where to look for it.

Ubuntu Intrepid

This forum thread has instructions for making Gnome play nice with xmonad on intrepid.

Fedora 10 and further links

This mailing list thread contains fedora 10 specific setup instructions, but also a bunch of other gnome setup links if you are having trouble with the above methods.

None of this worked for me (Colin Adams). What did work was to start gconf-editor and change desktop/gnome/session/required_components/windowmanager from metacity to $HOME/bin/xmonad . I then have to type "xmonad" from a terminal. (Likely the /usr/share/applications/xmonad.desktop file was missing. Generally this is the cause of xmonad not starting on login. Check ~/.xsession-errors for additional clues.)

Using the startup applications menu to modify your gnome session

You can also replace metacity in your full gnome session by using the gnome menus to create a new item in the System>Preferences>Startup Applications menu Programs tab to run xmonad as window manager. (Disable automatic saving of session components to use this setup method.)

For example, for Name: you could use "Window Manager XMonad", then for Program: use xmonad. Un-check the old "Window Manager" one with Program gnome-wm (don't delete or over-write it so you can switch back if you want) then click the checkbox to turn on the new "Window Manager XMonad" entry instead, log out and log back in choosing gnome-session. If it's not already there, this will create the applications/xmonad.desktop file discussed above. (Not a great method for people who switch frequently between metacity, compiz, and xmonad.)

Configure Xmonad to interoperate with Gnome

xmonad and gnome-panel

Using the Config.Gnome module

For xmonad-0.8 or greater, see Basic DE Integration for a simple three line xmonad.hs configuration that:

  • integrates docks and gnome-panel using ewmh's
  • allows gap-toggling
  • binds the gnome run dialog to mod-p, and mod-shift-q to save your session and logout
  • otherwise keeps xmonad defaults.

It is a good starting point. You can then come back and add some of the features below once everything's working.

Once the Config.Gnome module set up, you may want to customize these gnome settings.


Use EZConfig to add keybindings. Note that you must use gnomeConfig whereever defaultConfig is mentioned.

import XMonad
import XMonad.Util.EZConfig
main = xmonad $ gnomeConfig
        { terminal = "urxvt"
        , modMask = mod4Mask -- set the mod key to the windows key
                 [ ("M-m", spawn "echo 'Hi, mom!' | dzen2 -p 4")
                 , ("M-<Backspace>", withFocused hide) -- N.B. this is an absurd thing to do


Be sure to include the default gnome manageHook when overriding manageHooks so that xmonad can leave a gap for gnome-panel:

main = xmonad gnomeConfig
   , manageHook = composeAll
        [ manageHook gnomeConfig
        , title =? "foo" --> doShift "2"
        -- needs: import XMonad.Hooks.ManageHelpers (isFullscreen,doFullFloat)
        , isFullscreen --> doFullFloat


When overriding the default layouts, you must manually apply the desktopLayoutModifiers layout modifier.

import XMonad.Config.Desktop (desktopLayoutModifiers)
main = xmonad gnomeConfig
    , layoutHook = desktopLayoutModifiers (Tall 1 0.03 0.5 ||| Full)
A screenshot of xmonad cooperating with gnome

Tweak Gnome to work better with Xmonad

These are a few steps that greatly improves the experience of running Xmonad under Gnome. Note that on some systems the binary gconftool is called gconftool-2.

Disable the Nautilus desktop

This step is not required, but some users prefer to disable the desktop. From the command line execute:

   gconftool --type boolean --set /apps/nautilus/preferences/show_desktop false

(Using recent gnome and xmonad I found that it was necessary.)

Changing desktop background

If you need to change the workspace background programmatically (i.e. from some extension setting in xmonad's configuration file), you can use the command:

   gconftool --type string --set /desktop/gnome/background/picture_filename "/path/to/your/image.png"

Display XMonad logHook in gnome-panel

See xmonad log applet for a panel applet to display xmonad's logHook in gnome-panel via dbus

Key bindings for switching desktops

In 1 dimension: CycleWS

Gnome lays out the desktops in a row by default, and uses Ctrl+Alt+Left/Right for switching desktops left/right. To get similar behaviour in Xmonad, you need to add some keybindings. The contrib module XMonad.Actions.CycleWS has some useful actions for cycling workspaces:

main = xmonad gnomeConfig
    { modMask = mod4Mask }
    -- moving workspaces
    , ("M-<Left>",    prevWS )
    , ("M-<Right>",   nextWS )
    , ("M-S-<Left>",  shiftToPrev )
    , ("M-S-<Right>", shiftToNext )

In 2 dimensions: Plane

If Gnome is configured to lay out desktops in more than one line, it's possible to navigate with Ctrl+Alt+Up/Bottom also. The contrib module XMonad.Actions.Plane, available in the xmonad-0.8 or greater. The keybindings can be incorporated in with EZConfig as such:

import XMonad
import XMonad.Config.Gnome
import XMonad.Actions.Plane
import XMonad.Util.EZConfig
import qualified Data.Map as M
main = xmonad $ gnomeConfig
    { terminal = "urxvt"
    , modMask = mod4Mask -- set the mod key to the windows key
        [ ("M-m", spawn "echo 'Hi, mom!' | dzen2 -p 4")
        , ("M-<Backspace>", withFocused hide) -- N.B. this is an absurd thing to do
    M.toList (planeKeys mod4Mask GConf Finite)

Actions.WorkspaceCursors can be used to navigate workspaces arranged in three or more dimensions.

Logging out of the Gnome session vs. quitting Xmonad

When running Xmonad as above, it is launched by gnome-session, the "Gnome session manager." Quitting Xmonad in this situation will not log you out. If you make no changes, using mod+shift+q will leave you with all your applications still running and no window manager to navigate them! There are several remedies for this.

  * Run 'xmonad &' from a command line.
  * Quit X using Alt-Ctrl-Backspace.
  * Rebind mod+shift+q

Rebind mod+shift+q

To avoid exiting Xmonad and being stuck with no window manager, you might rebind mod+shift+q to execute the gnome-session "log out" functionality. This will of course prevent you from "quitting" Xmonad in the normal way, which may or may not be desirable. When the session logs out, the X11 server is terminated, which will in turn terminate all running X11 applications, including Xmonad.

(TODO: improve the description of changes that need to be made here.)

   , ("M-S-q", spawn "gnome-session-save --gui --logout-dialog") )

Configure rudimentary power management

It might be useful to include bindings for hibernation, screen locking, and other assorted basic functions. While Gnome provides the capability to do so, it's functionality is limited (Mod4 cannot be used as a mask), and you may prefer to have Xmonad manage it. Fortunately, these things can be controlled from the command line, and the following bindings may help. (NB: These are for one handed use of Dvorak control; make sure to bind them to something more fitting. They also use mod1 not to clash with mod4 by accident.)

    -- Lock Screen
    , ("M-S-l",    spawn "gnome-screensaver-command -l")
    -- Logout
    , ("M1-M-S-l", spawn "gnome-session-save --gui --kill")
    -- Sleep
    , ("M1-S-'",   spawn "gnome-power-cmd.sh suspend")
    -- Reboot
    , ("M1-S-,",   spawn "gnome-power-cmd.sh reboot")
    -- Deep Sleep
    , ("M1-S-.",   spawn "gnome-power-cmd.sh hibernate")
    -- Death
    , ("M1-S-p",   spawn "gnome-power-cmd.sh shutdown")

Configure the session manager to relaunch Xmonad

You can configure the Gnome Session Manager to restart Xmonad whenever it exits (i.e., if you haven't rebound mod-shift-q.) This is rarely a useful feature as xmonad has its builtin compile-and-restart (mod-q), but it will prevent you from accidentally ending up with no window manager and no way to launch one.

However, as of version 0.7, XMonad does not itself communicate with any session managers in they way they prefer, so setting things up takes some hackery:

(TBD: steps, see also Xmonad/Using_xmonad_in_Gnome/0.5#Preparing_your_GNOME_session)