pseup /.xmonad/xmonad.hs

-- Import {{{
import XMonad
import XMonad.Operations

import XMonad.Layout
import XMonad.Layout.NoBorders
import XMonad.Layout.ThreeColumns
import XMonad.Layout.PerWorkspace ( onWorkspace )

import XMonad.Hooks.DynamicLog ( PP(..), dynamicLogWithPP, dzenColor, shorten, wrap, defaultPP )
import XMonad.Hooks.ManageDocks

import XMonad.Prompt
import XMonad.Prompt.Shell

import qualified XMonad.StackSet as W
import qualified Data.Map as M
import System.Exit
import Graphics.X11.Xlib

import XMonad.Util.Run (spawnPipe)
import System.IO (Handle, hPutStrLn)
-- }}}
--------------------------------
-- Settings {{{
pIconDir = "/home/pseup/.xmonad/icons/"
pFont    = "-*-terminus-medium-*-*-*-12-*-*-*-*-*-*-*"

pTerm = "urxvtc"

normalBorderColor'  = "#323232"
focusedBorderColor' = "#323232"

pBorder :: Dimension
pBorder = 1

pGaps = [(18,0,0,0)]
pStatusCmd = "dzen2 -e '' -x 0 -y 0 -h 18 -w 960 -ta l -fg '#c5c5c5' -bg '#232323' -fn '" ++ pFont ++ "'"

modMask' :: KeyMask
modMask' = mod4Mask

-- }}}
--------------------------------
-- Main {{{
main = do
       h <- spawnPipe pStatusCmd
       xmonad $ defaultConfig 
              { workspaces = pWorkspaces
              , modMask = modMask'
              , borderWidth = pBorder
              , normalBorderColor = normalBorderColor'
              , focusedBorderColor = focusedBorderColor'
              , defaultGaps = pGaps
              , terminal = pTerm
              , keys = pKeys
              , logHook = dynamicLogWithPP $ customPP h
              , manageHook = manageHook defaultConfig <+> manageHook' -- <+> (doF W.swapDown)
              , layoutHook = pLayout
              }
-- }}}
--------------------------------
-- Dzen Pretty Printer {{{
customPP i = defaultPP 
           { ppCurrent = wrap "^fg(#DDDDDD)^bg(#323232)^p(6)" "^p(6)^fg()^bg()"
           , ppVisible = wrap "^fg(#555555)^bg(#232323)^p(6)" "^p(6)^fg()^bg()"
           , ppHidden  = wrap "^fg(#BBBBBB)^bg(#232323)^p(6)" "^p(6)^fg()^bg()"
           , ppHiddenNoWindows = wrap "^fg(#555555)^bg(#262626)^p(6)" "^p(6)^fg()^bg()"
           , ppLayout  = (\x -> case x of
                                     "Tall"        -> "^i(" ++ pIconDir ++ "/tileright.xbm)"
                                     "Mirror Tall" -> "^i(" ++ pIconDir ++ "/tilebottom.xbm)"
                                     "Full"        -> "^i(" ++ pIconDir ++ "/max.xbm)"
                                     "ThreeCol"    -> "^i(" ++ pIconDir ++ "/threecol.xbm)"
                                     )
           , ppTitle   = shorten 80
           , ppSep     = " "
           , ppWsSep   = ""
           , ppOutput  = hPutStrLn i
           }
-- }}}
--------------------------------
-- Prompt Setup {{{
pXPConfig :: XPConfig
pXPConfig = defaultXPConfig
          { position    = Top
          , font        = pFont
          , bgColor     = "#c5c5c5"
          , fgColor     = "#232323"
          , fgHLight    = "#e1e1e1"
          , bgHLight    = "#1e1e1e"
          , promptBorderWidth = 0
          }
-- }}}
--------------------------------
-- Workspaces & Layouts {{{
pWorkspaces :: [WorkspaceId]
pWorkspaces = ["Main", "Web", "Code", "Util", "Misc"]

pLayout = avoidStruts . smartBorders
        $ onWorkspace "Code" (ThreeCol 1 (3/100) (1/2))
        $ tiled ||| Mirror tiled ||| noBorders Full
  where
    tiled = Tall 1 (2/100) (2/3) 

-- }}}
--------------------------------
-- Hooks {{{
logHook' :: Handle -> X ()
logHook' h = dynamicLogWithPP $ customPP h
-- { ppOutput = hPutStrLn h } --dynamicLogXinerama

manageHook' :: ManageHook
manageHook' = composeAll . concat $
  [ [ className =? c --> doFloat | c <- myFloats ]
  ]
  where myFloats = ["feh"]
-- }}}
--------------------------------
-- Key Bindings {{{

pKeys :: XConfig Layout -> M.Map (KeyMask, KeySym) (X ())
pKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
    -- launching and killing programs
    [ ((modMask .|. shiftMask, xK_t     ), spawn $ XMonad.terminal conf) -- %! Launch terminal
    , ((modMask,               xK_p     ), shellPrompt pXPConfig) -- Open shel prompt 
    , ((modMask .|. shiftMask, xK_c     ), kill) -- %! Close the focused window
    , ((modMask .|. shiftMask, xK_v     ), spawn "urxvtc -e vim")
    , ((modMask .|. shiftMask, xK_w     ), spawn "firefox")
    , ((modMask .|. shiftMask, xK_m     ), spawn "urxvt")
    , ((modMask,               xK_Print ), spawn "scrot /home/pseup/Pictures/Screenshots/%y%m%d_%H-%M-%S.png")

    , ((modMask,               xK_space ), sendMessage NextLayout) -- %! Rotate through the available layout algorithms
    , ((modMask .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf) -- %!  Reset the layouts on the current workspace to default

    , ((modMask,               xK_n     ), refresh) -- %! Resize viewed windows to the correct size

    -- move focus up or down the window stack
    , ((modMask,               xK_Tab   ), windows W.focusDown) -- %! Move focus to the next window
    , ((modMask,               xK_j     ), windows W.focusDown) -- %! Move focus to the next window
    , ((modMask,               xK_k     ), windows W.focusUp  ) -- %! Move focus to the previous window
    , ((modMask,               xK_m     ), windows W.focusMaster  ) -- %! Move focus to the master window

    -- mpd controls
    , ((modMask .|. controlMask,  xK_h     ), spawn "mpc prev")
    , ((modMask .|. controlMask,  xK_t     ), spawn "mpc pause")
    , ((modMask .|. controlMask,  xK_n     ), spawn "mpc play")
    , ((modMask .|. controlMask,  xK_s     ), spawn "mpc next")

    , ((modMask .|. controlMask,  xK_g     ), spawn "mpc seek -2%")
    , ((modMask .|. controlMask,  xK_c     ), spawn "mpc volume -5")
    , ((modMask .|. controlMask,  xK_r     ), spawn "mpc volume +5")
    , ((modMask .|. controlMask,  xK_l     ), spawn "mpc seek +2%")


    -- modifying the window order
    , ((modMask,               xK_Return), windows W.swapMaster) -- %! Swap the focused window and the master window
    , ((modMask .|. shiftMask, xK_j     ), windows W.swapDown  ) -- %! Swap the focused window with the next window
    , ((modMask .|. shiftMask, xK_k     ), windows W.swapUp    ) -- %! Swap the focused window with the previous window

    -- resizing the master/slave ratio
    , ((modMask,               xK_h     ), sendMessage Shrink) -- %! Shrink the master area
    , ((modMask,               xK_l     ), sendMessage Expand) -- %! Expand the master area

    -- floating layer support
    , ((modMask,               xK_t     ), withFocused $ windows . W.sink) -- %! Push window back into tiling

    -- increase or decrease number of windows in the master area
    , ((modMask              , xK_comma ), sendMessage (IncMasterN 1)) -- %! Increment the number of windows in the master area
    , ((modMask              , xK_period), sendMessage (IncMasterN (-1))) -- %! Deincrement the number of windows in the master area

    -- toggle the status bar gap
    , ((modMask              , xK_b     ), modifyGap (\i n -> let x = (XMonad.defaultGaps conf ++ repeat (0,0,0,0)) !! i in if n == x then (0,0,0,0) else x)) -- %! Toggle the status bar gap

    -- quit, or restart
    , ((modMask .|. shiftMask, xK_q     ), io (exitWith ExitSuccess)) -- %! Quit xmonad
    , ((modMask              , xK_q     ), restart "xmonad" True) -- %! Restart xmonad
    ]
    ++
    -- mod-[1..9] %! Switch to workspace N
    -- mod-shift-[1..9] %! Move client to workspace N
    [((m .|. modMask, k), windows $ f i)
        | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
    ++
    -- mod-{a,o} %! Switch to physical/Xinerama screens 1, 2, or 3
    -- mod-shift-{a,o} %! Move client to screen 1, 2, or 3
    [((m .|. modMask, key), screenWorkspace sc >>= flip whenJust (windows . f))
        | (key, sc) <- zip [xK_a, xK_o] [0..]
        , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
-- }}}