Xmonad/Using xmonad in Gnome

From HaskellWiki
< Xmonad
Revision as of 11:14, 2 April 2008 by Datagrok (talk | contribs) (link to probably working instructions)
Jump to navigation Jump to 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.6.

This is an update to the previous page on Xmonad/Using xmonad in Gnome/0.5, which in turn was an update to the original page on the subject.

Setting up Gnome to use Xmonad

The easiest way is to let Gnome start Xmonad itself by setting the environment variable WINDOW_MANAGER to point to the xmonad executable before the Gnome session manager starts. On most systems, this means modifying one of ~/.xprofile or ~/.gnomerc to contain:

   export WINDOW_MANAGER=xmonad

If the binary is not in one of the directories in your $PATH, you must give the full path, i.e.:

   export WINDOW_MANAGER=${HOME}/bin/xmonad

Configure Xmonad to interoperate with Gnome

Put this in ~/.xmonad/xmonad.hs:

import XMonad
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.EwmhDesktops

main = xmonad defaultConfig
              { manageHook = manageDocks <+> manageHook defaultConfig
              , logHook    = ewmhDesktopsLogHook
              , layoutHook = avoidStruts $ layoutHook defaultConfig
              , modMask    = mod4Mask

This should set up Xmonad to make space for Gnome's panel and status bar automatically. Note that this requires xmonad-contrib to be installed.

Having done this, you should now be able to use Gnome with Xmonad, and most things will work. At the time of writing, there are a couple of things that don't fully work: clicking on the taskbar to select a window doesn't focus the window, and clicking on the panel to switch desktops doesn't. Of course you can use the standard Xmonad keys to perform these actions instead.

Explanations of the various options are given below, along with some other things you might want to tweak.

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

From the command line execute:

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

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"

Fixing the pointer

If you're not using the Gnome Display Manager, after switching to Xmonad you might notice that the default pointer isn't the one you chose in your beautiful Gnome theme. The way to address this is to run xsetroot during session startup. Open the session configuration dialogue (System -> Preferences -> Sessions). Add a new startup program, choose any name and comment you want but make the command

   /usr/bin/xsetroot -cursor_name left_ptr

Tips on configuring Xmonad

Allthe configuration is done in ~/.xmonad/xmonad.hs.

Change the mod key

The default mod key is alt, which conflicts with Gnome keybindings. In order to use be able to use the keyboard to e.g. getting rid of dialogues we rebind it to the left logo key:

main = xmonad defaultConfig
              { modMask = mod4Mask

Make space for the panel

ManageDocks makes it possible for Xmonad to work with panels in the way they expect, automatically leaving the appropriate amount of room for them at the edges of the screen. ManageDocks has been enabled in the example configuration above. By itself, configuration looks like this:

import XMonad.Hooks.ManageDocks
main = xmonad defaultConfig
              { manageHook = manageDocks <+> manageHook defaultConfig
              , layoutHook = avoidStruts  $  layoutHook defaultConfig

Prior to version 0.7, Xmonad alternatively supported a gaps option, configured like this:

main = xmonad defaultConfig
              { defaultGaps = [(24,24,0,0)]

Extended Window Manager Hints

EwmhDesktops makes it possible to let Gnome know about Xmonad windows and workspaces. EwmhDesktops has been enabled in the example configuration above. By itself, configuration looks like this:

import XMonad.Hooks.EwmhDesktops
main = xmonad defaultConfig
              { logHook = ewmhDesktopsLogHook

Key bindings for switching desktops

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, and I use these keybindings:

    -- moving workspaces
    , ((modMask,               xK_Left  ), prevWS )
    , ((modMask,               xK_Right ), nextWS )
    , ((modMask .|. shiftMask, xK_Left  ), shiftToPrev )
    , ((modMask .|. shiftMask, xK_Right ), shiftToNext )

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's two different remedies to this, you may enjoy either or both:

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

   , ((modMask .|. shiftMask, xK_q ), spawn "gnome-session-save --gui --kill") )

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)