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

From HaskellWiki
Jump to navigation Jump to search
Line 1: Line 1:
   
== Introduction ==
+
==Introduction==
Xmonad makes a great drop-in replacement for Gnome's default window manager (metacity) giving the user a slick tiling window manager. This guide will help you get your version of gnome up and running with xmonad 0.5.
 
   
  +
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.
=== Assumptions ===
 
For this tutorial we assume:
 
*you're using xmonad 0.5 or newer.
 
*you have installed the xmonad 0.5 contrib files.
 
*you have a working xmonad configuration and are already familiar with the basics of configuring and using xmonad.
 
*you're using GNOME 2.18 or newer. If you're using an earlier version beware that configuration dialogs and the names of certain settings could be quite different from what is illustrated here.
 
   
  +
This is an update to the previous page on [[Xmonad/Using xmonad in Gnome/0.5]],
== The configuration ==
 
  +
which in turn was an update to the
All configuration is done in the ~/.xmonad/xmonad.hs file.
 
  +
[http://xmonad.org/gnome.html original page on the subject].
   
  +
==Setting up Gnome to use Xmonad==
=== From scratch ===
 
To make space for the gnome-panel/taskbar at the top, we setup the [http://hackage.haskell.org/packages/archive/xmonad-contrib/0.5/doc/html/XMonad-Hooks-ManageDocks.html ManageDocks] class:
 
   
  +
The easiest way is to let Gnome start Xmonad itself by modifying ''~/.gnomerc'' to contain
import XMonad.Hooks.ManageDocks
 
main = xmonad defaultConfig
 
{ manageHook = manageDocks
 
, layoutHook = avoidStruts (tall ||| mirror tall ||| Full)
 
}
 
where tall = Tall 1 (3/100) (1/2)
 
   
  +
export WINDOW_MANAGER=/usr/bin/xmonad
For gnome to know about the windows and workspaces that xmonad creates, a class called [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-EwmhDesktops.html EwmhDesktop] exists. The configuration (from the [http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-EwmhDesktops.html EwmhDesktop] page)looks like this:
 
import XMonad
 
import XMonad.Hooks.EwmhDesktops
 
   
  +
==Tweak Gnome to work better with Xmonad==
myLogHook :: X ()
 
myLogHook = do ewmhDesktopsLogHook
 
return ()
 
   
  +
These are a few steps that greatly improves the experience of running Xmonad under Gnome. Note that on some systems the binary <tt>gconftool</tt> is called <tt>gconftool-2</tt>.
main = xmonad defaultConfig { logHook = myLogHook }
 
   
  +
===Disable the Nautilus desktop===
Putting it all together, a simple xmonad.hs configuraton file that works with Gnome might be:
 
import XMonad
 
import XMonad.Hooks.ManageDocks
 
import XMonad.Hooks.EwmhDesktops
 
 
myLogHook :: X ()
 
myLogHook = do ewmhDesktopsLogHook
 
return ()
 
   
  +
From the command line execute:
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)
 
   
  +
gconftool --type boolean --set /apps/nautilus/preferences/show_desktop false
You also need to tell gnome that you would like xmonad to be your default window manager. If gdm is your login manager, it looks in the ~/.gnomerc file for the WINDOW_MANGER variable. Let's set that. My ~/.gnomerc file looks like this:
 
   
  +
===Changing desktop background===
#!/bin/bash
 
export WINDOW_MANAGER="/usr/bin/xmonad"
 
   
  +
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:
=== From xmonad < 0.5 ===
 
To make space for the gnome-panel on the top of the screen, xmonad had to be manually configured to make space. Prior to xmonad 0.5, this was done using the defaultGaps config option. This can now safely be taken out in favor of ManageDocks. See above.
 
   
  +
gconftool --type string --set /desktop/gnome/background/picture_filename "/path/to/your/image.png"
== Issues ==
 
* Shortcuts - Be weary of the keyboard shortcuts that might conflict. For example, by default xmonad uses alt as the mod key. However, the shortcut alt-space (cycle layout) conflicts with gnome's default window management shortcut.
 
* Nautilus - The author has had problems when Nautilus is running. To disable it do the following:
 
*#Click System -> Preferences -> Sessions
 
*#Select the "Current Session" tab.
 
*#Find nautilus and select it. Set style: "Trash" and press remove.
 
*#On the "Session Options" tab. Press "Remember currently running applications"
 
   
  +
===Fixing the pointer===
== Old gnome tutorial from xmonad.org ==
 
   
  +
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
'''WARNING''': This is probably out of date. It's only here so that the static page can be deleted from xmonad.org. Someone who is knowledgeable about such things should go through and delete/incorporate into the above as appropriate.
 
   
  +
/usr/bin/xsetroot -cursor_name left_ptr
===Introduction===
 
   
  +
==Tips on configuring Xmonad==
As of xmonad 0.4 the procedure for replacing Metacity with xmonad under a normal GNOME/GDM session has been simplified greatly. Here you'll configure your xmonad process to be managed by gnome-session and in turn by gdm, such that logging into a GNOME session from GDM automatically launches xmonad, and logging out of GNOME in the usual manner exits both GNOME and xmonad, returning you to the GDM login screen.
 
   
  +
Allthe configuration is done in <tt>~/.xmonad/xmonad.hs</tt>.
For this tutorial we assume:
 
   
  +
===Change the mod key===
* you're using xmonad 0.4 or newer.
 
* you have a working xmonad configuration and are already familiar with the basics of configuring and using xmonad.
 
* you're using GNOME 2.18 or newer. If you're using an earlier version beware that configuration dialogs and the names of certain settings could be quite different from what is illustrated here.
 
   
  +
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'':
===Xmonad configuration===
 
   
  +
<haskell>
If you use gnome-panel or other panel/dock-style applications you'll want to create a gap space for them. Open xmonad's Config.hs in your editor and modify defaultGaps with the same height values (in pixels) your panels/docks use. For example, a single top-oriented gnome-panel instance 24 pixels in height would need:
 
  +
main = xmonad $ defaultConfig {
  +
modMask = mod4Mask
  +
}
  +
</haskell>
   
  +
===Make space for the panel===
defaultGaps = [(24,0,0,0)]
 
   
  +
There are two options for creating space for the Gnome panel; the builtin way using ''gaps'' and [http://hackage.haskell.org/packages/archive/xmonad-contrib/0.5/doc/html/XMonad-Hooks-ManageDocks.html ManageDocks].
Once that's set recompile and reinstall xmonad. Press mod-q to make the settings take effect in a running xmonad instance.
 
   
  +
For the former one can use the following:
[[Image:screen-ohmega-tab-gnome-twopane-thumb.jpg|center]]
 
   
  +
<haskell>
===Preparing your GNOME session===
 
  +
main = xmonad $ defaultConfig {
  +
defaultGaps = [(24,24,0,0)]
  +
}
  +
</haskell>
   
  +
For the latter:
The two main approaches to changing GNOME's window manager are explained below. If you have a ~/.gnome2/session file then you should use option A, otherwise option B.
 
   
  +
<haskell>
# Launch GNOME as usual and back up ~/.gnome2/session in case you need to revert back to your current session configuration. Next, launch System --> Preferences --> Sessions (or at the command line, gnome-session-properties) and perform the following:
 
  +
import XMonad.Hooks.ManageDocks
## In the Startup Programs tab click New (or Add in GNOME 2.20) and add a launcher called "xmonad" which has the command "/usr/bin/xmonad", then click OK. Make sure the new entry's box is checked so that it will be started automatically.
 
  +
main = xmonad defaultConfig {
## In the Current Session tab select the metacity item (or whichever window manager your current GNOME session is using) from the list and set its Style to Trash. Do the same for any items which have no icon in the Style column.
 
  +
manageHook = manageDocks
## Click Apply.
 
  +
, layoutHook = avoidStruts (tall ||| mirror tall ||| Full)
## In the Session Options tab click Save the current session (or Remember currently running applications in GNOME 2.20) and then Close. This will write your modified session to ~/.gnome2/session.
 
  +
}
# In the absence of a custom ~/.gnome2/session file GDM will fall back on the default GNOME session defined in /usr/share/gnome/default.session (this path may vary according to platform). The default session launches gnome-wm which in turn launches the window manager defined by the environment variable WINDOW_MANAGER. If that variable is undefined gnome-wm defaults to Metacity. You can define it on a per-user basis by putting the following in ~/.gnomerc, ~/.xsession or ~/.xinitrc:
 
  +
where tall = Tall 1 (3/100) (1/2)
  +
</haskell>
   
  +
===Extended Window Manager Hints===
export WINDOW_MANAGER="/usr/bin/xmonad"
 
   
  +
[http://xmonad.org/xmonad-docs/xmonad-contrib/XMonad-Hooks-EwmhDesktops.html EwmhDesktop] makes it possible to let Gnome know about Xmonad windows and workspaces:
You can also define it system-wide. On Gentoo for example, put the following in /etc/env.d/99local then run env-update:
 
   
  +
<haskell>
WINDOW_MANAGER="/usr/bin/xmonad"
 
  +
import XMonad.Hooks.EwmhDesktops
  +
main = xmonad $ defaultConfig {
  +
logHook = ewmhDesktopsLogHook
  +
}
  +
</haskell>
   
  +
===A complete example configuration===
Now that your session is ready, log out of GNOME.
 
   
  +
Here is a very simple configuration suitable for a desktop with two panels, one at the top and one at the bottom:
===Starting GNOME with xmonad===
 
   
  +
<haskell>
At the GDM login screen select GNOME for a new session then log indon't just accept the default Last session option for this initial login because your previous session might be used instead of the newly-modified session. After logging in you should see the GNOME splash screen briefly, thenif all went wellyou'll be running GNOME with xmonad instead of Metacity.
 
  +
import XMonad
  +
import XMonad.Hooks.EwmhDesktops
   
  +
-- left alt is used in GTK so use left logo instead
[[Image:gnome-thumb.png|center]]
 
  +
myModMask = mod4Mask
   
  +
-- let Gnome know about Xmonad actions
Xmonad should have your GNOME panel(s) positioned correctly by default. If not, try toggling the offending panel's Orientation property a couple of times. One reported panel fix involves adding a new manageHook rule to Config.hs; using a single top-oriented panel as an example, first add:
 
  +
myLogHook = ewmhDesktopsLogHook
   
  +
main = xmonad $ defaultConfig {
manageHook w "Top Expanded Edge Panel" "gnome-panel" _ = reveal w >> return (W.delete w)
 
  +
defaultGaps = [(24,24,0,0)],
 
  +
logHook = myLogHook,
and then remove "gnome-panel", from the following definition:
 
  +
modMask = myModMask
 
  +
}
manageHook w _ n _ | n `elem` ignore = reveal w >> return (W.delete w)
 
  +
</haskell>
where ignore = ["gnome-panel", "desktop_window", "kicker", "kdesktop"]
 
 
If you experience applications/applets hanging during startup, you can try this: Pull up the preferences for your GNOME session again, and in the Current Session tab, find the xmonad entry and change its Order from 50 to 99, click Apply, then in the Session Options tab click Save the current session (or Remember currently running applications in GNOME 2.20) and finally Close. This helps ensure that xmonad will be started last in subsequent sessions.
 
 
===Problematic applications===
 
 
* Dock mode applications Applications displaying in dock mode (GKrellM, Conky, etc.) may not behave as expected. If possible you might try setting the application to desktop window or normal window mode. Xmonad's manageHook setting provides a flexible method to make xmonad ignore the application altogether, allowing the application to sit unmanaged in a gap area (see Config.hs for more on using manageHook). Currently under development in xmonad darcs is an extension ManageDocks which aims to further improve dock management. See the comments in its source file for more information.
 
* Window List, Window Selector, and Workspace Switcher panel applets Xmonad-managed windows and workspaces don't currently register in GNOME, so these panel applets present empty lists. Fortunately there's another extension currently under development in xmonad darcs called EwmhDesktops designed to address such deficiencies.
 
 
===Tips===
 
 
* Launch gnome-terminal with mod-Shift-Enter If gnome-terminal is your preferred xterm you might want to change the key binding value for keys in Config.hs from:
 
 
[ ((modMask .|. shiftMask, xK_Return), spawn "xterm") -- @@ Launch an xterm
 
 
 
to the following:
 
 
[ ((modMask .|. shiftMask, xK_Return), spawn "gnome-terminal") -- @@ Launch an xterm
 
 
* Disable splash screen and Nautilus desktop Some find the Nautilus-managed desktop unhelpful when used in combination with xmonad. To disable it (while continuing to use Nautilus to manage files), you can use the command:
 
 
gconftool --type boolean --set /apps/nautilus/preferences/show_desktop false
 
 
 
The splash screen is another potential annoyance. It may also be disabled:
 
 
gconftool --type boolean --set /apps/gnome-session/options/show_splash_screen false
 
 
 
* Workspace background image The usual methods of setting the background image for the Nautilus-drawn desktop also determine the background used by xmonad's workspaces (which of course are drawn independently of Nautilus's desktop). 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"
 
 
 
NB: On some platforms the gconftool binary is named gconftool-2 instead.
 
 
[[Category:XMonad]]
 

Revision as of 23:27, 25 March 2008

Introduction

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

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
    }

A complete example configuration

Here is a very simple configuration suitable for a desktop with two panels, one at the top and one at the bottom:

import XMonad
import XMonad.Hooks.EwmhDesktops

-- left alt is used in GTK so use left logo instead
myModMask = mod4Mask

-- let Gnome know about Xmonad actions
myLogHook = ewmhDesktopsLogHook

main = xmonad $ defaultConfig {
        defaultGaps = [(24,24,0,0)],
        logHook = myLogHook,
        modMask = myModMask
    }