It's now time to ditch Xfce's default Window Manager xfwm4 and replace it with something better (i.e. XMonad). To do so, it's probably easiest to run xfrun4 with Xfce's default key combination Alt-F2 and enter the following:

+

You can now logout and login back to see if everything works. You can also just run <code>xmonad --replace</code> to change your window manager without ending your current session.

1 Introduction

This is an updated and hopefully less confusing version of my original blog post located here: X2Monad

Why use Xfce with XMonad?

Whilst XMonad is a truly excellent Window Manager, alone it doesn't offer the full convenience of an entire Desktop Environment, such as the provided menus, all-in-one configuration settings, consistent dialogs, etc. Out of the three main DEs available in Unix-like Operating Systems - Gnome, KDE and Xfce - the latter is often touted as the most "nimble" of the lot. In my own opinion, it is simpler to use than KDE but with more configuration options (and a saner environment) than Gnome.

2 Configuring XMonad to work with Xfce

This guide assumes that you're using at least version 4.4 of Xfce, and have both XMonad and XMonad-Contrib 0.7 installed. First we need to configure Xfce to play nicely, before adding in XMonad.

2.1 Xfce Settings

We're going to utilise Xfce's Session Manager to make sure that xfwm4 (Xfce's default WM) is no longer started. Preferably, it'd be nice if we could have XMonad started this way as well (or even set in a configuration option like with Gnome or KDE), but the former isn't possible until XMonad supports the required Session Management Protocol and the latter isn't possible in Xfce at all.

2.1.1 Backing up your settings

If you're already using Xfce, you may wish to first backup your ~/.config directory. Whilst Xfce isn't the only application/library/etc. to utilise the ~/.config directory to store it's settings, it does so in a few different sub-directories (i.e. in some cases specific applications have their own settings directory), it's easier to backup the whole thing.

Note that as far as I know, it isn't possible to have for the same user both a standard Xfce login and an XMonad Xfce login. Whilst you can have different sessions to determine whether you use XMonad or not, there are some settings - such as the panel layout - that aren't saved on a per-session basis.

2.1.2 Start a new session

For backup purposes in case something goes wrong with your XMonad settings, it is recommended to create a new Xfce session. To do so, open the "Sessions and Startup" option dialog either from the "Settings" section of the Xfce menu, or in Xfce's Settings Manager (xfce-setting-show). Enable the the session chooser and automatic saving of sessions, then logout and log back in again. When the session chooser appears, choose to create a new session.

A word of warning: I found that the session chooser kept crashing Xfce on a freshly installed Xfce-4.4.2. If this happens to you, delete the ~/.config/xfce-session directory.

2.1.3 Setting up Xfce

Open up the Xfce settings manager. There, you can customise Xfce to your hearts content. Note that the following settings dialogs won't be applicable once we start XMonad:

Window Manager

Window Manager Tweaks

Workspaces and Margins

The last option isn't required, as Xfce will happily use XMonad's workspaces.

These options are recommended:

Under "Desktop", let Xfce manage the desktop, but under Behaviour set the Desktop Icons to "None". This way, Xfce will control your wallpaper, etc., allowing you to have random lists, different wallpapers for different screens for multi-head setups, etc.

The Keyboard settings can be used to set keyboard shortcuts for those multimedia keys (e.g. XF86AudioMute) found on many keyboards, since these types of keys are currently difficult to create shortcuts for in XMonad. Simply setup the various keyevents to these keybindinds for use with xmodmap in ~/.Xmodmap and Xfce will read these on start.

Mouse: if you don't have or want to use a mouse, there's a limited type of mouse emulation available where you can use the Numpad arrow keys to move the cursor.

For "Preferred Applications", set whichever terminal emulator you plan to use. I find that Xfce's own Terminal application to work quite nicely with XMonad and to resize rather well.

If you so wish, you can now disable the session chooser, though I suggest you leave it enabled until you've successfully managed to login to your Xfce/XMonad environment several times.

2.1.4 Xfce's Panels

If you so wish you can now customize the panels and the plugins on them. This can be safely left to later, however. With XMonad, I typically only have one panel rather than the default two. In terms of panel plugins, I've removed the Task List, but kept the pager: with the EWMH settings in XMonad, Xfce's pager acts as a mini-preview of your various layouts!

2.1.5 Ensure Xmonad gets started

Run Xfce's Autostarted Applications manager (either under the Settings section in the Xfce menu (Menu -> Settings -> Setting Manager -> Sessin and Startup -> Application Autostart tab) or run xfce4-autostart-editor). Add an entry for xmonad and set the command to xmonad --replace (assuming xmonad is in your path). Ensure that the new autostarted application entry you just created is ticked.

2.2 XMonad Hacking

It's now time to customise XMonad. You have a wide variety of Layouts, Hooks, etc. to experiment with. Here are some basic changes that you should make:

Replace the old gaps setup with ManageDocks (especially since Gaps are deprecated in the current darcs version of XMonad and won't be present from 0.8 onwards). This also involves changing the keybinding to hide/show panels.

Use the EWMH hooks so that Xfce can obtain Workspace information from XMonad and vice versa. This lets the Pager plugin to the panel act as a mini workspace-previewer, and let you choose which workspace to view by clicking on the pager. Note that by using this, the pager will also automatically add/remove workspaces based upon how many workspaces XMonad has.

Use mod4 (aka the "Windows" key) as the modifier key. Many applications - including Xfce - use the Alt key for keybindings themselve (e.g. Xfce uses Alt-F2 to show its run dialog).

With keybindings, xfce4-session-logout to exit for the Mod-Shift-q keybinding, rather than just exiting XMonad (which will leave Xfce still running).

Use Xfce's Terminal as the terminal program.

Here is a minimal ~/.xmonad/xmonad.hs that demonstrates how to do this. Note that it is expected that you copy and edit the sample configuration file to get the remaining keybindings present, or else use something like the EZConfig extension in the Contrib library to selectively add/edit/remove keybindings from the default list. As it stands, this configuration file isn't sufficient, as it doesn't list all the keybindings and in fact won't compile due to the "..." present in the keybinding list.

2.3 Using XMonad.Config.Xfce

Use the following in your ~/.xmonad/xmonad.hs to implement all the suggestions made above. This is a compilable configuration giving you all the basics.

import XMonad
import XMonad.Config.Xfce
main = xmonad xfceConfig

You may wish to run ghci or something on your ~/.xmonad/xmonad.hs configuration file to make sure it's correct before moving on to the next section.

With the above configuration, the Meta key still acts as the modMask. I would suggest remapping the modMask to the Super key by the following changes to the above configuration:

main = xmonad xfceConfig
{ modMask = mod4Mask }

3 Get XMonad Going!

You can now logout and login back to see if everything works. You can also just run xmonad --replace to change your window manager without ending your current session.

4 That's all folks!

Congratulations, you have now successfully configured XMonad and Xfce so that XMonad acts as Xfce's Window Manager! Sample screenshots to come.

5 Specific version notes

5.1 4.6.0

The procedure above did not work for me, I had to manually edit the session cache (in ~/.cache/sessions) to remove the entry for xfwm4. This meant removing all the lines with Client0, decrementing the client number for all other clients, and decrementing Count. This needs to be done after logging out so that it isn't clobbered by saving the session on logout.

5.2 4.6.1

I had to delete ~/.cache/sessions directory(while already logged out from any existing Xfce session) for the above solution to work.

The command killall xfwm4 && xmonad didn't manage to kill xfwm4, it was possible to shut it down in "Settings->Session and Startup->Session" (or through xfce4-session-settings).

5.3 4.10

Overall, the whole article works, except the part about killing xfwm4, which is solved almost exactly the same as in 4.6.1. Though, you have to be perseverant. I have done the same procedure like 4 times and every time xfwm4 revives at least once. It's even possible that even when you see it killed and does not appear at the session settings dialog, after restarting, it will appear again. After a couple of times (aka: rinse and repeat) it will be gone for good.

6 Known Issues

Swapping of two windows does not reflect in the xfce panel. Also the order of the windows in the xfce panel does not match with the order of the windows in xmonad's stack.