Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import XMonad
- import qualified XMonad.StackSet as S
- import XMonad.Layout.IM
- import XMonad.Layout.Reflect (reflectHoriz)
- import XMonad.Layout.NoBorders (smartBorders)
- import XMonad.Layout.Decoration
- import XMonad.Layout.PerWorkspace (onWorkspace)
- import XMonad.Layout.NoFrillsDecoration
- import XMonad.Layout.IndependentScreens
- import XMonad.Hooks.ManageDocks
- import XMonad.Hooks.DynamicLog hiding (xmobar)
- import XMonad.Hooks.SetWMName (setWMName)
- import XMonad.Hooks.UrgencyHook
- import XMonad.Hooks.ManageHelpers
- import XMonad.Util.Run
- import XMonad.Util.Loggers
- import XMonad.Util.EZConfig (additionalKeys)
- import XMonad.Util.NamedWindows (getName)
- import System.Exit
- import System.IO
- import Data.Ord (comparing)
- import Data.List (intercalate, sortBy, isInfixOf)
- import Data.Maybe (isJust, catMaybes)
- import Data.Ratio ((%))
- import Data.Monoid (All(All), mappend, mempty)
- import Codec.Binary.UTF8.String (encodeString)
- import Control.Monad (when, zipWithM_, liftM2)
- import qualified Data.Map as M
- main = do
- xmobar0 <- xmobar 0 "/home/sembiance/.xmobarrc-center"
- xmobar1 <- xmobar 1 "/home/sembiance/.xmobarrc-left"
- xmobar2 <- xmobar 2 "/home/sembiance/.xmobarrc-right"
- xmonad $ defaultConfig {
- terminal = "urxvt",
- focusFollowsMouse = True,
- borderWidth = 1,
- modMask = mod1Mask,
- numlockMask = mod2Mask,
- workspaces = withScreens 3 ["1","2","3","4","5","6","7","8","9","0"],
- normalBorderColor = "#dddddd",
- focusedBorderColor = "#ff0000",
- keys = myKeys,
- mouseBindings = myMouseBindings,
- layoutHook = myLayout,
- manageHook = myManageHook,
- handleEventHook = mempty,
- logHook = myLogHook [ pp { ppOutput = hPutStrLn xmobar0 }
- , pp { ppOutput = hPutStrLn xmobar1 }
- , pp { ppOutput = hPutStrLn xmobar2 }
- ],
- startupHook = return ()
- }
- ------------------------------------------------------------------------
- -- Key bindings. Add, modify or remove key bindings here.
- --
- myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
- -- launch a terminal
- [ ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)
- -- launch dmenu
- , ((modm, xK_p ), spawn "exe=`dmenu_run` && eval \"exec $exe\"")
- -- close focused window
- , ((modm .|. shiftMask, xK_c ), kill)
- -- Rotate through the available layout algorithms
- , ((modm, xK_space ), sendMessage NextLayout)
- -- Reset the layouts on the current workspace to default
- , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
- -- Move focus to the next window
- , ((modm, xK_Tab ), windows S.focusDown)
- -- Push window back into tiling
- , ((modm, xK_t ), withFocused $ windows . S.sink)
- -- Toggle the status bar gap
- -- Use this binding with avoidStruts from Hooks.ManageDocks.
- -- See also the statusBar function from Hooks.DynamicLog.
- --
- -- , ((modm , xK_b ), sendMessage ToggleStruts)
- -- Quit xmonad
- , ((modm .|. shiftMask, xK_q ), io (exitWith ExitSuccess))
- -- Restart xmonad
- , ((modm , xK_q ), spawn "xmonad --recompile; xmonad --restart")
- ]
- ++
- --
- -- mod-[1..9], Switch to workspace N
- -- mod-shift-[1..9], Move client to workspace N
- --
- [((m .|. modm, k), windows $ onCurrentScreen f i)
- | (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]
- , (f, m) <- [(S.view, 0), (S.shift, shiftMask)]]
- ++
- --
- -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
- -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
- --
- [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
- | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
- , (f, m) <- [(S.view, 0), (S.shift, shiftMask)]]
- ------------------------------------------------------------------------
- -- Mouse bindings: default actions bound to mouse events
- --
- myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
- -- mod-button1, Set the window to floating mode and move by dragging
- [ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
- >> windows S.shiftMaster))
- -- mod-button2, Raise the window to the top of the stack
- , ((modm, button2), (\w -> focus w >> windows S.shiftMaster))
- -- mod-button3, Set the window to floating mode and resize by dragging
- , ((modm, button3), (\w -> focus w >> mouseResizeWindow w
- >> windows S.shiftMaster))
- -- you may also bind events to the mouse scroll wheel (button4 and button5)
- ]
- myLayout = avoidStruts $ tiled ||| Mirror tiled ||| Full
- where
- -- default tiling algorithm partitions the screen into two panes
- tiled = Tall nmaster delta ratio
- -- The default number of windows in the master pane
- nmaster = 1
- -- Default proportion of screen occupied by master pane
- ratio = 1/2
- -- Percent of screen to increment by when resizing panes
- delta = 3/100
- ------------------------------------------------------------------------
- -- Window rules:
- -- Execute arbitrary actions and WindowSet manipulations when managing
- -- a new window. You can use this to, for example, always float a
- -- particular program, or have a client always appear on a particular
- -- workspace.
- --
- -- To find the property name associated with a program, use
- -- > xprop | grep WM_CLASS
- -- and click on the client you're interested in.
- --
- -- To match on the WM_NAME, you can use 'title' in the same way that
- -- 'className' and 'resource' are used below.
- --
- myManageHook = composeAll $
- [ className =? "MPlayer" --> doFloat
- , className =? "Gimp" --> doFloat
- , className =? "Pidgin" --> doFloat
- , resource =? "desktop_window" --> doIgnore
- , resource =? "kdesktop" --> doIgnore ]
- ++[ manageDocks <+> manageHook defaultConfig ]
- xmobar screen file = spawnPipe . unwords $ options
- where options = [ "xmobar"
- , "-x"
- , show screen
- , wrap "'" "'" file
- ]
- currentScreenID :: X Int
- currentScreenID = (fromIntegral . S.screen . S.current) `fmap` gets windowset
- pp = xmobarPP
- { ppCurrent = xmobarColor "yellow" ""
- , ppHidden = xmobarColor "cyan" ""
- , ppHiddenNoWindows = xmobarColor "blue" ""
- , ppUrgent = xmobarColor "black" "red"
- , ppSep = " "
- , ppLayout = xmobarColor "black" "" . shorten 1
- , ppTitle = xmobarColor "magenta" ""
- }
- myLogHook pps = do
- screens <- (sortBy (comparing S.screen) . S.screens) `fmap` gets windowset
- zipWithM_ dynamicLogWithPP' screens pps
- focusedWindow = maybe Nothing (return . S.focus) . S.stack . S.workspace
- dynamicLogWithPP' screen pp = dynamicLogString' screen pp >>= io . ppOutput pp
- dynamicLogString' screen pp = do
- winset <- gets windowset
- urgents <- readUrgents
- sort' <- ppSort pp
- -- layout description
- let ld = description . S.layout . S.workspace $ screen
- -- workspace list
- let ws = pprWindowSet' screen sort' urgents pp winset
- -- window title
- wt <- maybe (return "") (fmap show . getName) $ focusedWindow screen
- -- run extra loggers, ignoring any that generate errors.
- extras <- mapM (`catchX` return Nothing) $ ppExtras pp
- return $ encodeString . sepBy (ppSep pp) . ppOrder pp $
- [ ws
- , ppLayout pp ld
- , ppTitle pp wt
- ]
- ++ catMaybes extras
- 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 ]
- where this = S.tag . S.workspace $ screen
- visibles = map (S.tag . S.workspace) (S.current s : S.visible s)
- fmt w = printer pp (snd . unmarshall $ S.tag w)
- where printer | S.tag w == this = ppCurrent
- | S.tag w `elem` visibles = ppVisible
- | any (\x -> maybe False (== S.tag w) (S.findTag x s)) urgents = \ppC -> ppUrgent ppC . ppHidden ppC
- | isJust (S.stack w) = ppHidden
- | otherwise = ppHiddenNoWindows
- sepBy :: String -> [String] -> String
- sepBy sep = intercalate sep . filter (not . null)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement