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?
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…
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!
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:
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.
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.
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].
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.
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
What this gives is a status bar at the top displaying something like this:
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
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.
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.
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:
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.