Advertisement
Guest User

binarycodes

a guest
Mar 15th, 2009
47
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- xmonad.hs
  2. -- Author: sujoy `binarycodes` <[email protected]>
  3. --
  4. -- Last Modified: 4th January, 2009
  5. --
  6.  
  7. -------------------------------------------------------------------------------
  8. -- Imports --
  9. -- stuff
  10. import XMonad
  11. import qualified XMonad.StackSet as W
  12. import qualified Data.Map as M
  13. import Data.Ratio ((%))
  14. import System.Exit
  15. import System.IO (Handle, hPutStrLn)
  16.  
  17. -- utils
  18. import XMonad.Util.Run (spawnPipe)
  19.  
  20. -- hooks
  21. import XMonad.Hooks.ManageDocks
  22. import XMonad.Hooks.DynamicLog
  23. import XMonad.Hooks.UrgencyHook
  24. import XMonad.ManageHook
  25.  
  26. -- layouts
  27. import XMonad.Layout.NoBorders
  28. import XMonad.Layout.ResizableTile
  29. import XMonad.Layout.Tabbed
  30. import XMonad.Layout.Grid
  31. import XMonad.Layout.PerWorkspace (onWorkspace)
  32. import XMonad.Layout.IM
  33. import XMonad.Layout.ThreeColumns
  34. import XMonad.Layout.SimplestFloat
  35.  
  36. -------------------------------------------------------------------------------
  37. -- Main --
  38. main = do
  39.        h <- spawnPipe "xmobar"
  40.        xmonad $ withUrgencyHook NoUrgencyHook
  41.               $ defaultConfig
  42.               { workspaces = workspaces'
  43.              , modMask = modMask'
  44.               , borderWidth = borderWidth'
  45.              , normalBorderColor = normalBorderColor'
  46.               , focusedBorderColor = focusedBorderColor'
  47.              , terminal = terminal'
  48.               , keys = keys'
  49.              , logHook = logHook' h
  50.               , layoutHook = layoutHook'
  51.              , manageHook = manageHook'
  52.               }
  53.  
  54. -------------------------------------------------------------------------------
  55. -- Hooks --
  56. manageHook' :: ManageHook
  57. manageHook' = myManageHook <+> manageHook defaultConfig <+> manageDocks <+> (doF W.swapDown)
  58.  
  59. myManageHook = composeAll $ concat
  60.              [ [ stringProperty "WM_WINDOW_ROLE" =? roleC --> doIgnore | roleC <- hide ]
  61.              , [ className =? webC --> doF (W.shift $ getWorkspaceId "web")  | webC <- web ]
  62.              , [ className =? mailC --> doF (W.shift $ getWorkspaceId "mail") | mailC <- mail ]
  63.              , [ className =? docC --> doF (W.shift $ getWorkspaceId "doc")  | docC <- doc ]
  64.              , [ className =? codeC --> doF (W.shift $ getWorkspaceId "code") | codeC <- code ]
  65.              , [ className =? chatC --> doF (W.shift $ getWorkspaceId "chat") | chatC <- chat ]
  66.              , [ className =? multC --> doF (W.shift $ getWorkspaceId "mult") | multC <- mult ]
  67.              , [ className =? downC --> doF (W.shift $ getWorkspaceId "down") | downC <- down ]
  68.              ]
  69.              where web  = [ "Gran Paradiso", "Opera", "Firefox", "Kazehakase" ]
  70.                    doc  = [ "GV" ,"Evince", "Xchm" ]
  71.                    code = [ ]
  72.                    chat = [ "Pidgin" ]
  73.                    mult = [ "Gimp" , "Blender" ]
  74.                    mail = [ "Thunderbird-bin", "Liferea-bin" ]
  75.                    down = [ "Transmission", "Deluge" ]
  76.                    hide = [ ]
  77.  
  78.  
  79. logHook' :: Handle ->  X ()
  80. logHook' h = dynamicLogWithPP $ customPP { ppOutput = hPutStrLn h }
  81.  
  82. layoutHook' = customLayout
  83.  
  84. -------------------------------------------------------------------------------
  85. -- Looks --
  86. -- bar
  87. customPP :: PP
  88. customPP = defaultPP { ppCurrent = xmobarColor "#71BEBE" ""
  89.                     , ppTitle =  shorten 80
  90.                     , ppSep =  "<fc=#EFE58B> | </fc>"
  91.                     , ppUrgent = wrap "<fc=#FF0000>*</fc>" "<fc=#FF0000>*</fc>"  
  92.                     , ppHidden = xmobarColor "#A5DCA5" ""
  93.                     , ppHiddenNoWindows = xmobarColor "#C4C4C4" ""
  94.                     }
  95.  
  96. -- borders
  97. borderWidth' :: Dimension
  98. borderWidth' = 1
  99.  
  100. normalBorderColor', focusedBorderColor' :: String
  101. normalBorderColor'  = "#222222"
  102. focusedBorderColor' = "#222222"
  103.  
  104. -- workspaces
  105. workspaceNames :: [String]
  106. workspaceNames = [ "main", "web", "chat", "doc", "code", "mail", "mult", "down" ]
  107.  
  108. workspaces' :: [WorkspaceId]
  109. workspaces' = zipWith (++) (map show [1..]) wsnames
  110.     where wsnames = map((:) ':') workspaceNames
  111.  
  112. getWorkspaceId :: String -> WorkspaceId
  113. getWorkspaceId name = case lookup name (zip workspaceNames workspaces') of
  114.     Just wsId -> wsId
  115.     Nothing -> head workspaces'
  116.  
  117. -- layouts
  118. customLayout = onWorkspace (getWorkspaceId "main") mainL
  119.             $ onWorkspace (getWorkspaceId "web") webL
  120.             $ onWorkspace (getWorkspaceId "doc") docL
  121.             $ onWorkspace (getWorkspaceId "chat") chatL
  122.             $ onWorkspace (getWorkspaceId "code") codeL
  123.          $ onWorkspace (getWorkspaceId "mult") multL
  124.             $ restL
  125.        where tiled = ResizableTall 1 (2/100) (1/2) []
  126.              threeCol = ThreeCol 1 (3/100) (1/2)
  127.  
  128.              im = avoidStruts $ IM ration roster
  129.              ration = 1%5
  130.              roster = And (ClassName "Pidgin") (Role "buddy_list")
  131.           --roster = Title "Pidgin"
  132.  
  133.              mainL = avoidStruts $ smartBorders (tiled ||| Grid ||| Mirror tiled ||| simpleTabbedBottom ||| Full)
  134.              webL  = avoidStruts $ smartBorders (Full ||| Mirror tiled ||| tiled ||| simpleTabbedBottom)
  135.              docL  = avoidStruts $ smartBorders (Mirror tiled ||| tiled ||| Full ||| simpleTabbedBottom)
  136.              codeL = avoidStruts $ smartBorders (tiled ||| Mirror tiled ||| Full ||| Grid)
  137.              chatL = avoidStruts $ smartBorders (im ||| threeCol ||| Mirror tiled ||| tiled)
  138.           multL = avoidStruts $ smartBorders (simplestFloat ||| threeCol ||| Mirror tiled ||| tiled)
  139.              restL = avoidStruts $ smartBorders (tiled ||| Full ||| Grid ||| threeCol ||| simplestFloat)
  140.  
  141. -------------------------------------------------------------------------------
  142. -- Terminal --
  143. terminal' :: String
  144. terminal' = "urxvtc"
  145.  
  146. -- Dmenu stuffs --
  147. myBarFont :: String
  148. myBarFont = "-*-profont-*-*-*-*-11-*-*-*-*-*-*-*"
  149.  
  150. myFocsFG, myFocsBG :: String
  151. myFocsFG = "#000000" -- focused foreground colour
  152. myFocsBG = "#999999" -- focused background colour
  153.  
  154. myNormFG, myNormBG :: String
  155. myNormFG = "#8ba574" -- normal foreground colour
  156. myNormBG = "#000000" -- normal background colour
  157.  
  158. myDmenuCmd :: String
  159. myDmenuCmd = "dmenu_path | dmenu -i -p 'Run:'" ++ myDmenuOpts
  160.      where myDmenuOpts = concatMap ((:) ' '. (:) '-')
  161.                  [ wrap "nf '" "'" myNormFG
  162.                  , wrap "nb '" "'" myNormBG
  163.                  , wrap "sf '" "'" myFocsFG
  164.                  , wrap "sb '" "'" myFocsBG
  165.                  , wrap "fn '" "'" myBarFont ]
  166.  
  167. -------------------------------------------------------------------------------
  168. -- Keys/Button bindings --
  169. -- modmask
  170. modMask' :: KeyMask
  171. modMask' = mod4Mask
  172.  
  173. -- keys
  174. keys' :: XConfig Layout -> M.Map (KeyMask, KeySym) (X ())
  175. keys' conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
  176.    -- launching and killing programs
  177.    [ --((modMask,               xK_Return), spawn $ XMonad.terminal conf)
  178.     ((modMask,               xK_p     ), spawn $ "exe=`" ++ myDmenuCmd ++ "` && eval \"exec $exe\"")
  179.    --, ((modMask,               xK_F2    ), spawn "gmrun")
  180.    , ((modMask .|. shiftMask, xK_c     ), kill)
  181.    --, ((modMask .|. shiftMask, xK_m     ), spawn "thunderbird")
  182.     --, ((modMask,         xK_f ), spawn "firefox")
  183.     --, ((modMask .|. shiftMask, xK_p   ), spawn "pidgin")
  184.     --, ((modMask,         xK_o ), spawn "opera")
  185.    --, ((modMask,               xK_w     ), spawn "/usr/lib/wicd/gui.py")
  186.    --, ((modMask,               xK_e     ), spawn "urxvtc -e emacs -nw")
  187.    -- layouts
  188.    , ((modMask,               xK_space ), sendMessage NextLayout)
  189.    , ((modMask .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
  190.    , ((modMask,               xK_b     ), sendMessage ToggleStruts)
  191.  
  192.    -- floating layer stuff
  193.    , ((modMask,               xK_t     ), withFocused $ windows . W.sink)
  194.  
  195.    -- refresh
  196.    , ((modMask,               xK_n     ), refresh)
  197.  
  198.    -- focus
  199.    , ((modMask,               xK_Tab   ), windows W.focusDown)
  200.    , ((modMask,               xK_j     ), windows W.focusDown)
  201.    , ((modMask,               xK_k     ), windows W.focusUp)
  202.    , ((modMask,               xK_m     ), windows W.focusMaster)
  203.  
  204.    -- swapping
  205.    , ((modMask .|. shiftMask, xK_Return), windows W.swapMaster)
  206.    , ((modMask .|. shiftMask, xK_j     ), windows W.swapDown  )
  207.    , ((modMask .|. shiftMask, xK_k     ), windows W.swapUp    )
  208.  
  209.    -- increase or decrease number of windows in the master area
  210.    , ((modMask              , xK_comma ), sendMessage (IncMasterN 1))
  211.    , ((modMask              , xK_period), sendMessage (IncMasterN (-1)))
  212.  
  213.    -- resizing
  214.    , ((modMask,               xK_h     ), sendMessage Shrink)
  215.    , ((modMask,               xK_l     ), sendMessage Expand)
  216.    , ((modMask .|. shiftMask, xK_h     ), sendMessage MirrorShrink)
  217.    , ((modMask .|. shiftMask, xK_l     ), sendMessage MirrorExpand)
  218.  
  219.    -- quit, or restart
  220.    , ((modMask .|. shiftMask, xK_q     ), io (exitWith ExitSuccess))
  221.    , ((modMask              , xK_q     ), restart "xmonad" True)
  222.  
  223.    ]
  224.    ++
  225.    -- mod-[1..9] %! Switch to workspace N
  226.    -- mod-shift-[1..9] %! Move client to workspace N
  227.    [((m .|. modMask, k), windows $ f i)
  228.        | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
  229.        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
  230.  
  231. -------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement