Advertisement
Guest User

descendent87

a guest
Feb 16th, 2010
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 11.63 KB | None | 0 0
  1. -- Imports {{{
  2. import XMonad
  3.  
  4. import XMonad.Actions.CycleWS       (toggleWS)
  5. import XMonad.Actions.UpdatePointer
  6.  
  7. import XMonad.Hooks.DynamicLog
  8. import XMonad.Hooks.FadeInactive
  9. import XMonad.Hooks.ManageHelpers
  10. import XMonad.Hooks.ManageDocks
  11. import XMonad.Hooks.UrgencyHook
  12.  
  13. import XMonad.Layout.IM
  14. import XMonad.Layout.LayoutHints    (layoutHintsWithPlacement)
  15. import XMonad.Layout.NoBorders
  16. import XMonad.Layout.PerWorkspace   (onWorkspace)
  17. import XMonad.Layout.ResizableTile
  18.  
  19. import XMonad.Util.EZConfig         (additionalKeysP)
  20. import XMonad.Util.Loggers          (maildirNew,dzenColorL,wrapL)
  21. import XMonad.Util.Run              (spawnPipe)
  22. import XMonad.Util.Scratchpad
  23. import XMonad.Util.WindowProperties (getProp32s)
  24. import XMonad.Util.WorkspaceCompare (getSortByXineramaRule)
  25.  
  26. import Data.List
  27. import Data.Monoid
  28. import Data.Ratio
  29.  
  30. import System.IO
  31.  
  32. import qualified Data.Map        as M
  33. import qualified XMonad.StackSet as W
  34.  
  35. -- }}}
  36.  
  37. -- Main {{{
  38.  
  39. main = do
  40.   d <- spawnPipe myLeftBar -- spawn the left statusbar
  41.   spawn myRightBar         -- spawn the right statusbar
  42.   spawn "conky"            -- spawn a standard conky
  43.  
  44.   -- and finally, start xmonad
  45.   xmonad $ withUrgencyHook myUrgencyHook $ defaultConfig
  46.     { terminal           = myTerminal
  47.     , modMask            = myModMask
  48.     , workspaces         = myWorkspaces
  49.     , borderWidth        = myBorderWidth
  50.     , normalBorderColor  = myNormalBorderColor
  51.     , focusedBorderColor = myFocusedBorderColor
  52.     , layoutHook         = myLayout
  53.     , manageHook         = myManageHook
  54.     , logHook            = myLogHook d
  55.     } `additionalKeysP` myKeys
  56.  
  57. -- }}}
  58.  
  59. -- Theme {{{
  60. --
  61. -- adjust these variables, they are used throughout
  62. --
  63. myXFTFont    = "xft:Verdana-8"   -- see 'Status Bars' for the dzen font
  64. conkyFile    = "~/.dzen_conkyrc" -- populates right status bar
  65.  
  66. colorBG      = "#303030"         -- background
  67. colorFG      = "#606060"         -- foreground
  68. colorFG2     = "#909090"         -- foreground w/ emphasis
  69. colorFG3     = "#ffffff"         -- foreground w/ strong emphasis
  70. colorUrg     = "#ffa824"         -- urgent
  71.  
  72. barHeight    = 17
  73. monitorWidth = 1920          -- two statusbars will span this width
  74. leftBarWidth = 960               -- right bar will span difference
  75.  
  76. -- }}}
  77.  
  78. -- Options {{{
  79. --
  80. -- you should adjust the terminal
  81. --
  82. -- if you change workspace names, be sure to update them throughout
  83. --
  84. myTerminal           = "urxvt"
  85. myWorkspaces         = ["1-main","2-web","3-chat"] ++ map show [4..9]
  86. myNormalBorderColor  = colorBG
  87. myFocusedBorderColor = colorFG3
  88. myBorderWidth        = 1
  89. myModMask            = mod4Mask
  90.  
  91. -- }}}
  92.  
  93. -- Layouts {{{
  94. myLayout = avoidStruts $ onWorkspace "2-web"  webLayouts
  95.                        $ onWorkspace "3-chat" imLayout
  96.                        $ standardLayouts
  97.  
  98.   where
  99.    
  100.     standardLayouts = tiled ||| Mirror tiled ||| full
  101.     webLayouts      = full ||| tiled ||| Mirror tiled
  102.  
  103.     -- im roster on left tenth, standardLayouts in other nine tenths
  104.     imLayout        = withIM (1/10) imProp standardLayouts
  105.  
  106.     -- WMROLE = "roster" is Gajim.py's buddy list
  107.     imProp          = Role "roster"
  108.  
  109.     tiled           = hinted (ResizableTall nmaster delta ratio [])
  110.     full            = hinted (noBorders Full)
  111.  
  112.     -- like hintedTile but for any layout
  113.     hinted l        = layoutHintsWithPlacement (0,0) l
  114.  
  115.     nmaster         = 1
  116.     delta           = 3/100
  117.     ratio           = toRational (2/(1 + sqrt 5 :: Double)) -- golden ratio
  118.  
  119. -- }}}
  120.  
  121. -- ManageHook {{{
  122. myManageHook = (composeAll . concat $
  123.   [ [resource  =? r                 --> doIgnore         |  r    <- myIgnores] -- ignore desktop
  124.   , [className =? c                 --> doShift "2-web"  |  c    <- myWebs   ] -- move webs to web
  125.   , [title     =? t                 --> doShift "3-chat" |  t    <- myChatT  ] -- move chats to chat
  126.   , [className =? c                 --> doShift "3-chat" | (c,_) <- myIM     ] -- move chats to chat
  127.   , [className =? c <&&> role /=? r --> doFloat          | (c,r) <- myIM     ] -- float all ims but roster
  128.   , [className =? c                 --> doCenterFloat    |  c    <- myFloats ] -- float my floats
  129.   , [name      =? n                 --> doCenterFloat    |  n    <- myNames  ] -- float my names
  130.   , [isFullscreen                   --> myDoFullFloat                        ]
  131.   ]) <+> manageTypes <+> manageDocks <+> manageScratchPad
  132.  
  133.   where
  134.  
  135.     role      = stringProperty "WM_WINDOW_ROLE"
  136.     name      = stringProperty "WM_NAME"
  137.  
  138.     -- [("ClassName","Role")]
  139.     myIM      = [("Gajim.py","roster","Pidgin","Pidgin.py")]
  140.  
  141.     -- titles
  142.     myChatT   = ["irssi","claws"]
  143.  
  144.     -- classnames
  145.     myFloats  = ["MPlayer","Zenity","VirtualBox","Xmessage","Save As...","XFontSel"]
  146.     myWebs    = ["Navigator","Shiretoko","Firefox","Uzbl","uzbl","Google-chrome", "Chromium"]
  147.  
  148.     -- resources
  149.     myIgnores = ["desktop","desktop_window"]
  150.  
  151.     -- names
  152.     myNames   = ["gmrun","Google Chrome Options","Chromium Options"]
  153.  
  154. -- a trick for fullscreen but stil allow focusing of other WSs
  155. myDoFullFloat :: ManageHook
  156. myDoFullFloat = doF W.focusDown <+> doFullFloat
  157.  
  158. -- manage the scratchpad
  159. manageScratchPad :: ManageHook
  160. manageScratchPad = scratchpadManageHook (W.RationalRect l t w h)
  161.  
  162.   where
  163.  
  164.     -- bottom 10% of the monitor
  165.     h = 0.1
  166.     w = 1
  167.     t = 1 - h
  168.     l = 1 - w
  169.  
  170. -- modified version of manageDocks
  171. manageTypes :: ManageHook
  172. manageTypes = checkType --> doCenterFloat
  173.  
  174. checkType :: Query Bool
  175. checkType = ask >>= \w -> liftX $ do
  176.   m   <- getAtom    "_NET_WM_WINDOW_TYPE_MENU"
  177.   d   <- getAtom    "_NET_WM_WINDOW_TYPE_DIALOG"
  178.   u   <- getAtom    "_NET_WM_WINDOW_TYPE_UTILITY"
  179.   mbr <- getProp32s "_NET_WM_WINDOW_TYPE" w
  180.  
  181.   case mbr of
  182.     Just [r] -> return $ elem (fromIntegral r) [m,d,u]
  183.     _        -> return False
  184.  
  185. -- }}}
  186.  
  187. -- Status Bars {{{
  188. --
  189. -- build two dzen2 bars
  190. --
  191. -- for non xft use something like this instead:
  192. --  
  193. --  myDzenFont = "-*-terminus-medium-*-*-*-12-*-*-*-*-*-*-*"
  194. --
  195. myDzenFont :: String
  196. myDzenFont = drop 4 myXFTFont -- strip the 'xft:' part
  197.  
  198. makeDzen :: Int -> Int -> Int -> Int -> String -> String
  199. makeDzen x y w h a = "dzen2 -p" ++
  200.                      " -ta "    ++ a          ++
  201.                      " -x "     ++ show x     ++
  202.                      " -y "     ++ show y     ++
  203.                      " -w "     ++ show w     ++
  204.                      " -h "     ++ show h     ++
  205.                      " -fn '"   ++ myDzenFont ++ "'" ++
  206.                      " -fg '"   ++ colorFG    ++ "'" ++
  207.                      " -bg '"   ++ colorBG    ++ "' -e 'onstart=lower'"
  208.  
  209. -- define the bars
  210. myLeftBar   = makeDzen 0 0 leftBarWidth barHeight "l"
  211. myRightBar  = "conky -c " ++ conkyFile ++ " | " ++ makeDzen leftBarWidth 0 (monitorWidth - leftBarWidth) barHeight "r"
  212.  
  213. -- }}}
  214.  
  215. -- LogHook {{{
  216. myLogHook :: Handle -> X ()
  217. myLogHook h = (dynamicLogWithPP $ defaultPP
  218.   { ppCurrent         = dzenColor colorBG  colorFG2 . pad
  219.   , ppVisible         = dzenColor colorBG  colorFG2 . pad
  220.   , ppUrgent          = dzenColor colorBG  colorUrg . dzenStrip . pad
  221.   , ppLayout          = dzenFG    colorFG2 . myRename
  222.   , ppHidden          = dzenFG    colorFG2 . noScratchPad
  223.   , ppTitle           = shorten 100
  224.   , ppHiddenNoWindows = namedOnly
  225.   , ppSort            = getSortByXineramaRule
  226.   , ppExtras          = [myAllMail, myInMail]
  227.   , ppSep             = " "
  228.   , ppWsSep           = ""
  229.   , ppOutput          = hPutStrLn h
  230.   }) >> updatePointer (Relative 0.95 0.95)
  231.  
  232.   where
  233.  
  234.     -- thanks byorgey (this filters out NSP too)
  235.     namedOnly ws = if any (`elem` ws) ['a'..'z'] then pad ws else ""
  236.  
  237.     -- my own filter out scratchpad function
  238.     noScratchPad ws = if ws == "NSP" then "" else pad ws
  239.  
  240.     -- L needed for loggers
  241.     dzenFG  c = dzenColor  c ""
  242.     dzenFGL c = dzenColorL c ""
  243.  
  244.     myAllMail = wrapL "  Mail: " ""  . dzenFGL colorFG2 $ maildirNew myArchive
  245.     myInMail  = wrapL "["        "]" . dzenFGL colorFG2 $ maildirNew myInbox
  246.  
  247.     myArchive = "/home/patrick/Mail/GMail/archive" -- All Mail
  248.     myInbox   = "/home/patrick/Mail/GMail/INBOX"   -- Inbox
  249.  
  250.     myRename = (\x -> case x of
  251.                "Hinted ResizableTall"          -> "  / /-/  "
  252.                "Mirror Hinted ResizableTall"   -> "  /-,-/  "
  253.                "Hinted Tabbed Bottom Simplest" -> "  /.../  "
  254.                "Hinted TwoPane"                -> "  / / /  "
  255.                "Hinted Full"                   -> "  /   /  "
  256.                _                               -> "  " ++ x ++ "  "
  257.                ) . stripIM
  258.  
  259.     stripIM s = if "IM " `isPrefixOf` s then drop (length "IM ") s else s
  260.  
  261. -- }}}
  262.  
  263. -- My SpawnHook {{{
  264. --
  265. -- spawn an arbitrary command on urgent
  266. --
  267. data MySpawnHook = MySpawnHook String deriving (Read, Show)
  268.  
  269. instance UrgencyHook MySpawnHook where
  270.     urgencyHook (MySpawnHook s) w = spawn $ s
  271.  
  272. -- 'ding!' on urgent (gajim has fairly unnannoying sounds thankfully)
  273. myUrgencyHook = MySpawnHook "ossplay -q /usr/share/sounds/purple/receive.wav"
  274.  
  275. -- }}}
  276.  
  277. -- Key Bindings {{{
  278. --
  279. -- only those which override/change defaults
  280. --
  281. -- custom scripts at http://pbrisbin.com:8080/pages/scripts.html
  282. --
  283. myKeys = [
  284.          -- opening apps with Win
  285.           ("M1-t"                  , scratchPad              ) -- Spawn scratch pad terminal
  286.          , ("M1-m"                  , spawn myMail            ) -- Open mail client
  287.          , ("M1-b"                  , spawn myBrowser         ) -- Open web client
  288.          , ("M1-i"                  , spawn myIRC             ) -- Open/attach IRC client in screen
  289.          , ("M1-l"                  , spawn myLock            ) -- Alt-l to lock screen
  290.          , ("M1-r"                  , spawn myTorrents        ) -- Open/attach rtorrent in screen
  291.  
  292.  
  293.          -- extended workspace navigations
  294.          , ("M-`"                   , toggleWS                ) -- Switch to the most recently vewed ws
  295.          , ("M-<Backspace>"         , focusUrgent             ) -- Focus most recently urgent window
  296.          , ("M-S-<Backspace>"       , clearUrgents            ) -- Make urgents go away
  297.  
  298.          -- extended window movements
  299.          , ("M-o"                   , sendMessage MirrorShrink) -- Shink slave panes vertically
  300.          , ("M-i"                   , sendMessage MirrorExpand) -- Expand slave panes vertically
  301.  
  302.          -- custom restart/quit commands
  303.          , ("M-q"                   , spawn myRestart         ) -- Restart xmonad
  304.          ]
  305.  
  306.          where
  307.  
  308.            -- use myTerminal as the scratchPad terminal
  309.            scratchPad = scratchpadSpawnActionTerminal myTerminal
  310.  
  311.            -- my apps
  312.            myMail     = "claws"
  313.            myBrowser  = "firefox"
  314.            myLock     = "slock"
  315.  
  316.            -- see http://pbrisbin.com:8080/pages/screen_tricks.html
  317.            myIRC      = myScreen "irssi"
  318.            myTorrents = myScreen "rtorrent"
  319.  
  320.            myScreen s = myTerminal ++ " -title "                    ++ s
  321.                                    ++ " -e bash -cl \"SCREEN_CONF=" ++ s
  322.                                    ++ " screen -S "                 ++ s
  323.                                    ++ " -R -D "                     ++ s
  324.                                    ++ "\""
  325.  
  326.            -- see http://pbrisbin.com:8080 recent post 9
  327.            mPlay s    = "echo " ++ s ++ " > $HOME/.mplayer_fifo"
  328.  
  329.            -- kill all conky/dzen2 before executing default restart command
  330.            myRestart  = "for pid in `pgrep conky`; do kill -9 $pid; done && " ++
  331.                         "for pid in `pgrep dzen2`; do kill -9 $pid; done && " ++
  332.                         "xmonad --recompile && xmonad --restart"
  333.  
  334. -- }}}
  335.  
  336. -- vim:foldmethod=marker
  337.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement