colinrmitchell.com

Blog

Setting up Xmonad on a desktop

Posted Saturday, June 18th 2011 in FreeBSD, Linux - Permalink

Xmonad is a great tiling window manager that I have been goofing around with for the last week. I really enjoy it on my laptop, as the less I have to use the mouse, the better. It also really improves the efficiency of my desktop. Here, I will give some brief notes on setting it up.

Ubuntu and Friends

I installed Xmonad on two different computers running Ubuntu/Xubuntu. For both, installation is easy,

# sudo apt-get install xmonad

Once installed, you will see an Xmonad session on your login screen. If you don’t use a login screen, I guess you won’t see it.

Gnome

For Ubuntu/Gnome, create the directory ~/.xmonad and enter into the file xmonad.hs there

import XMonad
import XMonad.Config.Gnome
main = xmonad gnomeConfig

This will set up Xmonad to be used within Gnome. Next, enter the following into a command line

# gconftool-2 -s /desktop/gnome/session/required_components/windowmanager xmonad --type string

This will tell Gnome to use Xmonad as its window manager, instead of Metacity. Log out and log back in, and you should be using your new window manager!

Xfce

For Xubuntu/Xfce4, things are a little different. Again, create xmonad.hs as above and enter into it

import XMonad
import XMonad.Config.Desktop
main = xmonad desktopConfig

Xfce4 doesn’t have an option to choose your window manager, so we have to do this with a bit of trickery. First, we want to set up Xfce4 to auto-start Xmonad. In the GUI, go to Settings->Session and Startup->Application Autostart. Now, add Xmonad to start on login. Next, hit the Session tab, and kill Xfwm4. Log out and back in, and you should be using Xmonad.

FreeBSD

For FreeBSD, install the hs-xmonad and hs-xmonad-contrib ports.

Xfce

Set it up like Xfce in the Linux section above. The default terminal is xterm, so to change it to the default Xfce4 terminal, terminal, add the following to ~/.xmonad/xmonad.hs

import XMonad
import XMonad.Config.Desktop

main = xmonad myConfig

myConfig = desktopConfig {
    terminal = "terminal"
    }
Plain X11

If you are using X11 on FreeBSD with no desktop environment, such as Gnome or Xfce, you can still use Xmonad. First, we need to make sure Xmonad is started when we startx. Add the following to your ~/.xinitrc:

xsetroot -cursor_name left_ptr
exec xmonad

You can use the following xmonad.hs. This code uses the port lxterminal instead of xterm as the terminal application.

import XMonad
import XMonad.Config.Desktop
import qualified Data.Map as M
import XMonad.Prompt
import XMonad.Prompt.Shell
import XMonad.Prompt.XMonad
import XMonad.Actions.PhysicalScreens

import XMonad.Layout.Accordion
import XMonad.Layout.Grid
import XMonad.Layout.Spiral

myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList
                [((modm .|. mask, key), f sc)
                | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
                , (f, mask) <- [(viewScreen, 0), (sendToScreen, shiftMask)]]

myLayout =
        Accordion |||
        GridRatio (4/3) |||
        spiral (4/5)

main = xmonad desktopConfig {
                terminal = "lxterminal",
                keys = myKeys <+> keys desktopConfig,
                layoutHook = (layoutHook desktopConfig) ||| myLayout
Troubleshooting

If you are using multiple monitors, setting Xmonad up can be a little more tricky. Xmonad depends on libXinerama to determine where the physical screens are within the large virtual desktop created by Xinerama. Without this, Xmonad will consider the entire virtual desktop as a single physical desktop, and you won’t be able to split the workspaces up between physical monitors. So we must ensure that Xmonad is built with Xinerama support.

To check,

# ldd `which xmonad`
/usr/local/bin/xmonad:
	librt.so.1 => /usr/lib/librt.so.1 (0x28254000)
	libutil.so.8 => /lib/libutil.so.8 (0x28259000)
	libXinerama.so.1 => /usr/local/lib/libXinerama.so.1 (0x28268000)
	libXext.so.6 => /usr/local/lib/libXext.so.6 (0x2826b000)
	libX11.so.6 => /usr/local/lib/libX11.so.6 (0x2827a000)
	libiconv.so.3 => /usr/local/lib/libiconv.so.3 (0x28394000)
	libgmp.so.10 => /usr/local/lib/libgmp.so.10 (0x2848a000)
	libm.so.5 => /lib/libm.so.5 (0x284e8000)
	libc.so.7 => /lib/libc.so.7 (0x28502000)
	libxcb.so.2 => /usr/local/lib/libxcb.so.2 (0x2861d000)
	libXau.so.6 => /usr/local/lib/libXau.so.6 (0x28635000)
	libXdmcp.so.6 => /usr/local/lib/libXdmcp.so.6 (0x28638000)
	libpthread-stubs.so.0 => /usr/local/lib/libpthread-stubs.so.0 (0x2863d000)
	librpcsvc.so.5 => /usr/lib/librpcsvc.so.5 (0x2863f000)

You should see an entry for libXinerama.so somewhere in there. If you do not, that means that the X11 Haskell bindings were not built with Xinerama support, and so Xmonad was not as well. The first thing to do is to rebuild the port hs-X11 with Xinerama support. Run make config to ensure that Xinerama support is enabled for rebuilding the port. After the port is built, you need to rebuild hs-xmonad, hs-xmonad-contrib, and hs-X11-xft. Run the above diagnostic again and it should confirm that Xmonad was built with Xinerama support..


List Posts Newest Posts Page 1Next Page