Huntly Cameron - Web Stuffs

How-to: Set up XMonad & XMobar on Ubuntu

Update: I’ve put my config files on github as pasting them into this blog didn’t keep everything (due to a plugin i use).

What is XMonad?

XMonad is a tiling window manager much like wmii or awesome e.t.c. However, it’s the first tiling window manager that I actually have enjoyed using.

What a tiling window manager essentially does is take care of positioning the windows you open by aligning them in a specific order. Why would you want this? Well, this is really useful for large screens and dual monitor setups as it saves you having to drag windows about and then resize them. Here’s a picture to illustrate this:

What I’ve done here is open chrome on the first monitor, then switched to the second monitor and open 3 terminals. Everything is positioned and all I’ve done is give the main terminal a bit more room to stop the code wrapping. Look cool? Here’s how to install it and get started using it…

Installing XMonad

Installation is quite straight forward:

apt-get install xmonad xmobar dwm-tools

This installs the XMonad window manager, the XMobar package which allows you to create a small status bar and the dwm-tools package gives you a nice application launcher. If you do not wish to use the status bar and application launcher and would prefer to keep your gnome panels by adding xmonad to gnome to have the best of both worlds, then just install xmonad only and look below for how keep the gnome panels.

If you’re not adding xmonad to gnome then once all of this is installed, logout, select XMonad from the session selection menu at the bottom of the login page.  You’ll notice nothing appears (unless you’re doing the gnome thing), this means its worked!

Getting Started

First thing you want to do is to open an application, to do this hold down the left ‘alt‘ key and press ‘p‘ this will bring up a menu at the top of the screen, start typing out the name of the application you wish to run and once its highlighted, hit enter. You can also delete as you type if you make a mistake and can use the arrow keys to move the selection. If you get a bit lost, hit escape if to cancel the process. I’ve loaded up Firefox:

Next open up something else, again alt + p to bring up the menu type out something, I’ve loaded Gwibber, it has taken place at the left of the screen, this is called the “main area“. Each new application you run loads into the main area and shunts what was there to the right. It should look like this:

Finally press alt + shift + enter to open up a terminal and your screen should now look like this:

Moving about

Use the alt key in conjunction with the j or k keys to move focus to the different windows, when you use alt + shift + j or k, it will move the currently focused window. There’s a convenience key combination of alt + enter to make the currently focused window shift to the main area.

Resizing

To give the main area a bit more or less room use alt + l and alt + h respectively.

Changing the view

If you press alt + space it will cycle the different views. The view we’re currently on (main area to the left, other applications to the right) is the default, the next one moves all our secondary windows to the bottom of the screen like so:

The final one makes the currently focused application go full screen and then you switch applications using the alt + j/k key combination. This view is useful if you want to watch flash on full screen.

Workspaces

You have 9 workspaces in which to put applications. When XMonad loads, you are using workspace 1. To move an application to a different workspace, first focus on the application you wish to move by using the alt + j/k keys and press alt + shift + a number from 1-9 to move it to the desired workspace. To change to a workspace just press alt + [1-9].

Dual monitors

If you have a dual monitor setup then you use alt + w to change focus to the left monitor and alt + e to change focus to the right monitor. By default, workspace 1 is on the main monitor, workspace 2 is on the second monitor. To switch the workspaces between monitors, just press alt + 2 or alt + 1. You’ll have to play about with workspace switching to get a feel for how it works, but it’s really straight forward.

Configuration

Now you’re used to using XMonad, we will now set up XMobar and alter the XMonad configuration. I’ve put up my config files onto github as pasting them in here gave some strange results….

Setting up XMobar

First up you’ll want to set up XMobar, to do this go to your home directory and create a file called .xmobarrc. This is my configuration which is ever so slightly modified from the default to include my local weather and bigger font size – Get your local weather code from here

My .xmobarrc config

What this gives is a status bar at the top displaying something like this:

Configuring XMonad

Next you’ll want to make a XMonad configuration, so create a folder called .xmonad in your home directory and then create a xmonad.hs file inside that. I’m not a Haskell guru, so my configuration is taken from this tutorial by John Goerzen

My .xmonad.hs config.

Note that you’ll need to modify the line beginning with “xmproc <- …” to match your path to the .xmobarrc file.  When done, hit alt + q to reload the configuration and there you go! The alt + q key combination simply reloads your XMonad configuration.

Doing more

This is by no means a complete tutorial on all you can do with your XMonad setup.  You can add other things like trays, designate workspaces for applications and even have individual applications display in certain ways.  Many more configuration examples can be found at the XMonad config archive page and you can learn more about XMobar at its homepage. There are a lot of things you can do, so it may be worth some effort to experiment and get things set up the way you want.

Tips & Tricks

Making windows look nice

If you’re using XMonad outside of gnome then you will notice it defaults back to the rather ugly theme.

You can set the theme by using a program called lxappearance (found thanks to this post on the ubuntu forums site.) All you need to do is:

apt-get install lxappearance

Run lxappearance and pick your theme, click apply and that will save your theme!

The “mod” key

Often around the internet you’ll see stuff like “press mod + q to reload the XMonad configuration.” The mod key by default is set to the alt key, but you can change this. You will want to do this if you use the irssi IRC client or GNU Emacs editor as the alt key is the basis of most of the shortcuts. To change the default mod key from alt to the windows key, add this line underneath the line in the XMonad config file beginning with “, layouthook…”:

, modMask = mod4Mask -- Rebind Mod to the Windows key

This means that instead of pressing alt + enter or alt + e you will be pressing win + enter and win + e.

Moving floating windows

If a floating window pops up (a window that sits in front of other applications, like a website authentication window or a dialog box) you can move this by holding down the mod key and then dragging the window with your mouse.

Keeping the Gnome Panels

If you want to keep the Gnome Panels, then what you can do is add XMonad to gnome!  All you need to do is open up a terminal and type “gconf-editor” one that opens navigate to Desktop>gnome>session>required_components and change the window manager attribute to “xmonad”. I’ve done this on my laptop and it looks like so:

This way you get to keep all the notifications and top tray for your chat, mail and Gwibber as well as keeping the default gnome menu.

One last thing…

If you’ve never tried out these types of window managers before, you’ll want to be able to shutdown your PC when done! To do this, open up a terminal by pressing alt + shift + enter and then type in the following command:

sudo poweroff

If you wish to restart then use the command reboot.  You can also get back to the login screen by pressing alt + shift + q and from there you can can go back to your previous desktop by simply selecting a different option at the bottom of the screen.

32 comments on “How-to: Set up XMonad & XMobar on Ubuntu

  1. Pingback: Tweets that mention How-to: Set up XMonad & XMobar on Ubuntu -- Topsy.com

  2. AM (AM's website)
    - Reply

    What version of Ubuntu are you using?

    I followed the directions exactly and it just screwed a lot of things up.

    Logging into an x-monad session dropped me in a session with a ridiculous screen resolution and my dual monitor setup was broken.

    In retrospect that’s not surprising but the post makes it sound like it just works.

    Following your directions to keep the gnome bar does nothing for an xmonad session, but it does add xmonad into a gnome session.

    This was all screwed up, there was no bar and windows wouldn’t open correctly. I’d have to switch around work spaces a bit and open a terminal before any windows would show up, and some of them got “lost” somewhere where I couldn’t get to them. I have to open up a terminal and kill them.

    Thanks for the effort anyway.

    1. Huntly (Huntly's website)
      - Reply

      Hey, I use lucid (10.04)

      I’m not sure why you had the graphics problems, I run an nvidia card on the desktop and one of the integrated intel cards on the laptop and nothing messed up when I logged in. I’m afraid, for me, for once it actually “just worked”…

      Sorry about the gnome panel bit, I need to clear that up, the whole point of that bit was to add xmonad to gnome, not the other way around! Thanks for pointing that out though.

      When you did the alt + q command to reload the xmonad config, did it throw up a window with any errors or warnings? By not having the bar and windows not opening correctly, it sounds like a config error to me.

      Hope this helps somewhat and thanks for taking the time to comment.

  3. AM (AM's website)
    - Reply

    Hey I really appreciate the effort to help, but I decided not to go with xmonad on my laptop (running Lucid). The tiling didn’t fit my work style/screen size.

    These directions did however work great on my desktop running #!, which is based on Jaunty. I run almost exclusively terminal apps on it; a lot of which I want to just keep open all the time (like irrsi) ….so xmonad is a great fit. This “cheat sheet” has me up and running pretty easily.

    Thanks

    1. Huntly (Huntly's website)
      - Reply

      Fair enough, completely understand that: I tried it out on my laptop first as it doesn’t matter much If I make a mess of it but, personally, I only find XMonad useful for fairly big displays (read >= 22″) or multi-monitor setups where you can comfortably have a few different things on the screen at one time. So I don’t bother with it on the laptop either.

      Glad you managed to get it working though! :)

  4. Rob (Rob's website)
    - Reply

    I’m using Xmonad (besides the desktop) on an eee pc which is just awesome with a properly configured Tabbed and Full layout.

    Certainly way more comfortable than anything else wasting space on stupid window decorations.

    Give it a try and be impressed.

  5. Pingback: Eamonn O’Brien-Strain » Blog Archive » links for 2011-02-09

  6. ri (ri's website)
    - Reply

    love it! xmonad the best thing is haskell base. how Rob i don’t like the decorations for windows (give me a Terminal and moving the world).

    Good post.

    1. Huntly (Huntly's website)
      - Reply

      Yeah the Haskell base makes it quite powerful in terms of setting up your config! But it’s quite easy to miss a character and mess it up too! :)

  7. Pingback: ใช้ xmonad กับ Ubuntu 10.10 | Wittawat's Blog

  8. Nick (Nick's website)
    - Reply

    I just followed your installation tutorial on Ubuntu 12.04. Your tutorial is very nice, thanks for posting! I have a question though: following your tutorial in 12.04 configures xmonad in such a way that when i open a new terminal (alt+shift+enter), I get a menu bar at the top: “File Edit View Search Terminal Help”. How can I remove that menu bar as in your pictures?

    1. Huntly (Huntly's website)
      - Reply

      Hey Nick, thanks for taking the time to comment, glad you found it useful. For the terminal issue you’ve got two options:

      1) If you’re using the default Gnome terminal there is a option under the view menu to hide the the menu. You can get it back at any point by right-clicking in the terminal window and selecting the appropriate option in the context menu.

      2) Whilst you’re experimenting with your setup, you might want to try out another terminal. RXVT is quite a popular terminal in the Arch Linux camp and comes without any menu bars, scroll bars or context menus. Have a look at this for more info: https://wiki.archlinux.org/index.php/Rxvt-unicode

      Good luck!

  9. Pingback: Chronicle of a ColdFusion Expatriot » Rediscovering the Linux desktop

    1. Huntly (Huntly's website)
      - Reply

      Sorry Jez, I can’t offer any advice as I don’t currently have ubuntu on my machine. I switched to crunchbang a while back with the default openbox setup which works quite well for me these days!

  10. Pingback: Installing XMonad on Gentoo | pikedom.com

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>