Author Topic: Using Xmonad in Ubuntu  (Read 1809 times)

0 Members and 1 Guest are viewing this topic.

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Using Xmonad in Ubuntu
« on: June 29, 2013, 08:26:57 pm »


Xmonad is a tiling window manager written and configured in Haskell.
I got a new laptop and decided to use Xmonad without Gnome or any other desktop manager.
As said >>here<<: "The advantages of using xmonad in Ubuntu without a full DE are speed and reduced memory use."

It's not only the overall performance that will be better, but also your working speed once you got used to navigating the tiling windows. I tried xmonad the first time on Arch and I never want back to non-tiling windows since then.
 You will need your mouse much less than before and you will get the most out of your screen as it isn't filled with unnecessary stuff, unless you want to.
 
 You can use the following description to set up your own Xmonad or just to see what is possible.
 Look at the end of my post for links to some other guides, i.e. using Xmonad in Gnome.

This is my current setup (screenshot):



For this you need to install:

Code: [Select]
xmonad
trayer
xmobar
gtk-theme-switch
xcompmgr
hsetroot
rxvt-unicode
suckless-tools (contains dmenu)

The configuration file for Xmonad is ~/.xmonad/xmonad.hs
Create this file. It looks like this for me:

Code: (Haskell) [Select]
import System.IO
import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.FadeInactive
import XMonad.Hooks.SetWMName
import XMonad.Util.Run (spawnPipe)
import XMonad.Util.EZConfig (additionalKeys)
import XMonad.Actions.GridSelect
import XMonad.Layout.Fullscreen
import XMonad.Layout.NoBorders (smartBorders)

myNormalBorderColor = "#cccccc"
myFocusedBorderColor = "#0000ff"

myManageHook = composeAll
        [ (className =? "Firefox" <&&> resource =? "Dialog") --> doFloat
        , className =? "Thunderbird" --> doShift "mail"
        , className =? "Firefox" --> doShift "web"
        , manageDocks
        ]

myLayout = Mirror tiled ||| tiled ||| Full
  where
    -- default tiling algorithm partitions the screen into two panes
    tiled   = Tall nmaster delta ratio
    -- The default number of windows in the master pane
    nmaster = 1
    -- Default proportion of screen occupied by master pane
    ratio   = 3/4
    -- Percent of screen to increment by when resizing panes
    delta   = 3/100

--fades inactive windows, but is a bit distracting
--myLogHook :: X ()
--myLogHook = fadeInactiveLogHook fadeAmount
--    where fadeAmount = 0.8

main = do
        xmproc <- spawnPipe "xmobar ~/.xmobarrctop"
        xmbottom <- spawnPipe "xmobar ~/.xmobarrcbottom"
        xmonad $ defaultConfig
                { manageHook = fullscreenManageHook <+> myManageHook <+> manageHook defaultConfig
                , handleEventHook = fullscreenEventHook

                -- add --depth 32 for transparency, you need xcompmgr for shadows and transparency effects
                , terminal = "urxvt -bg rgba:0000/0000/0000/eeee -fg rgba:cc00/cc00/cc00/ffff +vb +sb"

                -- spawn programs you want at startup
                , startupHook = do
                                spawn "thunderbird"
                                spawn "firefox"

                -- set your layout, smartborders removes window borders if not necessary
                , layoutHook = fullscreenFull $ avoidStruts $ smartBorders myLayout

                -- names and sequence of your workspaces
                , workspaces = ["web", "shell", "mail", "coding", "irc"] ++ map show [6..9]

                -- sets the windows key as mod key
                , modMask = mod4Mask

                -- pipe title information into top bar of xmobar
                , logHook = dynamicLogWithPP xmobarPP
                        { ppOutput = hPutStrLn xmproc
                        , ppTitle = xmobarColor "green" "" . shorten 50
                        }
                -- set your border colors
                , normalBorderColor = myNormalBorderColor
                , focusedBorderColor = myFocusedBorderColor
                }`additionalKeys`
                [ -- use Ctrl + Alt + L to lock the screen
                  ((mod1Mask .|. controlMask, xK_l), spawn "gnome-screensaver-command --lock")
                 --  use Ctrl + Print to make a delayed screenshot
                , ((controlMask, xK_Print), spawn "sleep 0.2; scrot -s")
                 -- use Print to make a screenshot
                , ((0, xK_Print), spawn "scrot")
                 -- Mod + g for gridselection for your workspaces
                , ((mod4Mask, xK_g), goToSelected defaultGSConfig)
                ]


Make sure that the file compiles by typing on the command line:


Code: [Select]
ghc --make xmonad.hsor
Code: [Select]
xmonad --recompile
Set up a custom xsession by creating a file in /usr/share/xsessions/custom.desktop that looks i.e. like this (Name can be whatever you like):

Code: [Select]
[Desktop Entry]
Name=MyCustomXsession
Exec=/etc/X11/Xsession

Edit or create your .xinitrc with the following contents, edit the path to the wallpaper you wish to have:

Code: [Select]
#!/bin/bash

#set trayer for applet icons
trayer --edge top --align right --SetDockType true --SetPartialStrut true \
 --expand true --width 5 --transparent true --alpha 0 --tint 0x000000 --height 16 &
#start network-manager applet
nm-applet --sm-disable &
#show wallpaper
hsetroot -full ~/pathtowallpaper.jpg
#start composite manager
xcompmgr -C &
#start xmonad
exec xmonad

xmobar is a minimalistic text based status bar that works well with xmonad and is also written in Haskell.
Set up the config files for the bars on top and bottom.

top (.xmobarrctop):

Code: [Select]
Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
       , bgColor = "black"
       , fgColor = "grey"
       , position = TopSize L 95 16
       , lowerOnStart = True
       , commands = [ Run Network "wlan0" ["-L","0","-H","300","--normal","green","--high","red"] 10
                        , Run Network "eth0" ["-L","0","-H","300","--normal","green","--high","red"] 10
                        , Run Memory ["-t","Mem: <usedratio>% (Cache: <cache>M)", "-L","3","-H","50","--normal","green","--high","red"] 10
                        , Run Swap [] 10
                        , Run StdinReader
                        , Run DiskU [("/", "DISK space: <used>/<size>")] ["-L", "20", "-H", "50", "-m", "1", "-p", "3"] 20
                        , Run DiskIO [("/", "read: <read> write: <write>")]
["-L","0","-H","5000","--normal","green","--high","red"] 10
                        ]
       , sepChar = "%"
       , alignSep = "}{"
       , template = "%memory% %swap% %disku% %diskio% } %StdinReader% { %wlan0%"
       }

bottom (.xmobarrcbottom):

Code: [Select]
Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
       , bgColor = "black"
       , fgColor = "grey"
       , position = Bottom
       , lowerOnStart = True
       , commands = [ Run Weather "EDDP" ["-t","<station>: <tempC> C","-L","10","-H","25","--normal","green","--high","red","--low","lightblue"] 36000
                        , Run MultiCpu ["-t", "CPU: <autobar>" , "-L","3","-H","50","--normal","green","--high","red", "-b", ":", "-f", ":"] 10
                        , Run StdinReader
                        , Run Com "uname" ["-s","-r"] "" 36000
                        , Run Date "%a %b %_d %Y %H:%M:%S" "date" 10
                        ]
       , sepChar = "%"
       , alignSep = "}{"
       , template = "%multicpu% } %uname% { %EDDP% | <fc=#ee9a00>%date%</fc>"
       }

Now log out of your current session and log in into your custom xsession (switch the session by clicking on the icon in the default Ubuntu login screen).

Last but not least use the gtk-theme-switch2 command to set up a theme you like.
The tool lxappearance may work too, but it didn't for me.

For more information see the links below.

xmobar:
http://projects.haskell.org/xmobar/

xmonad:
http://xmonad.org/

xmonad in ubuntu:
http://www.haskell.org/haskellwiki/Xmonad/Using_xmonad_in_Ubuntu

xmonad and gnome:
http://www.haskell.org/haskellwiki/Xmonad/Using_xmonad_in_Gnome

custom xsession:
https://wiki.ubuntu.com/CustomXSession

urxvt configuration:
https://wiki.archlinux.org/index.php/Rxvt-unicode
« Last Edit: June 29, 2013, 08:36:53 pm by Deque »

Offline proxx

  • Avatarception
  • Global Moderator
  • Titan
  • *
  • Posts: 2803
  • Cookies: 256
  • ФФФ
    • View Profile
Re: Using Xmonad in Ubuntu
« Reply #1 on: June 29, 2013, 10:41:42 pm »
Excellent story Deque.
I personally use awesome and before DWM for the raw speed.
Totally agree with you once you go tiling you never go back.
Its actually suprising how much of a workflow killer non tiling is.

Ill still have to try xmonad,I have experience with the above and I3 which is also a great.
Only If you like speed.. why ubuntu ?
« Last Edit: June 29, 2013, 10:43:08 pm by proxx »
Wtf where you thinking with that signature? - Phage.
This was another little experiment *evillaughter - Proxx.
Evilception... - Phage

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Using Xmonad in Ubuntu
« Reply #2 on: June 30, 2013, 06:18:43 am »
Excellent story Deque.
I personally use awesome and before DWM for the raw speed.
Totally agree with you once you go tiling you never go back.
Its actually suprising how much of a workflow killer non tiling is.

Ill still have to try xmonad,I have experience with the above and I3 which is also a great.
Only If you like speed.. why ubuntu ?

I have Arch on my desktop computer. But that's much too insecure to use on my laptop which I--sometimes--rarely update. You probably know the hazzle with an Arch system that wasn't updated a while ago. My laptop has to be relieable for doing work and presentations at university, I need a distro that just works and Ubuntu is great for that.
« Last Edit: June 30, 2013, 06:19:09 am by Deque »

Offline Deque

  • P.I.N.N.
  • Global Moderator
  • Overlord
  • *
  • Posts: 1203
  • Cookies: 518
  • Programmer, Malware Analyst
    • View Profile
Re: Using Xmonad in Ubuntu
« Reply #3 on: July 01, 2013, 01:35:43 pm »
xmobar provides the use of icons since version 0.17. So I used some icons for dzen which I got from >>here<<

The result looks like this:




These are my recent xmobar configuration files:

top:

Code: (Haskell) [Select]
Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
       , bgColor = "#000055"
       , fgColor = "#ffffff"
       , position = TopSize L 95 16
       , lowerOnStart = True
       , commands = [ Run Weather "EDDP" ["-t","<station>: <tempC> C","-L","10",
                                    "-H","25","--normal","green","--high","red",
                                    "--low","lightblue"] 36000
                        , Run Network "wlan0" ["-t","<icon=/home/deque/icons/net_down_03.xbm/> <rx> <icon=/home/deque/icons/net_up_03.xbm/> <tx>",
                                    "-S","True","-L","0","-H","300",
                                    "--normal","green", "--high","red"] 10
                        , Run Network "eth0" ["-L","0","-H","300","--normal",
                                    "green","--high","red"] 10
                        , Run Memory ["-t","<icon=/home/deque/icons/mem.xbm/> <usedratio>%",
                                    "-L","3","-H","50","--normal","green",
                                    "--high","red"] 10
                        , Run Swap [] 10
                        , Run StdinReader
                        , Run DiskU [("/", "<icon=/home/deque/icons/diskette.xbm/> space: <used>/<size>")]
                                    ["-L", "20", "-H", "50", "-m", "1", "-p", "3"] 20
                        , Run DiskIO [("/", "read: <read> write: <write>")]
                                    ["-L","0","-H","5000","--normal","green",
                                    "--high","red"] 10
                        , Run BatteryP ["BAT0"]
                                    ["-t", "<icon=/home/deque/icons/bat_full_01.xbm/> <acstatus> <leftbar>",
                                     "-L", "10", "-H", "80", "-p", "3", "--low", "red",
                                     "--normal","yellow","--high","green",
                                     "-b", "-", "-f", "|",
                                     "--", "-O", "<fc=green>On</fc>",
                                     "-L", "-15", "-H", "-5",
                                     "-l", "red", "-m", "blue", "-h", "green"] 20
                        ]
       , sepChar = "%"
       , alignSep = "}{"
       , template = "%memory% | %swap% | %disku% %diskio% } %StdinReader% { %wlan0% | %battery%"
       }

bottom:

Code: (Haskell) [Select]
Config { font = "-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
       , bgColor = "#000055"
       , fgColor = "#ffffff"
       , position = Bottom
       , lowerOnStart = True
       , commands = [ Run Weather "EDDP" ["-t","<station>: <tempC> C","-L","10",
                        "-H","25","--normal","green","--high","red","--low","lightblue"] 36000
                        , Run MultiCpu ["-t", "<icon=/home/deque/icons/cpu.xbm/> <total> | <icon=/home/deque/icons/cpu.xbm/><icon=/home/deque/icons/cpu.xbm/> <autototal>"
                        , "-L","40","-H","70","--low","lightblue","--normal"
                        ,"yellow","--high","red","--padchars","0","-w","2"
                        , "-b", ".", "-f", ":"] 10
                        , Run Com "uname" ["-s","-r"] "" 3600
                        , Run Locks
                        , Run Date "%a %_d %b %Y %H:%M:%S" "date" 10
                    ]
       , sepChar = "%"
       , alignSep = "}{"
       , template = "%multicpu% } <icon=/home/deque/icons/arch.xbm/> %uname% { <fc=#ffff00>%locks%</fc> %EDDP% | <icon=/home/deque/icons/clock.xbm/> <fc=#ee9a00>%date%</fc>"
       }

If you installed xmobar via apt-get you will have an older version (for me it was 0.14) that doesn't support any icons.

You get the most recent version using cabal.

Code: [Select]
sudo apt-get install cabal-install
sudo cabal update
sudo cabal install xmobar

The resulting binaries will be saved in

Code: [Select]
~/.cabal/bin/
In order to use these you should either call xmobar in your xmonad.hs (or wherever you call it) with the absolute path or add this to the root path (Note: this won't work by editing .bashrc, because that wouldn't be root)
« Last Edit: July 01, 2013, 01:36:32 pm by Deque »