Difference between revisions of "Xmonad/Using xmonad in Gnome"

From HaskellWiki
Jump to navigation Jump to search
Line 14: Line 14:
   
 
export WINDOW_MANAGER=/usr/bin/xmonad
 
export WINDOW_MANAGER=/usr/bin/xmonad
  +
  +
==Configure Xmonad to interoperate with Gnome==
  +
  +
Put this in ''~/.xmonad/xmonad.hs'':
  +
  +
<haskell>
 
import XMonad
 
import XMonad.Hooks.ManageDocks
  +
import XMonad.Hooks.EwmhDesktops
  +
  +
myLogHook :: X ()
 
myLogHook = do ewmhDesktopsLogHook
  +
return ()
  +
 
main = xmonad $ defaultConfig
  +
{ borderWidth = 2
  +
, manageHook = manageDocks
  +
, workspaces = map show [1 .. 5 :: Int]
 
, logHook = myLogHook
  +
, layoutHook = avoidStruts (tall ||| Mirror tall ||| Full)
  +
}
  +
where tall = Tall 1 (3/100) (1/2)
  +
</haskell>
  +
  +
This should set up Xmonad to make space for Gnome's panel and status bar automatically.
  +
  +
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.
   
 
==Tweak Gnome to work better with Xmonad==
 
==Tweak Gnome to work better with Xmonad==
Line 85: Line 114:
 
</haskell>
 
</haskell>
   
  +
===Key bindings for switching desktops===
===A complete example configuration===
 
   
  +
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 [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Actions-CycleWS.html XMonad.Actions.CycleWS] has some useful actions for cycling workspaces, and I use these keybindings:
Here is a very simple configuration suitable for a desktop with two panels, one at the top and one at the bottom:
 
   
 
<haskell>
 
<haskell>
  +
-- moving workspaces
import XMonad
 
  +
, ((modMask, xK_Left ), prevWS )
import XMonad.Hooks.EwmhDesktops
 
  +
, ((modMask, xK_Right ), nextWS )
 
  +
, ((modMask .|. shiftMask, xK_Left ), shiftToPrev )
-- left alt is used in GTK so use left logo instead
 
  +
, ((modMask .|. shiftMask, xK_Right ), shiftToNext )
myModMask = mod4Mask
 
 
-- let Gnome know about Xmonad actions
 
myLogHook = ewmhDesktopsLogHook
 
 
main = xmonad $ defaultConfig {
 
defaultGaps = [(24,24,0,0)],
 
logHook = myLogHook,
 
modMask = myModMask
 
}
 
 
</haskell>
 
</haskell>

Revision as of 16:35, 26 March 2008

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.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 modifying ~/.gnomerc to contain

   export WINDOW_MANAGER=/usr/bin/xmonad

Configure Xmonad to interoperate with Gnome

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

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

myLogHook :: X ()
myLogHook = do ewmhDesktopsLogHook
               return ()

main = xmonad $ defaultConfig
                { borderWidth      = 2
                , manageHook       = manageDocks
                , workspaces       = map show [1 .. 5 :: Int]
                , logHook          = myLogHook
                , layoutHook       = avoidStruts (tall ||| Mirror tall ||| Full)
                }
              where tall = Tall 1 (3/100) (1/2)

This should set up Xmonad to make space for Gnome's panel and status bar automatically.

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.

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

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

There are two options for creating space for the Gnome panel; the builtin way using gaps and ManageDocks.

For the former one can use the following:

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

For the latter:

import XMonad.Hooks.ManageDocks
main = xmonad defaultConfig {
        manageHook = manageDocks
        , layoutHook = avoidStruts (tall ||| mirror tall ||| Full)
    }
    where tall = Tall 1 (3/100) (1/2)

Extended Window Manager Hints

EwmhDesktop makes it possible to let Gnome know about Xmonad windows and workspaces:

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 )