Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --
- -- ~/.xmonad/xmonad.hs
- -- original by pbrisbin
- --
- -- 18 june 2010 (a few new actions)
- -- Imports {{{
- import XMonad hiding ( (|||) )
- import XMonad.Actions.CycleWS (toggleWS)
- import XMonad.Actions.FindEmptyWorkspace
- import XMonad.Actions.WithAll (killAll)
- import XMonad.Actions.UpdatePointer
- import XMonad.Actions.GridSelect
- import XMonad.Hooks.DynamicLog
- import XMonad.Hooks.EwmhDesktops (ewmh)
- import XMonad.Hooks.ManageHelpers
- import XMonad.Hooks.ManageDocks
- import XMonad.Hooks.UrgencyHook
- import XMonad.Hooks.SetWMName
- import XMonad.Layout.IM
- import XMonad.Layout.LayoutCombinators (JumpToLayout)
- import XMonad.Layout.LayoutHints (layoutHintsWithPlacement)
- import XMonad.Layout.LayoutCombinators
- import XMonad.Layout.NoBorders
- import XMonad.Layout.PerWorkspace (onWorkspace)
- import XMonad.Layout.ResizableTile
- import XMonad.Layout.Maximize
- import XMonad.Layout.Minimize
- import XMonad.Util.EZConfig (additionalKeysP)
- import XMonad.Util.Loggers (maildirNew,logCmd,dzenColorL,wrapL,shortenL)
- import XMonad.Util.NamedScratchpad
- import XMonad.Util.Run (spawnPipe)
- import XMonad.Util.WindowProperties (getProp32s)
- import XMonad.Util.WorkspaceCompare (getSortByXineramaRule)
- import Data.List
- import Data.Monoid
- import Data.Ratio
- import System.IO
- import qualified Data.Map as M
- import qualified XMonad.StackSet as W
- -- }}}
- -- Main {{{
- main = do
- d <- spawnPipe myLeftBar
- spawnList myStartupApps
- -- ewmh just makes wmctrl work
- xmonad $ ewmh $ withUrgencyHook myUrgencyHook $ defaultConfig
- { startupHook = setWMName "LG3D"
- , modMask = mod4Mask
- , terminal = myTerminal
- , workspaces = myWorkspaces
- , borderWidth = myBorderWidth
- , normalBorderColor = myNormalBorderColor
- , focusedBorderColor = myFocusedBorderColor
- , layoutHook = myLayout
- , manageHook = myManageHook
- , logHook = myLogHook d
- } `additionalKeysP` myKeys
- where
- spawnList :: [String] -> IO ()
- spawnList = mapM_ spawn
- -- apps to start along with xmonad
- myStartupApps = [myRightBar,"conky","qutim",myWicd]
- -- }}}
- -- Theme {{{
- myFont = "Verdana-8" -- xft-enabled dzen required (aur/dzen2-svn)
- conkyFile = "~/.dzen_conkyrc" -- populates right status bar via conky -c | dzen2
- colorBG = "#303030" -- background
- colorFG = "#606060" -- foreground
- colorFG2 = "#909090" -- foreground w/ emphasis
- colorFG3 = "#c4df90" -- foreground w/ strong emphasis
- colorUrg = "#cc896d" -- urgent, peach
- colorUrg2 = "#c4df90" -- urgent, lime
- barHeight = 17
- monitorWidth = 1920 -- two statusbars will span this width
- leftBarWidth = 800 -- right bar will span difference
- -- }}}
- -- Options {{{
- --
- -- if you change workspace names, be sure to update them throughout
- --
- myTerminal = "urxvtc"
- myWorkspaces = ["1-main","2-web","3-chat"] ++ map show [4..9]
- myNormalBorderColor = colorFG
- myFocusedBorderColor = colorUrg
- myBorderWidth = 1
- -- }}}
- -- Layouts {{{
- --
- -- see http://pbrisbin.com:8080/pages/im-layout.html
- --
- myLayout = avoidStruts $ onWorkspace "3-chat" imLayout $ maximize $ minimize $ standardLayouts
- where
- standardLayouts = tiled ||| Mirror tiled ||| full
- -- im roster on left tenth, standardLayouts in other nine tenths
- imLayout = withIM (1/10) imProp standardLayouts
- -- WMROLE = "roster" is Gajim.py's buddy list
- imProp = Role "roster"
- tiled = hinted $ ResizableTall nmaster delta ratio []
- full = hinted $ noBorders Full
- -- like hintedTile but for any layout l
- hinted l = layoutHintsWithPlacement (0,0) l
- nmaster = 1
- delta = 3/100
- ratio = toRational $ 2/(1 + sqrt 5 :: Double) -- golden ratio
- -- }}}
- -- ManageHook {{{
- myManageHook = (composeAll . concat $
- [ [resource =? r --> doIgnore | r <- myIgnores] -- ignore desktop
- , [className =? c --> doShift "2-web" | c <- myWebs ] -- move webs to web
- , [title =? t --> doShift "3-chat" | t <- myChats ] -- move chats to chat
- , [className =? c --> doShift "3-chat" | (c,_) <- myIMs ] -- move chats to chat
- , [className =? c <&&> role /=? r --> doFloat | (c,r) <- myIMs ] -- float all ims but roster
- , [className =? c --> doFloat | c <- myFloats ] -- float my floats
- , [className =? c --> doCenterFloat | c <- myCFloats] -- float my floats
- , [name =? n --> doFloat | n <- myNames ] -- float my names
- , [name =? n --> doCenterFloat | n <- myCNames ] -- float my names
- , [isFullscreen --> myDoFullFloat ]
- ]) <+> manageTypes <+> manageDocks <+> manageScratchPads
- where
- role = stringProperty "WM_WINDOW_ROLE"
- name = stringProperty "WM_NAME"
- -- [ ("class1","role1"), ("class2","role2"), ... ]
- myIMs = [("Qutim","roster")]
- -- titles
- myChats = ["irssi","mutt"]
- -- classnames
- myFloats = ["MPlayer","Smplayer","Zenity","Comix","VirtualBox","rdesktop"]
- myCFloats = ["Xmessage","Save As...","XFontSel"]
- myWebs = ["Firefox"] ++ -- firefox
- ["Chromium"] -- chrom(e|ium)
- -- resources
- myIgnores = ["desktop","desktop_window"]
- -- names
- myNames = ["Chromium Options"]
- myCNames = ["bashrun"]
- -- a trick for fullscreen but stil allow focusing of other WSs
- myDoFullFloat = doF W.focusDown <+> doFullFloat
- -- modified version of manageDocks
- manageTypes = checkType --> doCenterFloat
- where
- checkType :: Query Bool
- checkType = ask >>= \w -> liftX $ do
- m <- getAtom "_NET_WM_WINDOW_TYPE_MENU"
- d <- getAtom "_NET_WM_WINDOW_TYPE_DIALOG"
- u <- getAtom "_NET_WM_WINDOW_TYPE_UTILITY"
- mbr <- getProp32s "_NET_WM_WINDOW_TYPE" w
- case mbr of
- Just [r] -> return $ elem (fromIntegral r) [m,d,u]
- _ -> return False
- -- manage all my scratchpads based on the rules listed in the datatypes
- manageScratchPads = namedScratchpadManageHook myScratchPads
- -- }}}
- -- ScratchPads {{{
- myScratchPads = [ NS "mixer" spawnMixer findMixer manageMixer
- , NS "terminal" spawnTerm findTerm manageTerm
- ]
- where
- spawnMixer = myTerminal ++ " -e alsamixer"
- findMixer = className =? "alsamixer"
- manageMixer = customFloating $ W.RationalRect l t w h
- where
- h = 0.6 -- height, 60%
- w = 0.6 -- width, 60%
- t = (1 - h)/2 -- centered top/bottom
- l = (1 - w)/2 -- centered left/right
- spawnTerm = myTerminal ++ " -name scratchpad"
- findTerm = resource =? "scratchpad"
- manageTerm = customFloating $ W.RationalRect l t w h
- where
- h = 0.1 -- height, 10%
- w = 1 -- width, 100%
- t = 1 - h -- bottom edge
- l = (1 - w)/2 -- centered left/right
- -- }}}
- -- Status Bars {{{
- --
- -- see http://pbrisbin.com:8080/pages/xmonad_status.html
- --
- makeDzen :: Int -> Int -> Int -> Int -> String -> String
- makeDzen x y w h a = "dzen2 -p" ++
- " -ta " ++ a ++
- " -x " ++ show x ++
- " -y " ++ show y ++
- " -w " ++ show w ++
- " -h " ++ show h ++
- " -fn '" ++ myFont ++ "'" ++
- " -fg '" ++ colorFG ++ "'" ++
- " -bg '" ++ colorBG ++ "' -e 'onstart=lower'"
- -- define the bars
- myLeftBar = makeDzen 0 0 leftBarWidth barHeight "l"
- myRightBar = "conky -c " ++ conkyFile ++ " | " ++ makeDzen leftBarWidth 0 (monitorWidth - leftBarWidth) barHeight "r"
- -- kill instances of wicd-client and start a new one
- myWicd = "for pid in `pgrep wicd-client`; do kill -9 $pid; done && " ++
- "wicd-client"
- -- }}}
- -- LogHook {{{
- myLogHook :: Handle -> X ()
- myLogHook h = (dynamicLogWithPP $ defaultPP
- { ppCurrent = dzenFG colorUrg2 . pad
- , ppVisible = dzenFG colorFG2 . pad
- , ppUrgent = dzenFG colorUrg . pad . dzenStrip
- , ppLayout = dzenFG colorFG2 . myRename
- , ppHidden = dzenFG colorFG2 . noScratchPad
- , ppHiddenNoWindows = namedOnly
- , ppTitle = shorten 100
- , ppSort = getSortByXineramaRule
- -- uzbl generates too many events, these are slow
- --, ppExtras = [myMail, myUpdates, myTorrents]
- , ppExtras = [myMail]
- , ppSep = " "
- , ppWsSep = ""
- , ppOutput = hPutStrLn h
- }) >> updatePointer (Relative 0.95 0.95) >> setWMName "LG3D"
- where
- -- thanks byorgey (this filters out NSP too)
- namedOnly ws = if any (`elem` ws) ['a'..'z'] then pad ws else ""
- -- my own filter out scratchpad function
- noScratchPad ws = if ws == "NSP" then "" else pad ws
- -- L needed for loggers
- dzenFG c = dzenColor c ""
- dzenFGL c = dzenColorL c ""
- -- custom loggers
- myMail = wrapL "Mail: " "" . dzenFGL colorFG2 $ maildirNew "/home/yadda/Mail/GMail/INBOX"
- --myUpdates = logCmd "$HOME/.bin/logger-updates"
- --myTorrents = logCmd "$HOME/.bin/logger-torrents"
- myRename = (\x -> case x of
- "Hinted ResizableTall" -> "/ /-/"
- "Mirror Hinted ResizableTall" -> "/-,-/"
- "Hinted Tabbed Bottom Simplest" -> "/.../"
- "Hinted TwoPane" -> "/ / /"
- "Hinted Full" -> "/ /"
- _ -> x
- ) . stripIM
- stripIM s = if "IM " `isPrefixOf` s then drop (length "IM ") s else s
- -- }}}
- -- My SpawnHook {{{
- --
- -- spawn an arbitrary command on urgent
- --
- data MySpawnHook = MySpawnHook String deriving (Read, Show)
- instance UrgencyHook MySpawnHook where
- urgencyHook (MySpawnHook s) w = spawn $ s
- -- 'ding!'
- myUrgencyHook = MySpawnHook ""
- -- }}}
- -- Key Bindings {{{
- --
- -- only those which override/change defaults
- --
- -- see http://pbrisbin.com:8080/pages/scripts.html
- --
- myKeys = [ ("M4-p" , spawn "launcher" ) -- dmenu app launcher
- , ("M4-r" , spawn "bashrun" ) -- gmrun replacement
- , ("M4-C-c" , kill ) -- kill the focused window
- -- opening apps with Win
- , ("M4-e" , spawn "nautilus --no-desktop") -- bring me a nautilus
- , ("M4-g" , spawn "gedit" ) -- start gedit
- , ("M4-x" , spawn "urxvtc" ) -- bring me a full urxvtc
- , ("M4-u" , scratchTerm ) -- bring me a term
- , ("M4-S-m" , scratchMixer ) -- bring me a mixer
- , ("M4-m" , spawn myMail ) -- open mail client
- , ("M4-b" , spawn myBrowser ) -- open web client
- , ("M4-c" , spawn myIRC ) -- open/attach IRC client in screen
- , ("M4-S-t" , spawn myTorrents ) -- open/attach rtorrent in screen
- , ("M4-l" , spawn myLock ) -- W-l to lock screen
- , ("M4-S-h" , spawn myHtop ) -- htop
- -- some custom hotkeys
- , ("M4-a" , spawn "msearch all" ) -- search current playlist via dmenu
- , ("M4-C-g" , spawn "goodsong" ) -- note current song as 'good'
- , ("M4-S-g" , spawn "goodsong -p" ) -- play a random 'good' song
- , ("<Print>" , spawn "scrot" ) -- take a screenshot
- -- extended workspace navigations
- , ("M4-`" , toggleWS ) -- switch to the most recently viewed ws
- , ("M4-<Backspace>" , focusUrgent ) -- focus most recently urgent window
- , ("M4-S-<Backspace>" , clearUrgents ) -- make urgents go away
- , ("M4-0" , viewEmptyWorkspace ) -- go to next empty workspace
- , ("M4-S-0" , tagToEmptyWorkspace ) -- targ window to empty workspace and view it
- -- extended window movements
- , ("M4-o" , sendMessage MirrorShrink) -- shink slave panes vertically
- , ("M4-i" , sendMessage MirrorExpand) -- expand slave panes vertically
- , ("M4-f" , jumpToFull ) -- jump to full layout
- , ("M4-C-m" , withFocused (sendMessage . maximizeRestore) ) -- "maximalize" window
- , ("M4-C-n" , withFocused (\f -> sendMessage (MinimizeWin f)) ) -- "minimize" window
- , ("M4-n" , sendMessage RestoreNextMinimizedWin) -- restore "minimized" windows on this workspace
- , ("M4-S-x" , sendMessage ToggleStruts) -- makes dzen bars go away
- -- non-standard navigation
- , ("M4-C-h" , sendMessage Shrink ) -- shrink master (was M-h)
- , ("M4-C-l" , sendMessage Expand ) -- expand master (was M-l)
- -- mpd and oss volume
- , ("<XF86AudioRewind>" , spawn "mpc seek -00:00:05" ) -- rewind 5 sec
- , ("<XF86AudioForward>" , spawn "mpc seek +00:00:05" ) -- forward 5 sec
- , ("<XF86AudioPlay>" , spawn "mpc toggle" ) -- play/pause mplayer
- , ("<XF86AudioStop>" , spawn "mpc stop" ) -- stop mpd
- , ("<XF86AudioPrev>" , spawn "mpc prev" ) -- prev song
- , ("<XF86AudioNext>" , spawn "mpc next" ) -- next song
- , ("<XF86AudioMute>" , spawn "amixer sset Master toggle" ) -- toggle mute
- , ("<XF86AudioLowerVolume>", spawn "amixer -c 0 set Master 5dB-" ) -- volume down
- , ("<XF86AudioRaiseVolume>", spawn "amixer -c 0 set Master 5dB+" ) -- volume up
- -- Mod+ to control MPlayer
- , ("M4-<XF86AudioPlay>" , mPlay "pause" ) -- play/pause mplayer
- , ("M4-<XF86AudioStop>" , mPlay "stop" ) -- stop mplayer
- , ("M4-<XF86AudioPrev>" , mPlay "seek -10" ) -- seek back 10s
- , ("M4-<XF86AudioNext>" , mPlay "seek 10" ) -- seek forward 10s
- -- kill, reconfigure, exit commands
- , ("M4-w" , killAll ) -- close all windows on this ws
- , ("M4-q" , spawn myRestart ) -- restart xmonad
- , ("M4-S-q" , spawn "leave" ) -- logout/shutdow/restart menu
- , ("M4-s" , spawnSelected defaultGSConfig myApps)
- , ("M4-S-s" , goToSelected defaultGSConfig )
- ]
- where
- myApps = ["ario","gimp","jD","gedit","tbird","iview","mp3tag","mirc","eclipse","OOo Writer","boinc","texmaker","smplayer"]
- focusScreen n = screenWorkspace n >>= flip whenJust (windows . W.view)
- jumpToFull = sendMessage $ JumpToLayout "Hinted Full"
- scratchTerm = namedScratchpadAction myScratchPads "terminal"
- scratchMixer = namedScratchpadAction myScratchPads "mixer"
- -- my apps
- myMail = myTerminal ++ " -e mutt"
- myHtop = myTerminal ++ " -e htop"
- myBrowser = "firefox"
- myLock = "slock"
- myEject = "eject -T /dev/sr0"
- myIRC = myScreen "irssi"
- myTorrents = myScreen "rtorrent"
- -- see http://pbrisbin.com:8080/pages/screen_tricks.html
- myScreen s = myTerminal ++ " -title " ++ s
- ++ " -e bash -cl \"SCREEN_CONF=" ++ s
- ++ " screen -S " ++ s
- ++ " -R -D " ++ s
- ++ "\""
- -- see http://pbrisbin.com:8080/pages/mplayer-control.html
- mPlay s = spawn $ "echo " ++ s ++ " > $HOME/.mplayer_fifo"
- -- kill all conky/dzen2 before executing default restart command
- myRestart = "for pid in `pgrep conky`; do kill -9 $pid; done && " ++
- "for pid in `pgrep dzen2`; do kill -9 $pid; done && " ++
- "xmonad --recompile && xmonad --restart"
- -- }}}
- -- vim:foldmethod=marker foldmarker={{{,}}}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement