Advertisement
Guest User

Untitled

a guest
Jan 19th, 2011
220
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Haskell 13.24 KB | None | 0 0
  1. -- Imports --------------------------------------------------------------------
  2.  
  3. -- Core
  4. import XMonad
  5. import qualified XMonad.StackSet as W
  6. import qualified Data.Map as M
  7. import System.Exit
  8. import Graphics.X11.Xlib
  9. import Graphics.X11.ExtraTypes.XF86
  10. import IO (Handle, hPutStrLn)
  11. import XMonad.Actions.CycleWS (nextScreen,prevScreen)
  12. import Data.List
  13.  
  14. -- Prompts
  15. import XMonad.Prompt
  16. import XMonad.Prompt.Shell
  17.  
  18. -- Actions
  19. import XMonad.Actions.MouseGestures
  20. import XMonad.Actions.UpdatePointer
  21. import XMonad.Actions.GridSelect
  22.  
  23. -- Utils
  24. import XMonad.Util.Run (spawnPipe)
  25. import XMonad.Util.Loggers
  26. import XMonad.Util.EZConfig
  27. -- Hooks
  28. import XMonad.Hooks.ManageDocks
  29. import XMonad.Hooks.DynamicLog
  30. import XMonad.Hooks.UrgencyHook
  31. import XMonad.Hooks.Place
  32.  
  33. -- Layouts
  34. import XMonad.Layout.NoBorders
  35. import XMonad.Layout.ResizableTile
  36. import XMonad.Layout.Tabbed
  37. import XMonad.Layout.DragPane
  38. import XMonad.Layout.LayoutCombinators hiding ((|||))
  39. import XMonad.Layout.DecorationMadness
  40. import XMonad.Layout.TabBarDecoration
  41. import XMonad.Layout.IM
  42. import XMonad.Layout.Grid
  43. import XMonad.Layout.PerWorkspace
  44. import XMonad.Layout.Reflect
  45. import XMonad.Layout.DwmStyle
  46. import Data.Ratio ((%))
  47. import XMonad.Layout.ToggleLayouts
  48. import XMonad.Layout.Spacing
  49. import XMonad.Hooks.ManageHelpers
  50.  
  51.  
  52.  
  53.  
  54. -- Main -----------------------------------------------------------------------
  55.  
  56. main = do
  57.        h <- spawnPipe myStatusBar
  58.        xmonad $ withUrgencyHook NoUrgencyHook defaultConfig
  59.               { workspaces = workspaces'
  60.              , modMask = modMask'
  61.               , borderWidth = borderWidth'
  62.              , normalBorderColor = normalBorderColor'
  63.               , focusedBorderColor = focusedBorderColor'
  64.              , terminal = terminal'
  65.               , keys = keys'
  66.              , logHook = logHook' h
  67.               , layoutHook = layoutHook'
  68.              , manageHook = manageHook defaultConfig <+> manageHook'
  69.               }
  70.  
  71. -- Hooks ----------------------------------------------------------------------
  72.  
  73. -- Managehook
  74. manageHook' :: ManageHook
  75. manageHook' = composeAll . concat $
  76.     [ [className =? c --> doFloat                                 | c <- myFloats]
  77.     , [title     =? t --> doFloat                                 | t <- myOtherFloats]
  78.     , [title     =? t --> doIgnore                                | t <- myIgnores]
  79.     , [className =? c --> doF (W.shift (workspaces' !! 1))        | c <- webApps]
  80.    , [className =? c --> doF (W.shift (workspaces' !! 4))        | c <- graApps]
  81.     , [className =? c --> doF (W.shift (workspaces' !! 3))        | c <- docApps]
  82.    , [title     =? t --> (placeHook muttPlacement <+> doFloat)   | t <- placeMutt]
  83.    , [title     =? t --> (placeHook calPlacement <+> doFloat)    | t <- placeCal]
  84.     , [manageDocks ]
  85.     ]
  86.    where
  87.    myFloats       = ["feh", "file-roller", "File-roller", "MPlayer", "Gnome-calculator" ]
  88.    myOtherFloats  = ["alsamixer", "file-roller", "Gran Paradiso Preferences", "New Layer", "Color Balance", "Hue-Saturation" ]
  89.    myIgnores      = [""]
  90.    webApps        = ["Firefox", "Chrome", "Chromium", "Vimperator"]
  91.    graApps        = ["gimp-2.6", "Gimp-2.6", "GIMP", "gimp"]
  92.    docApps        = ["evince", "Evince", "Apvlv"]
  93.    placeMutt      = ["mailbox"]
  94.    placeCal       = ["cc-calendar"]
  95.  
  96. -- Placehook for mutt and calcurse (executed from dzen bar)
  97. muttPlacement = withGaps (0,0,20,0) (fixed (1,1))
  98. calPlacement  = withGaps (20,0,0,0) (fixed (1,0))
  99.  
  100. -- Loghook
  101. logHook' :: Handle ->  X ()
  102. logHook' h = dynamicLogWithPP $ customPP { ppOutput = hPutStrLn h }
  103.  
  104.  
  105. -- Layouthook
  106. layoutHook' = customLayout
  107.  
  108. -- Looks ----------------------------------------------------------------------
  109.  
  110. -- dzen2 settings --
  111. myStatusBar = "/usr/bin/dzen2 -ta l -h 20 -w 500 -fn '-*-droid sans mono-medium-r-*-*-12-*-*-*-*-*-*-*' -e '' "
  112.  
  113. -- XMonad dzen2 bar
  114. customPP :: PP
  115. customPP = defaultPP { ppCurrent = dzenColor "#B8BCB8" "#990000" . pad
  116.                      , ppHidden = dzenColor "#B8BCB8" "#484C48" . pad
  117.                      , ppTitle = dzenColor "#C4C4C4" "" . shorten 120
  118.                      , ppLayout = dzenColor "#990000" "" .
  119.                         (\ x -> fill (case x of
  120.                             "ResizableTall"                         -> icon "tall.xbm"
  121.                             "Mirror ResizableTall"                  -> icon "mtall.xbm"
  122.                             "Full"                                  -> icon "full.xbm"
  123.                             "IM Grid"                               -> icon "mail.xbm"
  124.                             "IM ReflectX IM Full"                   -> icon "scorpio.xbm"
  125.                             "TabBar Tall"                           -> icon "info_01.xbm"
  126.                             "Tabbed Bottom Simplest"                -> icon "info_02.xbm"
  127.                             "ReflectX IM Tabbed Bottom Simplest"    -> icon "scorpio.xbm"
  128.                             "ReflectX IM Mirror ResizableTall"      -> icon "info_01.xbm"
  129.                             "DefaultDecoration Tall"                -> icon "info_02.xbm"
  130.                             _                                       -> pad x) 4)
  131.                      , ppWsSep = ""
  132.                      , ppHiddenNoWindows = dzenColor "#616161" "" . pad
  133.                      , ppUrgent = dzenColor "#616161" "#D4D455" . dzenDontStripMyIcons
  134.                      }
  135.                      where
  136.                      icon h = "^i(/home/sphadnis/.xmonad/icons/" ++ h ++ ")"
  137.                      fill :: String -> Int -> String
  138.                      fill h i ="^p(" ++ show i ++ ")" ++ h ++ "^p(" ++ show i ++")"
  139.  
  140.  
  141. -- Use this instead of dzenStrip for icons to work with urgencyhook, also makes urgent workspace clickable
  142. dzenDontStripMyIcons :: String -> String
  143. dzenDontStripMyIcons = strip [] where
  144.     strip keep x
  145.       | null x                  = keep
  146.       | "^i" `isPrefixOf`     x = strip (keep ++"^") (drop 1 x)
  147.       | "^ca" `isPrefixOf`    x = strip (keep ++"^") (drop 1 x)
  148.       | '^' == head x           = strip keep (drop 1 . dropWhile (/= ')') $ x)
  149.       | otherwise               = let (good,x') = span (/= '^') x
  150.                                        in strip (keep ++ good) x'
  151.  
  152.  
  153. -- XPConfig
  154. myXPConfig = defaultXPConfig   { bgColor = "#101010"
  155.                                , fgColor = "#990000"
  156.                                , bgHLight = "#990000"
  157.                                , fgHLight = "#B8BCB8"
  158.                                , borderColor = "#990000"
  159.                                , promptBorderWidth = 0
  160.                                , position = Bottom
  161.                                , height = 25
  162.                                , font = "-*-droid sans mono-medium-r-*-*-12-*-*-*-*-*-*-*"
  163. --                               , showCompletionOnTab = True
  164.                                }
  165.  
  166.  
  167.  
  168. -- TabConfig
  169. myTabConfig = defaultTheme { inactiveBorderColor = "#303030"
  170.                            , activeBorderColor = "#303030"
  171.                            , activeColor = "#990000"
  172.                            , inactiveColor = "#990000"
  173.                            , activeTextColor = "#FFFFFF"
  174.                            , inactiveTextColor = "#C4C4C4"
  175.                            , decoHeight = 16
  176.                            }
  177.  
  178. -- Grid Select Config
  179. myGSConfig = defaultGSConfig { gs_cellheight = 30
  180.                              , gs_cellwidth = 100
  181.                              , gs_cellpadding = 0
  182.                              }  
  183.  
  184. -- Borders
  185. borderWidth' :: Dimension
  186. borderWidth' = 1
  187.  
  188. normalBorderColor', focusedBorderColor' :: String
  189. normalBorderColor'  = "#000000"
  190. focusedBorderColor' = "#990000"
  191.  
  192. -- Workspaces
  193. workspaces' :: [WorkspaceId]
  194. workspaces' = clickable $ ["^i(/home/sphadnis/.xmonad/icons/screen.xbm):main", -- 0
  195.                            "^i(/home/sphadnis/.xmonad/icons/fox.xbm):web", -- 1
  196.                            "^i(/home/sphadnis/.xmonad/icons/dev.xbm):dev", -- 2
  197.                            "^i(/home/sphadnis/.xmonad/icons/book.xbm):lib", -- 3
  198.                            "^i(/home/sphadnis/.xmonad/icons/mouse_01.xbm):mail", -- 4
  199.                            "^i(/home/sphadnis/.xmonad/icons/cpu.xbm):vm", -- 5
  200.                            "^i(/home/sphadnis/.xmonad/icons/info_03.xbm):sys" --6
  201.                           ]
  202.  
  203.               where clickable l = [ "^ca(1,xdotool key super+" ++ show (n) ++ ")" ++ ws ++ "^ca()" |
  204.                                     (i,ws) <- zip [1..] l,
  205.                                     let n = if i == 10 then 0 else i ]
  206.  
  207.  
  208.  
  209. -- Layouts --------------------------------------------------------------------
  210.  
  211. customLayout = avoidStruts . smartBorders. toggleLayouts Full $
  212.  
  213.     -- Layout for Workspaces
  214.     onWorkspace (workspaces' !! 4) (gimp ||| gimpg) $
  215.  
  216.    -- Default layout
  217.    tiled ||| spaced ||| (Mirror tiled) ||| tallDefault shrinkText myTabConfig ||| Full
  218.  
  219.  where
  220.    tiled   = ResizableTall 1 (2/100) (1/2) []
  221.    gimpTab = tabbedBottomAlways shrinkText myTabConfig
  222.    gimpg   = reflectHoriz $
  223.              withIM (0.18) (Role "gimp-toolbox") (Mirror tiled)
  224.    gimp    = reflectHoriz $
  225.              withIM (0.18) (Role "gimp-toolbox") gimpTab
  226.    spaced  = spacing 2 $ ResizableTall 1 (3/100) (1/2) []
  227.  
  228.  
  229. -------------------------------------------------------------------------------
  230. -- Terminal --
  231. terminal' :: String
  232. terminal' = "urxvtr"
  233.  
  234. -------------------------------------------------------------------------------
  235. -- Keys/Button bindings --
  236. -- modmask
  237. modMask' :: KeyMask
  238. modMask' = mod4Mask
  239.  
  240. -- keys
  241. keys' :: XConfig Layout -> M.Map (KeyMask, KeySym) (X ())
  242. keys' conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
  243.    -- launching and killing programs
  244.    [ ((modMask,               xK_Return), spawn $ XMonad.terminal conf)
  245.    , ((modMask .|. shiftMask, xK_c     ), kill)
  246.    , ((modMask,               xK_F1    ), spawn "firefox")
  247.    , ((modMask,               xK_F2    ), spawn "thunderbird")
  248.    , ((modMask,               xK_F4    ), spawn "thunar")
  249.    , ((modMask,               xK_F12   ), spawn "gnome-calculator")
  250.    , ((modMask,               xK_F3    ), spawn (terminal'++" -e htop"))
  251.     , ((modMask,               xK_F9    ), spawn "scrot")
  252.  
  253.     -- layouts
  254.     , ((modMask,               xK_space ), sendMessage NextLayout)
  255.     , ((modMask .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
  256.     , ((modMask,               xK_b     ), sendMessage ToggleStruts)
  257.  
  258.     -- floating layer stuff
  259.     , ((modMask,               xK_t     ), withFocused $ windows . W.sink)
  260.  
  261.     -- refresh
  262.     , ((modMask,               xK_n     ), refresh)
  263.  
  264.     -- focus
  265.     , ((modMask,               xK_Right ), windows W.focusDown)
  266.     , ((modMask,               xK_Left  ), windows W.focusUp)
  267.     , ((modMask,               xK_Tab   ), windows W.focusDown)
  268.     , ((modMask .|. shiftMask, xK_Tab   ), windows W.focusUp)
  269.     , ((modMask,               xK_j     ), windows W.focusDown)
  270.     , ((modMask,               xK_k     ), windows W.focusUp)
  271.     , ((modMask,               xK_m     ), windows W.focusMaster)
  272.  
  273.     -- workspaces
  274.     , ((modMask .|. controlMask, xK_Right), nextScreen)
  275.     , ((modMask .|. controlMask, xK_Left ), prevScreen)
  276.  
  277.     -- swapping
  278.     , ((modMask .|. shiftMask, xK_Return), windows W.swapMaster)
  279.     , ((modMask .|. shiftMask, xK_j     ), windows W.swapDown  )
  280.     , ((modMask .|. shiftMask, xK_k     ), windows W.swapUp    )
  281.  
  282.     -- increase or decrease number of windows in the master area
  283.     , ((modMask              , xK_comma ), sendMessage (IncMasterN 1))
  284.     , ((modMask              , xK_period), sendMessage (IncMasterN (-1)))
  285.  
  286.     -- resizing
  287.     , ((modMask,               xK_h     ), sendMessage Shrink)
  288.     , ((modMask,               xK_l     ), sendMessage Expand)
  289.     , ((modMask .|. shiftMask, xK_h     ), sendMessage MirrorShrink)
  290.     , ((modMask .|. shiftMask, xK_l     ), sendMessage MirrorExpand)
  291.     , ((modMask,               xK_f     ), sendMessage ToggleStruts >> sendMessage ToggleLayout)
  292.  
  293.     -- volume management
  294.     , ((0,               xF86XK_AudioRaiseVolume       ), spawn "amixer set Master 5+")
  295.     , ((0,               xF86XK_AudioLowerVolume  ), spawn "amixer set Master 5-")
  296.     , ((0,               xF86XK_AudioMute  ), spawn "amixer set Master toggle")
  297.  
  298.     -- moc controls
  299.     , ((modMask,               xK_KP_Right     ), spawn "mpc next")
  300.     , ((modMask,               xK_KP_Left      ), spawn "mpc prev")
  301.     , ((modMask,               xK_KP_Insert    ), spawn "mpc toggle")
  302.     , ((modMask,               xK_KP_Delete    ), spawn "mpc stop")
  303.  
  304.     -- prompts
  305.     , ((modMask,  xK_p                  ), shellPrompt myXPConfig)
  306.  
  307.     -- GridSelect
  308.     , ((modMask,  xK_g                  ), goToSelected myGSConfig)
  309.  
  310.     -- lock, quit, or restart
  311.     , ((modMask .|. shiftMask, xK_x     ), spawn "slock")
  312.     , ((modMask .|. shiftMask, xK_q     ), io (exitWith ExitSuccess))
  313.     , ((modMask              , xK_q     ), restart "xmonad" True)
  314.     ]
  315.     ++
  316.     -- mod-[1..9] %! Switch to workspace N
  317.     -- mod-shift-[1..9] %! Move client to workspace N
  318.     [((m .|. modMask, k), windows $ f i)
  319.         | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
  320.         , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
  321. -------------------------------------------------------------------------------
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement