Basic Xmonad setup in (L)ubuntu

tagged under   linux  


Updated 22-Sep-2013 : Autostart favorite applications on login [ jump to this ]

Updated 23-Sep-2013 : Toggling visibility of system-tray application "Trayer" [ jump to this ]

Xmonad is a featureful and productive tiling window manager written in Haskell. The following is a super simple setup on Lubuntu (can be setup similarly on Ubuntu based systems).

Installation

$ sudo apt-get install ghc6 libx11-dev cabal-install gmrun
$ sudo cabal update
$ sudo cabal install xmonad --global
$ sudo cabal install xmonad-contrib --global

Setup

Create the file /usr/share/xsessions/xmonad.desktop with the following contents (root required).

[Desktop Entry]
Name=XMonad
Comment=Lightweight tiling window manager
Exec=xmonad
Type=XSession

Give the above file proper permissions.

$ sudo chown root:root /usr/share/xsessions/xmonad.desktop

The above file is required to give you the option to choose xmonad as your window manager at the login prompt.

Next, let us configure xmonad itself. Create the file ~/.xmonad/xmonad.hs with the following contents.

import XMonad
import XMonad.Hooks.ManageDocks

main = do
    xmonad $ defaultConfig
        { modMask = mod4Mask -- make Win as mod key
        , terminal = "terminator" -- replace with your fav terminal emu
        , manageHook = manageDocks <+> manageHook defaultConfig -- ignore docks
        }

Finally the most imp thing -- aesthetics. If you use xmonad with just the above setup, you will find that gtk applications like firefox look terribly ugly, but fixing this issue is simple. So, go ahead and do it before you start using xmonad.

Launch gtk-chtheme and select your preferred gtk-2.0 theme and any font that catches your eye as well. Save your settings. You should now find the file ~/.gtkrc-2.0.

Now, let us fix some ugly gtk-3.0 apps as well. Create the file ~/.config/gtk-3.0/settings.ini with the following contents (choose your preferred themes and fonts).

[Settings]
gtk-theme-name = Lubuntu-default
gtk-icon-theme-name = Lubuntu
gtk-font-name = Ubuntu Medium 11

Thats it. Logout and log in selecting xmonad as your session (instead of the default Lubuntu) at the login prompt. You are greeted with a plain screen. Press Win+Shift+Ret to launch the terminal or Win+Shift+p to launch your fav apps via gmrun. For more basic keybindings and usage, checkout the man page of xmonad or head to Xmonad Official Doc.

You might also like to have a tray for your fav applets like nm-applet | dropbox | battery status | pidgin, etc. Read on.

$ sudo apt-get install trayer

Create a shell script ~/.autostart with execute permission with the following contents.

#!/bin/bash

mpd &>/dev/null &
dropbox start &>/dev/null &
redshift -l 12.9667:77.5667 -t 3700:3700 &>/dev/null &

trayer --edge bottom --align right --SetDockType true \
--SetPartialStrut true --expand true --width 20 --height 25 &>/dev/null &

sleep 1
nm-applet --sm-disable &>/dev/null &

I am using this script to start a few applications I use frequently like mpd(ncmpcpp), dropbox, redshift.

Then, I am creating a tray with trayer, and then launching nm-applet which I can then access from the tray which is visible on all workspaces (Win+1 to Win+9) courtesy of the managehook in our xmonad.hs configuration file.

At the moment, I am using this shell script to launch apps manually after logging into xmonad. My attempts at using .xinitrc or .xsession to automate the same have failed. I would appreciate it if anyone could point me in the right direction. I will keep this page updated as and when I find something new and noteworthy.

Comments and feedback and tips|tricks are welcome.




UPDATE SEP 22

Thanks to @kasbah for providing a solution to automate the startup of my fav applications in the comments below, which I provide here for completeness. The following is my new xmonad.hs to autostart applications.

import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO

main = do
    xmonad $ defaultConfig
        { modMask = mod4Mask
        , terminal = "terminator"
        , manageHook = manageDocks <+> manageHook defaultConfig
        , startupHook = startup
        } `additionalKeys`
        [ ((mod4Mask, xK_q), spawn "killall redshift nm-applet trayer"
          >> restart "xmonad" True)
        ]

startup :: X()
startup = do
    spawn "mpd"
    spawn "dropbox start"
    spawn "redshift -l 12.9667:77.5667 -t 3700:3700"
    spawn "trayer --edge bottom --align right --SetDockType true
           --SetPartialStrut true --expand true --widthtype percent
           --width 100 --height 25"
    spawn "nm-applet"

This is basically using the startupHook concept to start applications after xmonad loads. The problem with using startupHook alone is that the applications are (re)started everytime I reload the xmonad config with Win+q. To overcome this limitation, I have rebinded Win+q to first kill the applications that I autostarted before restarting xmonad itself.




UPDATE SEP 23

The problem with the above xmonad config is that the trayer gets blocked by open apps. To use the trayer applets, you will have to go to an empty workspace (with no open apps). To overcome this limitation, use the xmonad.hs below which sets the strut option for trayer and then asks xmonad not to block struts with the application windows. There is also a keybinding Win+b to toggle the struts(toggle the display of trayer), thus making trayer accessible even when other apps are open.

import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeys)
import System.IO

main = do
    xmonad $ defaultConfig
        { modMask = mod4Mask
        , terminal = "terminator"
        , manageHook = manageDocks <+> manageHook defaultConfig
        , layoutHook = avoidStruts  $  layoutHook defaultConfig
        , startupHook = startup
        } `additionalKeys`
        [ ((mod4Mask, xK_q), spawn "sudo killall redshift nm-applet trayer"
          >> restart "xmonad" True)
        , ((mod4Mask, xK_z), spawn "slock")
        , ((mod4Mask, xK_b), sendMessage ToggleStruts)
        ]

startup :: X()
startup = do
    spawn "mpd"
    spawn "dropbox start"
    spawn "redshift -l 12.9667:77.5667 -t 3700:3700"
    spawn "trayer --edge bottom --align right --SetDockType true
           --SetPartialStrut true --expand true --widthtype percent
           --width 100 --height 25"
    spawn "sudo nm-applet"

« older posts newer posts »



other articles you might like
  • Configuring Lenovo T440s touchpad in Linux
  • Alternatives to Truecrypt on Linux
  • Connecting to wired/wireless networks via command line
  • Android reverse USB tethering
  • Linux command line tools and tricks - Part 3
  • Basic dwm setup in (L)ubuntu
  • EOM a.k.a End of Mail a.k.a Emacs + offlineimap + mu4e
  • First attempt at developing a Firefox addon
  • Bash script to perform super-fast file transfer using netcat and tar
  • Jekyll : Handling Github page build failure and Jekyll plugins on Github
  • Emacs newbie cheat sheet -- from a vim convert
  • ncmpcpp : ncurses based music player for Linux
  • How to create a custom CWM recovery flash-able android apps zip file in Linux via command line
  • Task Warrior - The best CLI task manager for Linux
  • Custom kernel in Ubuntu (also generate .deb package)
  • Linux command line tools and tricks - Part 2
  • Superb Linux command line tools and tricks for Linux geeks
  • RSA encryption using Tcl



  • Share this post ⇒  





    blog comments powered by Disqus