20 January 2008

X²Monad

I’ve been following the XMonad project recently. For those of you who don’t know what XMonad is, I recommend you have a browse through the home page and it’s Wikipedia article. I’ve been planning on playing with XMonad for a while, though my initial plans were to wait till I bought myself a new über box to use in conjunction with my laptop. However, I decided to delay purchasing a new computer (because I couldn’t decide which CPU to get, not due to lack of cash) but couldn’t delay using XMonad any further.

Square that X!

One problem I’ve always had with all the XMonad screenshots I’d seen was that to my mind, dzen and xmobar look rather ugly to me, though this could be due to everyone loving dark colours for their setup. Personally, I much prefer a live graphical image of the various meters, etc. that I have residing on my panels.

Since I heard that KDE 4.0 was going to be released soon (this was around the 9th of January when I started this), I thought I’d do one better than Spencer Janssen’s usage of kicker with XMonad and actually use the full KDE environment with XMonad replacing kwin. After all, if it’s possible to integrate XMonad into Gnome, doing it with KDE should be possible. However, I got sick of waiting for the release date and decided to install version 3.5.8 instead.

Whilst I prefer KDE to Gnome, in the end I couldn’t stand using KDE either. So I decided to go back to using Xfce 4.4, which I’ve been using since one of its betas. I quite like Xfce: for a Desktop Environment, it’s rather responsive and fast. My only complaints is that sometimes it’s too simplistic: so to change an autostart application I have to manually edit the file rather than using the GUI; and some Gnome-oriented apps keep dumbing down. So I decided to combine Xfce with XMonad to form X2Monad (though it turns out gour on #gentoo-haskell has been doing this for a while already without telling anyone).

So why use a DE?

First of all, why not? :p Sure, most people use XMonad in a very minimalistic-environment. However, I’ve become used to having an overall set of applications that integrate nicely, with a consistent manner for configuration (including setting the theme, etc.). Furthermore, I quite like the Xfce panels and the plugins for them (more so than kicker & co.).

Secondly, I’ve found that DEs have better menus and have them by default. Whilst I don’t use the menu often, it is often useful to get an idea of what’s installed and what the name of a particular program you have is (I’ve done this before where I installed something, decided I didn’t like it but couldn’t remember what it was called to uninstall it).

Finally, I want to use a DE with XMonad because I can… that’s the beauty of FLOSS! Especially when you bring in Gentoo’s USE-flags, etc.

Getting the required packages

I use Gentoo, so obviously this section will be distro-centric. However, you can probably find the equivalent package in whatever distribution you use and/or build it from source yourself.

You obviously need Xfce 4.4 and XMonad installed (along with XMonad-Contrib, the user-contributed libraries for XMonad). I’ve been using the darcs (i.e. development) version of the latter two, and so far haven’t had any problems (despite updating at least once a day). To get the ebuilds for these in Gentoo, you first need to access the Haskell Overlay. This is available via layman, but requires darcs to be installed (if you don’t already have ghc – the Glorious Glasgow Haskell Compiler – installed, consider emerging it with the “binary” USE flag, which will install a customised Gentoo ghc binary for you).

So, assuming you’ve got the overlay installed (if not, you can probably just use the non darcs packages in the official tree, but YMMV: in particular, these instruction require at least version 0.5 of XMonad), you’ll need to install the following packages:

xfce4 (optionally with xfce4-extras)

xmonad-darcs

xmonad-contrib

The latter two will probably require adding them to your package.keywords file first before being able to emerge them.

The USE flags for these don’t really matter, though enabling the “doc” USE flag may be helpful (for the two XMonad packages, this installs the haddock docs which are also available on the homepage).

Configuring Xfce

Before being able to use XMonad together with Xfce, we first need to setup Xfce. We’re going to use Xfce’s session management for the most part to get rid of xfwm4 (Xfce’s default window manager) and keep the rest of Xfce happy.

First of all, particularly if you’re already using Xfce, backup your ~/.config directory, as well as anywhere else you might have Xfce settings lying around. This is important in particular to restore your panel settings if you decide to stop using XMonad.

The Settings Manager

Now open up Xfce’s settings manager (you can get this either from the menu, the prompt or else by running xfce-setting-show). Under “Sessions and Startup”, enable choosing of sessions and auto-saving of sessions. Now, to try and ensure we’ve got a backup session going that still works, logout and log back in again, this time choosing to create a new session.

Open up the settings manager again. Under “Desktop”, you can choose to disable desktop management. When Xfce manages your desktop, it does three things:

Setting/Changing the wallpaper

Desktop Icons (stored in your ~/Desktop folder)

Ability to get popup-menus (including the normal program menu and a window listing menu) by clicking on the desktop.

In reality, unless you use some of the more “innovative” of the layouts, you’re not likely to see the desktop at all (at least not after you’ve opened a program on that particular workspace). I’ve still got it enabled at the moment, but that’s only because I’m slowly paring down the junk I’ve saved onto the Desktop.

Edit: There’s a setting in Desktop that enables you to disable icons on the desktop. Now I just use xfdesktop to set my wallpaper.

Under “Preferred Applications”, set the preferred Terminal Emulator (under Utilities) under whatever terminal program you’re going to use. I’m currently using the (XMonad-) recommended rxvt-unicode (AKA urxvt), though Xfce’s Terminal seems to work nicely as well. You can also set your preferred browser and mail client. These settings are used for when Xfce has to open one of these applications (and what the default panel shortcut buttons open up), so these settings may be useless to you if you open everything yourself.

You can safely ignore the “Window Manager” and “Window Manager Tweaks” sections, as we’re not going to be using xfwm4 for much longer. The “Workplaces and Margins” settings are also ignorable, as Xfce seems to quite happily use XMonad’s settings for number of workplaces, etc.

IF you want, you can now disable Xfce’s session manager asking you which session you want to start with. However, I would leave it for now in case you make a mistake and need to get back to your saved backup session. Apart from that, we’re finished with the settings manager.

The Panels

If you want, you can now setup your panels how you want them. Note that you can leave this to later if you wish (as I did). However, as far as I can tell it is not possible to have panels configured on a per-session basis, so any changes you make now are those you’re stuck with (which is why you should have backed up your ~/.config folder). In particular, I decided to remove items such as the Task List. Keep the pager, however… it plays nicely with XMonad to provide you with mini-previews of what applications are on which workspace as well as their layout (however, you can’t as yet switch workspaces via the pager).

Configuring XMonad

For the most part, the instructions on how to setup XMonad to play nicely with Xfce are the same as those for Gnome. These settings let the gaps for the panels be automatically detected and created, and for the pager in the panel to get information on XMonad’s workspaces.

However, I recommend that rather than starting from scratch, that you copy over the the sample xmonad.hs configuration file into ~/.xmonad/xmonad.hs and edit that instead. There is one item on that page that is missing, however: thanks to rob| on #xmonad, the following line in the sample xmonad.hs:

This allows the mod-b behaviour to work properly with the struts setup.

Another change you might want to make is customising the modMask used: there are some Xfce key-combinations (e.g. Alt+F2) that are still handy and mightn’t work properly if XMonad uses the left Alt key as its modMask (not to mention other programs like Emacs that use Alt). I’m using the Windows key at the moment (which is mapped to mod4mask). I’d like to use the right Alt key, but I’ve got to play further with xmodmap to get it working.

Getting rid of xfwm4

Now we need to get rid of xfwm4 and startup XMonad. In a prompt or using xfrun4 (defaults to Alt+F2), enter the following:

killall xfwm4 && xmonad

You might have to hit mod-q to get your customised layout to show up, but otherwise you should now have XMonad working!

Keeping it working

Unfortunately, whilst the session manager can keep xfwm4 killed, XMonad as yet isn’t compatible with session managers. To get XMonad to start each time we log in, we can use Xfce’s autostart feature: open it from the menu of by running xfce4-autostart-editor, and add in an XMonoad entry (the run command merely needs to be “xmonad” without the quotes). That should now be it!

Of course, you can still change other Xfce settings, and edit the plugins in the panel. If you can successfully log in and out, then you can also disable choosing which session you want to use.

The proof is in the screenies

Here are two screenshots of my system: one before I used XMonad (note that this was a while ago, so some settings might have changes slightly):

(In case you’re wondering, the IRC conversation here involved me stating that the new aMSN looked rather nice, whilst everyone else immediately dismissed it for using tcl/tk, though after posting that screenshot they grudgingly half-agreed with me.)

And one after:

(Both of these thumbnails link to the full size images.)

Now, my XMonad configuration isn’t perfect (I’m still playing with layouts, auto-floating stuff, etc.)…. but I’m already quite happy with it. Note especially the pager in the second screenshot: I added in the fifth workspace to XMonad just to see what happened, and after restarting XMonad the extra workspace instantly appeared in the pager! Now that’s cool!

Thanks for this article. I used xfce+xmonad before but I didnt know about that cool ewmh stuff nor that it can be done without editing .xinitrc and starting everything I want from xfce but xfwm4 “by hand”.

Note: You can also use dzen *and* the xfce panel together by just adding the dynamic log hook line to the do block you posted.

Dzen (as its configured here) does a few things xfce panel cant do:
* displays *names* of the workspaces
* shows an icon that informs me about the current layout algorithm
* shows the title of the current window (-> title of webpages, names of open files in editors, etc…)
I know you could substitude this with the tabbar extrensions for fullscreen mode but for tiled layout this is quite useful to me.

I think I dont have to tell much about why I use the xfce panel I think: its easy to configure, provides start-buttons, lots of cool objects, a pager, etc…

Well, I personally prefer icons to text for my panel (besides, I think my xfce panel is prettier than dzen :p ). Also, what’s the point of using xfce without using its panels? I’m not even sure if you can get rid of them all… IIRC, you have to have at least one.

– I prefer Icons too. But dzen can show me an icon that shows the current layout (tabbed, tiled, whatever).
And it can display the workspace name.
(My first 3 workspace names for example are “1:web”, “2:com” and “3:work”)

– I completely agree that the coolest and maybe most import thing in xfce are its panels. All what I’m using of xfce is a panel at the bottom actually. (But I also have a dzen at the top for the things that xfce panels simply cant do)

– Yes xfce’s panels are a lot more pretty. But in combination with xmonad they cant display the workspace name, the current layout or the title of the focused window.
I like these features so dzen can have its few pixels at the top for exactly this 3 tasks. I couldnt live without my xfce bars and all its cool plugins though ;)

I know this conversation is a bit old and no one will help me here, but I know nowhere else to place my doubts and comments.
I followed this “tutorial” to config xmonad on xfce, and I got the same problem Joachim Breitner said, the pager always shows the last window.
I also tried to make session manager restore my windows, like ivanmiljenovic said, but it doesn’t restore all windows and toss all windows to 1st workspace, which makes it not very useful.
I’m liking xmonad more every day, its very productive, although it’s *very* hard to set up (even the basics), it should be tagged “for geeks only”

First of all, this setup is rather old, and you should follow the guide on the wiki (which is based on this). Note that I no longer use Xfce, but rather LXDE (still with XMonad though :p ).

With pagers, I’m not quite sure what problem you’re talking about. If its about Xinerama issues (both workspaces are shown), as far as I know this is a problem with the EWMH standard (the people that wrote it thought one workspace over all screens).

For session management, not all applications support it unfortunately (for example, XMonad itself doesn’t). To get apps open on the right workspaces, uses ManageHooks in XMonad.

I might be biased, but I don’t find XMonad “hard”… then again, having at least basic knowledge on how to program in Haskell does help.

Welcome!

Greetings and salutations be upon thee to my little corner of what we like to charmingly call "the internet". This is where I put forth cunning arguments and repartee on such topics as Haskell, Gentoo, university... just don't ask me if I have a social life :s