Xmonad/Using xmonad in Gnome

From HaskellWiki
< Xmonad
Revision as of 01:03, 21 June 2009 by Joe (talk | contribs) (me too!)

Jump to: navigation, search
Xmonad-logo-small.png

XMonad

Introduction

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

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

Setting up Gnome to use Xmonad

.gnomerc

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. The best way to do this is to edit ~/.gnomerc to contain:

   export WINDOW_MANAGER=xmonad


If Gnome is hanging on startup, try placing the following lines in ~/.xsession instead:

   export WINDOW_MANAGER=xmonad
   exec gnome-session --purge-delay=3000

(If the xmonad binary is not installed to one of the directories in your display manager $PATH environment, you must give the full path, i.e.:

   export WINDOW_MANAGER=${HOME}/bin/xmonad

When using a directory outside your display manager path and customizing the configuration with ~/.xmonad/xmonad.hs, you will also want to modify your restart keybinding in xmonad.hs to use the full path.

To edit the mod-q binding to use /path/to/xmonad, see the keybindings in the sample xmonad.hs included with xmonad documentation, source code for Config.hs, or the template xmonad.hs for your xmonad version from the xmonad config archive.)

gnome-session

Another way to do this is to configure the session. Go to gnome-session-properties (or Desktop -> Preferences -> Sessions) -> Current Session, select Metacity and change style to Trash. Add xmonad to Startup Programs and run:

   $ killall metacity; xmonad &

Close all programs, and in gnome-session-properties, go to Session Options and click on Remember Currently Running Applications.

Ubuntu Intrepid

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

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 &

To add an xmonad launcher you can put the following in /usr/share/applications/xmonad.desktop

   [Desktop Entry]
   Type=Application
   Encoding=UTF-8
   Name=Xmonad
   Exec=xmonad
   NoDisplay=true
   X-GNOME-WMName=Xmonad
   X-GNOME-Autostart-Phase=WindowManager
   X-GNOME-Provides=windowmanager
   X-GNOME-Autostart-Notify=false

This lets gnome know that xmonad is a windowmanager and where to look for it.

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 .gnomerc/gnome-session 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.

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.


No Config.Gnome module

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

import XMonad
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.EwmhDesktops
import qualified XMonad.StackSet as W

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

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. (The myKeys part isn't needed for a minimal install but that was something that gave me problems early on. See the XMonad.Utils.EZConfig documentation for details.)

Depending on your versions of nautilus and xmonad, step 4.1 (Disabling the nautilus desktop, see below) may be mandatory. (Otherwise, the nautilus desktop will be raised into the floating layer where it covers all your other windows.)

Having done this, you should now be able to use Gnome with Xmonad, and most things will work. (An example of something that doesn't is iconifying windows from the panel window list.)

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

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"

Tips on configuring Xmonad

All the 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
              }

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

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

    -- moving workspaces
    , ("M-<Left>",    prevWS )
    , ("M-<Right>",   nextWS )
    , ("M-S-<Left>",  shiftToPrev )
    , ("M-S-<Right>", shiftToNext )
Xmonad-screen-gnome-brownblack5.jpg

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, or the darcs version of XMonad, provides support for this kind of navigation. To use it with 3 lines, for instance, you could use this configuration:

     [ ((keyMask .|. m, keySym), function 3 Finite direction)
     | (keySym, direction) <- zip [xK_Left .. xK_Down] $ enumFrom ToLeft
     , (keyMask, function) <- [(0, planeMove), (shiftMask, planeShift)]
     ]

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 --kill") )

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
    , ((modMask .|. shiftMask, xK_l), spawn "gnome-screensaver-command -l")
    -- Logout
    , ((modMask .|. mod1Mask .|. shiftMask, xK_l), spawn "gnome-session-save --gui --kill")
    -- Sleep
    , ((mod1Mask .|. shiftMask, xK_apostrophe), spawn "gnome-power-cmd.sh suspend")
    -- Reboot
    , ((mod1Mask .|. shiftMask, xK_comma), spawn "gnome-power-cmd.sh reboot")
    -- Deep Sleep
    , ((mod1Mask .|. shiftMask, xK_period), spawn "gnome-power-cmd.sh hibernate")
    -- Death
    , ((mod1Mask .|. shiftMask, xK_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)