Personal tools

Xmonad/Using xmonad in Gnome/0.5

From HaskellWiki

< Xmonad | Using xmonad in Gnome
Revision as of 23:26, 25 March 2008 by DonStewart (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This is the old version of the gnome document, describing gnome support under xmonad 0.5

Contents

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

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

2 The configuration

All configuration is done in the ~/.xmonad/xmonad.hs file.

2.1 From scratch

To make space for the gnome-panel/taskbar at the top, we setup the ManageDocks class:

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

For gnome to know about the windows and workspaces that xmonad creates, a class called EwmhDesktop exists. The configuration (from the EwmhDesktop page)looks like this:

import XMonad
import XMonad.Hooks.EwmhDesktops
myLogHook :: X ()
myLogHook = do ewmhDesktopsLogHook
               return ()
main = xmonad defaultConfig { logHook = myLogHook }

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

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:

#!/bin/bash
export WINDOW_MANAGER="/usr/bin/xmonad"

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

3 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:
    1. Click System -> Preferences -> Sessions
    2. Select the "Current Session" tab.
    3. Find nautilus and select it. Set style: "Trash" and press remove.
    4. On the "Session Options" tab. Press "Remember currently running applications"

4 Old gnome tutorial from xmonad.org

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.

4.1 Introduction

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.

For this tutorial we assume:

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

4.2 Xmonad configuration

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:

   defaultGaps = [(24,0,0,0)]

Once that's set recompile and reinstall xmonad. Press mod-q to make the settings take effect in a running xmonad instance.

Screen-ohmega-tab-gnome-twopane-thumb.jpg

4.3 Preparing your GNOME session

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.

  1. 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:
    1. 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.
    2. 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.
    3. Click Apply.
    4. 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.
  2. 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:
     export WINDOW_MANAGER="/usr/bin/xmonad"
     You can also define it system-wide. On Gentoo for example, put the following in /etc/env.d/99local then run env-update:
     WINDOW_MANAGER="/usr/bin/xmonad"

Now that your session is ready, log out of GNOME.

4.4 Starting GNOME with xmonad

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.

Gnome-thumb.png

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:

   manageHook w "Top Expanded Edge Panel" "gnome-panel" _ = reveal w >> return (W.delete w)

and then remove "gnome-panel", from the following definition:

   manageHook w _ n _ | n `elem` ignore = reveal w >> return (W.delete w)
    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.

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

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