2 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 running a full gnome session replacing only gnome's window manager. They tell gnome-session to use xmonad instead of metacity by running:

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 'man gnome-wm' for details. 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:

Alternatively, you can create the above as ~/.local/share/applications/xmonad.desktop for the current user only.

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:

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.

2.1 Gnome3

This blog post has instructions for integrating xmonad with Gnome3 on archlinux. It should also work for most other distros that don't work out of the box. (E.g. Fedora 15 should "just work".) Note that these instructions will not work with a fresh Ubuntu 11.10 install, since bits of Gnome are missing in the release. (See below for details.)

Note also that many Gnome3 features such as the gnome shell are part of the mutter window manager. You can't use part of mutter plus part of some other window manager.

2.2 A Simple Hybrid Alternative

There is also a hybrid method that seems to work much more simply and easily than the custom start script, while still allowing XMonad to be chosen as a separate session. applications/xmonad.desktop and xsessions/xmonad.desktop are created as above. And, as above, xsessions/xmonad.desktop points to a custom xmonad.start script. But, the contents of the xmonad.start script are simply the following:

export WINDOW_MANAGER=xmonad
gnome-session

This gives all the bells and whistles of gnome, including integrated logout support, etc, while also allowing xmonad and gnome to be selected as separate sessions from the login screen. Note that if you go this road with Ubuntu 10.04 (tested with gnome 2.30.0), you will also need to unset the gconf windowmanager setting.

2.3 Ubuntu

I had tried above methods described by "simple hybrid", but they are not staight forward and didn't work.

export WINDOW_MANAGER=/path to xmonad
gnome-sesson

If once I execute "gnome-wm" manually, after that it works, I got xmonad integrated in gnome well. However, once I switch to my gnome session, and then return back to my xmonad session, the xmonad window manager isn't run, just as I log into the gnome session.

After delving into gnome-wm script and some analysis and many try, I found out why the plain script did not work. Because I had turned on the "auto save gnome session" function, I guess gnome-session wouldn't call gnome-wm again when I change from gnome session to xmonad session.
So I disable the save session function, and remove the files in .config/gnome-session/saved-session/*.

Finally it works! This indirectly prove the above guess is right.
Actually I had put this script to xmonad-custom.start, then I can have gnome and xmonad session seperated, and they don't interfere with the other. I think this method is simple yet elegant, and easy to understand.

2.4 Ubuntu Oneiric

The syntax for Gnome session descriptions is slightly different in Gnome 3. To set up Gnome to use Xmonad in Oneiric, you first need to add a new session description to /usr/share/gnome-session/sessions/xmonad.session which looks something like:

This should add an entry to the sessions menu in LightDM, called Xmonad. Select this option and log in to start a Gnome session with Xmonad goodness.

Note that Ubuntu's flavour of Gnome 3 shows the menu bar for the focused window at the top of the screen, presumably because Unity wants it there. Even in Classic Gnome, it's there, hiding behind gnome-panel. Annoying, but you can cover it up with Xmobar or something if you want. Maybe there's something in dconf-editor that'll make it go away?

2.5 Ubuntu Natty

2.5.1 Using New Session Files

On Natty you need to create a new gnome session description at

/usr/share/gnome-session/sessions/xmonad.session which should look something like this

I also had to uninstall the appmenu stuff to get my menus back for some reason. Not sure what the problem with the global menus are in Natty since the Gnome Classic session gets normal in-window menus and the appmenu panel still works. With xmonad it just seems totally broken.

2.5.2 Using GConf

Rather than having an administrator create new .desktop and .session files, an unprivileged user may configure gnome-wm to use Xmonad as Gnome's window manager through GConf as described at #Setting_up_Gnome_to_use_Xmonad.

This approach worked in previous versions of Ubuntu but at present with Natty, if /usr/lib/nux/unity_support_test is not installed, an administrator may have to comment out or remove the IsRunnableHelper line from /usr/share/xsessions/gnome-classic.desktop:

# IsRunnableHelper=/usr/lib/nux/unity_support_test --compiz

Logging in using the "Ubuntu Classic" session will then launch Xmonad and all the other Gnome widgets. See also Ubuntu Bug#774357.

2.6 Ubuntu Karmic

Follow the above general instructions. Most people will probably want to use the "simple hybrid method", .xsession, 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.

2.6.1 using xsession under karmic

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

2.6.2 xmonad-0.9 for karmic

2.7 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:

2.9.1 Fedora 15

Installing xmonad or bluetile should "just work" out of the box. Select "xmonad GNOME" or "GNOME + bluetile" at the gdm prompt.

2.9.2 Fedora 10 and further links

This old 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.

2.10 Using the startup applications menu to modify your gnome session

An alternative to using gconftool to change the window manager in a gnome session:

On many distros you can 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 on logout" to use
this setup method.)

For example, for Name: you could use "Window Manager XMonad", then
for Program: use xmonad. Un-check the old Metacity
one (typically called Window Manager and using Programgnome-wm). Don't delete or over-write it so you can switch back if you want. Click the checkbox to turn on the new "Window Manager XMonad" entry instead, save your session, 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.)

3 Configure Xmonad to interoperate with Gnome

3.1 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.

3.1.1 Keys

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

4.3 Display XMonad logHook in gnome-panel

See xmonad log applet for a third party panel applet to display xmonad's logHook in gnome-panel via dbus. You will also need to install the DBus package from hackage. For more detailed installation and setup instructions, see Installing xmonad log applet.

4.4 Key bindings for switching desktops

4.4.1 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:

4.4.2 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:

4.5 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.

4.5.1 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.

The following mapping in `additionalKeysP` effects this change.

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

4.5.2 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.)

4.5.3 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: