Advertisement
Guest User

xmonad.hs - 3 displays

a guest
Dec 4th, 2011
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import XMonad
  2. import qualified XMonad.StackSet as S
  3.  
  4. import XMonad.Layout.IM
  5. import XMonad.Layout.Reflect             (reflectHoriz)
  6. import XMonad.Layout.NoBorders           (smartBorders)
  7. import XMonad.Layout.Decoration
  8. import XMonad.Layout.PerWorkspace        (onWorkspace)
  9. import XMonad.Layout.NoFrillsDecoration
  10. import XMonad.Layout.IndependentScreens
  11.  
  12. import XMonad.Hooks.ManageDocks
  13. import XMonad.Hooks.DynamicLog    hiding (xmobar)
  14. import XMonad.Hooks.SetWMName            (setWMName)
  15. import XMonad.Hooks.UrgencyHook
  16. import XMonad.Hooks.ManageHelpers
  17.  
  18. import XMonad.Util.Run
  19. import XMonad.Util.Loggers
  20. import XMonad.Util.EZConfig              (additionalKeys)
  21. import XMonad.Util.NamedWindows          (getName)
  22.  
  23. import System.Exit
  24. import System.IO
  25.  
  26. import Data.Ord                          (comparing)
  27. import Data.List                         (intercalate, sortBy, isInfixOf)
  28. import Data.Maybe                        (isJust, catMaybes)
  29. import Data.Ratio                        ((%))
  30. import Data.Monoid                       (All(All), mappend, mempty)
  31.  
  32. import Codec.Binary.UTF8.String          (encodeString)
  33. import Control.Monad                     (when, zipWithM_, liftM2)
  34.  
  35. import qualified Data.Map as M
  36.  
  37. main = do
  38.         xmobar0 <- xmobar 0 "/home/sembiance/.xmobarrc-center"
  39.         xmobar1 <- xmobar 1 "/home/sembiance/.xmobarrc-left"
  40.         xmobar2 <- xmobar 2 "/home/sembiance/.xmobarrc-right"
  41.         xmonad $ defaultConfig {
  42.  
  43.         terminal           = "urxvt",
  44.         focusFollowsMouse  = True,
  45.         borderWidth        = 1,
  46.         modMask            = mod1Mask,
  47.         numlockMask        = mod2Mask,
  48.         workspaces         = withScreens 3 ["1","2","3","4","5","6","7","8","9","0"],
  49.         normalBorderColor  = "#dddddd",
  50.         focusedBorderColor = "#ff0000",
  51.  
  52.         keys               = myKeys,
  53.         mouseBindings      = myMouseBindings,
  54.  
  55.         layoutHook         = myLayout,
  56.         manageHook         = myManageHook,
  57.         handleEventHook    = mempty,
  58.         logHook            = myLogHook [ pp { ppOutput = hPutStrLn xmobar0 }
  59.                                        , pp { ppOutput = hPutStrLn xmobar1 }
  60.                                        , pp { ppOutput = hPutStrLn xmobar2 }
  61.                                        ],
  62.         startupHook        = return ()
  63.     }
  64.  
  65. ------------------------------------------------------------------------
  66. -- Key bindings. Add, modify or remove key bindings here.
  67. --
  68. myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
  69.  
  70.     -- launch a terminal
  71.     [ ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)
  72.    
  73.     -- launch dmenu
  74.     , ((modm,               xK_p     ), spawn "exe=`dmenu_run` && eval \"exec $exe\"")
  75.  
  76.     -- close focused window
  77.     , ((modm .|. shiftMask, xK_c     ), kill)
  78.  
  79.      -- Rotate through the available layout algorithms
  80.     , ((modm,               xK_space ), sendMessage NextLayout)
  81.  
  82.     --  Reset the layouts on the current workspace to default
  83.     , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
  84.  
  85.     -- Move focus to the next window
  86.     , ((modm,               xK_Tab   ), windows S.focusDown)
  87.  
  88.     -- Push window back into tiling
  89.     , ((modm,               xK_t     ), withFocused $ windows . S.sink)
  90.  
  91.     -- Toggle the status bar gap
  92.     -- Use this binding with avoidStruts from Hooks.ManageDocks.
  93.     -- See also the statusBar function from Hooks.DynamicLog.
  94.     --
  95.     -- , ((modm              , xK_b     ), sendMessage ToggleStruts)
  96.  
  97.     -- Quit xmonad
  98.     , ((modm .|. shiftMask, xK_q     ), io (exitWith ExitSuccess))
  99.  
  100.     -- Restart xmonad
  101.     , ((modm              , xK_q     ), spawn "xmonad --recompile; xmonad --restart")
  102.     ]
  103.     ++
  104.  
  105.     --
  106.     -- mod-[1..9], Switch to workspace N
  107.     -- mod-shift-[1..9], Move client to workspace N
  108.     --
  109.     [((m .|. modm, k), windows $ onCurrentScreen f i)
  110.         | (i, k) <- zip (workspaces' conf) [xK_1, xK_2, xK_3, xK_4, xK_5, xK_6, xK_7, xK_8, xK_9, xK_0]
  111.        , (f, m) <- [(S.view, 0), (S.shift, shiftMask)]]
  112.    ++
  113.  
  114.    --
  115.    -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
  116.    -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
  117.    --
  118.    [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
  119.        | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
  120.        , (f, m) <- [(S.view, 0), (S.shift, shiftMask)]]
  121.  
  122.  
  123. ------------------------------------------------------------------------
  124. -- Mouse bindings: default actions bound to mouse events
  125. --
  126. myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
  127.  
  128.    -- mod-button1, Set the window to floating mode and move by dragging
  129.    [ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
  130.                                       >> windows S.shiftMaster))
  131.  
  132.    -- mod-button2, Raise the window to the top of the stack
  133.    , ((modm, button2), (\w -> focus w >> windows S.shiftMaster))
  134.  
  135.    -- mod-button3, Set the window to floating mode and resize by dragging
  136.    , ((modm, button3), (\w -> focus w >> mouseResizeWindow w
  137.                                       >> windows S.shiftMaster))
  138.  
  139.    -- you may also bind events to the mouse scroll wheel (button4 and button5)
  140.    ]
  141.  
  142. myLayout = avoidStruts $ tiled ||| Mirror tiled ||| Full
  143.  where
  144.     -- default tiling algorithm partitions the screen into two panes
  145.     tiled   = Tall nmaster delta ratio
  146.  
  147.     -- The default number of windows in the master pane
  148.     nmaster = 1
  149.  
  150.     -- Default proportion of screen occupied by master pane
  151.     ratio   = 1/2
  152.  
  153.     -- Percent of screen to increment by when resizing panes
  154.     delta   = 3/100
  155.  
  156. ------------------------------------------------------------------------
  157. -- Window rules:
  158.  
  159. -- Execute arbitrary actions and WindowSet manipulations when managing
  160. -- a new window. You can use this to, for example, always float a
  161. -- particular program, or have a client always appear on a particular
  162. -- workspace.
  163. --
  164. -- To find the property name associated with a program, use
  165. -- > xprop | grep WM_CLASS
  166. -- and click on the client you're interested in.
  167. --
  168. -- To match on the WM_NAME, you can use 'title' in the same way that
  169. -- 'className' and 'resource' are used below.
  170. --
  171. myManageHook = composeAll $
  172.     [ className =? "MPlayer"        --> doFloat
  173.     , className =? "Gimp"           --> doFloat
  174.     , className =? "Pidgin"         --> doFloat
  175.     , resource  =? "desktop_window" --> doIgnore
  176.     , resource  =? "kdesktop"       --> doIgnore ]
  177.     ++[ manageDocks <+> manageHook defaultConfig ]
  178.  
  179.  
  180. xmobar screen file = spawnPipe . unwords $ options
  181.     where options = [ "xmobar"
  182.                     , "-x"
  183.                     , show screen
  184.                     , wrap "'" "'" file
  185.                     ]
  186.  
  187. currentScreenID :: X Int
  188. currentScreenID = (fromIntegral . S.screen . S.current) `fmap` gets windowset
  189.  
  190. pp = xmobarPP
  191.     { ppCurrent = xmobarColor "yellow" ""
  192.     , ppHidden = xmobarColor "cyan" ""
  193.     , ppHiddenNoWindows = xmobarColor "blue" ""
  194.     , ppUrgent = xmobarColor "black" "red"
  195.     , ppSep = "  "
  196.     , ppLayout = xmobarColor "black" "" . shorten 1
  197.     , ppTitle = xmobarColor "magenta" ""
  198.     }
  199.  
  200.  
  201. myLogHook pps = do
  202.     screens <- (sortBy (comparing S.screen) . S.screens) `fmap` gets windowset
  203.     zipWithM_ dynamicLogWithPP' screens pps
  204.  
  205. focusedWindow = maybe Nothing (return . S.focus) . S.stack . S.workspace
  206.  
  207. dynamicLogWithPP' screen pp = dynamicLogString' screen pp >>= io . ppOutput pp
  208.  
  209. dynamicLogString' screen pp = do
  210.  
  211.   winset <- gets windowset
  212.   urgents <- readUrgents
  213.   sort' <- ppSort pp
  214.  
  215.  -- layout description
  216.  let ld = description . S.layout . S.workspace $ screen
  217.  
  218.  -- workspace list
  219.  let ws = pprWindowSet' screen sort' urgents pp winset
  220.  
  221.  -- window title
  222.  wt <- maybe (return "") (fmap show . getName) $ focusedWindow screen
  223.  
  224.  -- run extra loggers, ignoring any that generate errors.
  225.  extras <- mapM (`catchX` return Nothing) $ ppExtras pp
  226.  
  227.  return $ encodeString . sepBy (ppSep pp) . ppOrder pp $
  228.             [ ws
  229.             , ppLayout pp ld
  230.             , ppTitle  pp wt
  231.             ]
  232.             ++ catMaybes extras
  233.  
  234. pprWindowSet' screen sort' urgents pp s = sepBy (ppWsSep pp) . map fmt . sort' $ [ w | w <- S.workspaces s, (fst $ unmarshall (S.tag w)) == S.screen screen ]
  235.     where this     = S.tag . S.workspace $ screen
  236.           visibles = map (S.tag . S.workspace) (S.current s : S.visible s)
  237.  
  238.           fmt w = printer pp (snd . unmarshall $ S.tag w)
  239.               where printer | S.tag w == this                                               = ppCurrent
  240.                             | S.tag w `elem` visibles                                       = ppVisible
  241.                             | any (\x -> maybe False (== S.tag w) (S.findTag x s)) urgents  = \ppC -> ppUrgent ppC . ppHidden ppC
  242.                             | isJust (S.stack w)                                            = ppHidden
  243.                             | otherwise                                                     = ppHiddenNoWindows
  244.  
  245. sepBy :: String -> [String] -> String
  246. sepBy sep = intercalate sep . filter (not . null)
  247.  
  248.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement