Personal tools

Xmonad/Config archive/Regalia's xmonad.hs

From HaskellWiki

< Xmonad | Config archive(Difference between revisions)
Jump to: navigation, search
(Regalia's xmonad.hs)
 
 
Line 8: Line 8:
 
import Data.List
 
import Data.List
 
import Data.Ratio ((%))
 
import Data.Ratio ((%))
+
import XMonad.ManageHook
 
-- Actions
 
-- Actions
 
import XMonad.Actions.CycleWS
 
import XMonad.Actions.CycleWS
import XMonad.Actions.Plane
 
import XMonad.Actions.TopicSpace
 
 
import XMonad.Actions.SpawnOn
 
import XMonad.Actions.SpawnOn
 
import XMonad.Actions.OnScreen
 
import XMonad.Actions.OnScreen
 
import XMonad.Actions.SwapWorkspaces
 
import XMonad.Actions.SwapWorkspaces
+
import XMonad.Actions.Submap
  +
import XMonad.Actions.Search
  +
import XMonad.Actions.UpdatePointer
  +
import XMonad.Actions.SpawnOn
 
-- Hooks
 
-- Hooks
 
import XMonad.Hooks.ManageHelpers
 
import XMonad.Hooks.ManageHelpers
Line 24: Line 22:
 
import XMonad.Hooks.FadeInactive
 
import XMonad.Hooks.FadeInactive
 
import XMonad.Hooks.UrgencyHook hiding (Never)
 
import XMonad.Hooks.UrgencyHook hiding (Never)
+
import XMonad.Hooks.ICCCMFocus
 
-- Layouts
 
-- Layouts
 
import XMonad.Layout.PerWorkspace
 
import XMonad.Layout.PerWorkspace
Line 32: Line 30:
 
import XMonad.Layout.NoBorders
 
import XMonad.Layout.NoBorders
 
import XMonad.Layout.Reflect
 
import XMonad.Layout.Reflect
+
import XMonad.Layout.Tabbed
  +
import qualified XMonad.Layout.Magnifier as Mag
  +
import XMonad.Layout.MultiToggle
  +
import XMonad.Layout.Minimize
  +
import XMonad.Layout.BoringWindows
  +
import qualified XMonad.Layout.ToggleLayouts as Tog
 
-- Prompts
 
-- Prompts
 
import XMonad.Prompt
 
import XMonad.Prompt
Line 41: Line 39:
 
import XMonad.Prompt.RunOrRaise
 
import XMonad.Prompt.RunOrRaise
 
import XMonad.Prompt.AppendFile
 
import XMonad.Prompt.AppendFile
 
 
-- Util
 
-- Util
  +
import XMonad.Util.NamedScratchpad
 
import XMonad.Util.Run(spawnPipe)
 
import XMonad.Util.Run(spawnPipe)
 
import XMonad.Util.EZConfig(additionalKeysP, additionalKeys)
 
import XMonad.Util.EZConfig(additionalKeysP, additionalKeys)
  +
  +
-- Simple configuration
  +
myBorderWidth = 3
  +
myBrowser = "uzbl-browser"
  +
myTerminal = "urxvtc"
  +
myShell = "zsh"
  +
myModMask = mod4Mask
  +
myIconDir = "/home/scott/.dzen/dzenIcons/"
  +
myStatusBar = "dzen2 -xs 2 -x '0' -y '0' -h '18' -w '750' -ta 'l' -bg '" ++ myDBGColor ++ "' -fn '" ++ myFont ++ "'"
  +
myLeft = ".dzen/left.zsh | dzen2 -xs 2 -x '750' -y '0' -h '18' -w '530' -ta 'r' -bg '" ++ myDBGColor ++ "' -fg '" ++ myFontCol ++ "' -fn '" ++ myFont ++ "'"
  +
myFont = "-*-terminus-medium-*-*-*-12-120-75-75-*-*-iso8859-*"
  +
myFont2 = "-*-terminus-bold-*-*-*-16-160-72-72-*-*-iso8859-*"
  +
  +
myWorkspaces = ["web", "de", "V", "v", "t", "Φ", "com", "music", "vm"]
  +
color1 = "#262621"
  +
color2 = "#a3d930"
  +
color3 = "#fdfdfd"
  +
color4 = "#38a2d6"
  +
color5 = "#1793d1"
  +
  +
myDFGColor = color4
  +
myDBGColor = color1
  +
  +
myFFGColor = color3
  +
myFBGColor = color4
  +
  +
myVFGColor = color3
  +
myVBGColor = color1
  +
  +
myUFGColor = color1
  +
myUBGColor = color2
  +
  +
myIFGColor = color3
  +
myIBGColor = color1
  +
  +
mySColor = color5
  +
myBorder = "#121212"
  +
myFBorder = color2
  +
myFontCol = color5
  +
   
 
--
 
--
Line 51: Line 89:
   
 
main = do
 
main = do
checkTopicConfig myTopics myTopicConfig
 
 
dzen <- spawnPipe myStatusBar
 
dzen <- spawnPipe myStatusBar
 
other <- spawnPipe myLeft
 
other <- spawnPipe myLeft
other <- spawnPipe myRight
+
xmonad $ withUrgencyHook dzenUrgencyHook {args = ["-bg", "green", "-xs", "0"] } $ defaultConfig
xmonad $ withUrgencyHook NoUrgencyHook defaultConfig
+
{ manageHook = manageHook defaultConfig <+> namedScratchpadManageHook scratchpads<+> myManageHook
{ manageHook = manageHook defaultConfig <+> myManageHook
 
 
, layoutHook = mylayoutHook
 
, layoutHook = mylayoutHook
 
, startupHook = setWMName "LG3D"
 
, startupHook = setWMName "LG3D"
Line 63: Line 100:
 
, focusFollowsMouse = True
 
, focusFollowsMouse = True
 
, normalBorderColor = myBorder
 
, normalBorderColor = myBorder
, focusedBorderColor = myFocusedBorder
+
, focusedBorderColor = myFBorder
, workspaces = myTopics
+
, workspaces = myWorkspaces
, logHook = myLogHook >> (dynamicLogWithPP $ myDzenPP dzen)
+
, logHook = myLogHook >> (dynamicLogWithPP $ myDzenPP dzen )
 
} `additionalKeysP` myKeys
 
} `additionalKeysP` myKeys
   
 
-- End Main
 
-- End Main
   
-- Simple configuration
 
myBorderWidth = 2
 
myBrowser = "firefox"
 
myTerminal = "urxvtc"
 
myShell = "zsh"
 
myModMask = mod4Mask
 
myIconDir = "/home/scott/.dzen/dzenIcons/"
 
myStatusBar = "dzen2 -x '0' -y '0' -h '20' -w '330' -ta 'l' -bg '" ++ myDBGColor ++ "' -fn '" ++ myFont ++ "'"
 
myLeft = ".dzen/left.zsh | dzen2 -xs 1 -x '330' -y '0' -h '20' -w '1110' -ta 'r' -bg '" ++ myDBGColor ++ "' -fg '" ++ myDFGColor ++ "' -fn '" ++ myFont ++ "'"
 
myRight = ".dzen/right.zsh | dzen2 -xs 2 -y '0' -h '20' -ta 'r' -bg '" ++ myDBGColor ++ "' -fg '" ++ myDFGColor ++ "' -fn '" ++ myFont ++ "'"
 
myFont = "-*-terminus-medium-*-*-*-12-120-75-75-*-*-iso8859-*"
 
   
 
-- Layout Hook
 
-- Layout Hook
mylayoutHook = smartBorders $ avoidStruts $ lessBorders (Combine Difference Screen OnlyFloat) (Mirror tiled ||| tiled ||| fullscreenLayout)
+
mylayoutHook = mkToggle (single REFLECTX) $ mkToggle (single REFLECTY) $
  +
boringWindows $ minimize $ Mag.magnifierOff $
  +
smartBorders $ avoidStruts $ lessBorders (Combine Difference Screen OnlyFloat)
  +
(Tog.toggleLayouts Full (Mirror tiled ||| Grid ||| onWorkspace "web" tabbedLayout tiled))
 
where
 
where
fullscreenLayout = smartBorders Full
+
fullscreenLayout = smartBorders Full
tiled = Tall nmaster delta ratio
+
tiled = Tall nmaster delta ratio
nmaster = 1
+
nmaster = 1
delta = 3 / 100
+
delta = 3 / 100
ratio = 11 / 20
+
ratio = 11 / 20
  +
tabbedLayout = tabbed shrinkText myTabConfig
  +
reflected = reflectHoriz $ tiled
   
  +
-- Scratchpads
  +
scratchpads = [
  +
NS "htop" "urxvtc -e htop" (title =? "htop") (customFloating $ W.RationalRect 0 0 1 (5/12)),
  +
NS "python" "urxvtc -e python" (title =? "python") (customFloating $ W.RationalRect 0 0 1 (5/12)),
  +
NS "skynet" "urxvtc -title skynet -e ssh skynet -t screen -Dr" (title =? "skynet") (customFloating $ W.RationalRect 0 0 1 (5/12)),
  +
NS "devmtp" "urxvtc -title devmtp -e ssh devmtp -t screen -Dr" (title =? "devmtp") (customFloating $ W.RationalRect 0 0 1 (5/12)),
  +
NS "andromeda" "urxvtc -title andromeda -e ssh andromeda -t screen -Dr" (title =? "andromeda") (customFloating $ W.RationalRect 0 0 1 (5/12))
  +
]
 
-- Manage hook
 
-- Manage hook
 
myManageHook = composeAll
 
myManageHook = composeAll
 
[ className =? "Xmessage" --> doFloat
 
[ className =? "Xmessage" --> doFloat
, className =? "Pidgin" --> doShift "im"
+
,className =? "Dialogue" --> doFloat
, className =? "Navigator" --> doShift "web"
 
, title =? "wowee" --> doShift "term"
 
, title =? "dev" --> doShift "dev"
 
, title =? "irssi" --> doShift "irc"
 
, title =? "nyxmms2" --> doShift "music"
 
, title =? "sup" --> doShift "mail"
 
, title =? "htop" --> doShift "mon"
 
 
]
 
]
<+> (fmap not isDialog --> doF avoidMaster)
+
<+> (fmap not isDialog --> doF avoidMaster)
 
<+> composeOne [ isFullscreen -?> doFullFloat ]
 
<+> composeOne [ isFullscreen -?> doFullFloat ]
   
 
-- Log Hook
 
-- Log Hook
myLogHook = fadeInactiveLogHook fadeAmount
+
myLogHook = takeTopFocus >> fadeInactiveLogHook fadeAmount >> updatePointer (Relative 0.2 0.5)
 
where fadeAmount = 0.90
 
where fadeAmount = 0.90
   
Line 106: Line 140:
 
myXPConfig :: XPConfig
 
myXPConfig :: XPConfig
 
myXPConfig = defaultXPConfig { font = myFont
 
myXPConfig = defaultXPConfig { font = myFont
, height = 22
+
, height = 22
, bgColor = myDBGColor }
+
, bgColor = myDBGColor
  +
, fgColor = myDFGColor
  +
, fgHLight = myFFGColor
  +
, bgHLight = myFBGColor
  +
, historySize = 10 }
  +
  +
myTabConfig = defaultTheme { fontName = myFont
  +
, activeColor = myFBGColor
  +
, inactiveColor = myDBGColor
  +
, activeTextColor = myFFGColor
  +
, inactiveTextColor = myDFGColor }
   
myDFGColor = "#b2b27f" -- Dzen
 
myDBGColor = "#2f3436"
 
myFFGColor = "#4c5e52" -- Focused
 
myFBGColor = "#ffbe2c"
 
myVFGColor = "#4c5e52" -- Visible
 
myVBGColor = "#2f3436"
 
myUFGColor = "#4c5e52" -- Urgent
 
myUBGColor = "#ffeca1"
 
myIFGColor = "#ffeca1" -- Icon
 
myIBGColor = myDBGColor
 
mySColor = myDFGColor -- Seperator
 
myBorder = "#4c5e52"
 
myFocusedBorder = "#4c5e52"
 
   
 
-- Pretty Printing
 
-- Pretty Printing
 
myDzenPP h = defaultPP
 
myDzenPP h = defaultPP
{ ppCurrent = dzenColor myFFGColor myFBGColor . wrap ("^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/eye_l.xbm)" ++ "^fg(" ++ myFFGColor ++ ")") ""
+
{ ppCurrent = dzenColor myFFGColor myFBGColor . wrap ("^i(" ++ myIconDir ++ "/dzen_bitmaps/has_win.xbm)") ""
, ppVisible = dzenColor myVFGColor myVBGColor . wrap "" ("^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/eye_r.xbm)")
+
, ppVisible = dzenColor myVFGColor myVBGColor . wrap ("^i(" ++ myIconDir ++ "/dzen_bitmaps/has_win.xbm)") ""
, ppHidden = dzenColor myDFGColor myDBGColor . wrap ("^i(" ++ myIconDir ++ "/dzen_bitmaps/has_win.xbm)") ""
+
, ppHidden = dzenColor myDFGColor myDBGColor . wrap ("^i(" ++ myIconDir ++ "/dzen_bitmaps/has_win.xbm)") "" . filterNSP
, ppHiddenNoWindows = dzenColor myDFGColor myDBGColor . wrap ("^i(" ++ myIconDir ++ "/dzen_bitmaps/has_win_nv.xbm)") ""
+
, ppHiddenNoWindows = dzenColor myDFGColor myDBGColor . wrap ("^i(" ++ myIconDir ++ "/dzen_bitmaps/has_win_nv.xbm)") "" .filterNSP
 
, ppUrgent = dzenColor myUFGColor myUBGColor . wrap ("^i(" ++ myIconDir ++ "/info_03.xbm)") "" . dzenStrip
 
, ppUrgent = dzenColor myUFGColor myUBGColor . wrap ("^i(" ++ myIconDir ++ "/info_03.xbm)") "" . dzenStrip
, ppTitle = dzenColor myDFGColor myDBGColor . shorten 0
+
, ppTitle = dzenColor myDFGColor myDBGColor . trim . shorten 20
 
, ppLayout = dzenColor myDFGColor myDBGColor .
 
, ppLayout = dzenColor myDFGColor myDBGColor .
  +
-- None of these match anymore, need to strip off Mag/Toggle/Reflect
 
(\x -> case x of
 
(\x -> case x of
 
"Mirror Tall" -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/mtall.xbm)"
 
"Mirror Tall" -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/mtall.xbm)"
 
"Tall" -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/tall.xbm)"
 
"Tall" -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/tall.xbm)"
 
"Full" -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/full.xbm)"
 
"Full" -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/full.xbm)"
  +
"Tabbed Simplest" -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/full.xbm)"
 
"Grid" -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/grid.xbm)"
 
"Grid" -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/grid.xbm)"
 
"TwoPane" -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/two_pane.xbm)"
 
"TwoPane" -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/two_pane.xbm)"
 
_ -> x
 
_ -> x
 
)
 
)
, ppSep = " "
+
, ppSep = "||"
 
, ppOutput = hPutStrLn h }
 
, ppOutput = hPutStrLn h }
  +
where
  +
filterNSP ws = if ws /= "NSP" then ws else ""
  +
   
 
-- Key Bindings
 
-- Key Bindings
myKeys = [ ("M-f", spawn myBrowser)
+
myKeys = [ ("M-u", spawnHere myBrowser)
-- xmms2
+
-- run
, ("M-S-'", spawn "nyxmms2 prev")
+
, ("M-r", submap . M.fromList $
, ("M-S-.", spawn "nyxmms2 next")
+
[ ((0, xK_i), spawnHere "/opt/idea/bin/idea.sh")
, ("M-S-p", spawn "nyxmms2 toggle")
+
, ((0, xK_c), spawnHere "google-chrome")
-- ALSA Volume
+
])
  +
  +
-- web apps
  +
, ("M-a", submap . M.fromList $
  +
[ ((0, xK_p), spawnHere "google-chrome http://plus.google.com")
  +
, ((0, xK_f), spawnHere "google-chrome http://facebook.com")
  +
, ((0, xK_t), spawnHere "google-chrome http://www.toodledo.com/tasks/index.php")
  +
, ((0, xK_g), spawnHere "google-chrome http://gmail.com")
  +
, ((0, xK_m), spawnHere "google-chrome http://mint.com")
  +
])
  +
  +
-- bookmarks
  +
, ("M-b", submap . M.fromList $
  +
[ ((0, xK_r), spawnHere "uzbl-browser reddit.com")
  +
])
  +
-- searches
  +
, ("M-s", promptSearchBrowser myXPConfig myBrowser google)
  +
, ("M-S-s", submap . M.fromList $
  +
[ ((0, xK_a), promptSearchBrowser myXPConfig myBrowser amazon)
  +
, ((0, xK_c), promptSearchBrowser myXPConfig myBrowser codesearch)
  +
, ((0, xK_d), promptSearchBrowser myXPConfig myBrowser dictionary)
  +
, ((0, xK_g), promptSearchBrowser myXPConfig myBrowser google)
  +
, ((0, xK_i), promptSearchBrowser myXPConfig myBrowser imdb)
  +
, ((0, xK_m), promptSearchBrowser myXPConfig myBrowser maps)
  +
, ((0, xK_t), promptSearchBrowser myXPConfig myBrowser thesaurus)
  +
, ((0, xK_y), promptSearchBrowser myXPConfig myBrowser youtube)
  +
])
  +
-- documentation
  +
, ("M-d", submap . M.fromList $
  +
[ ((0, xK_p), spawnHere "uzbl-browser http://docs.python.org/modindex.html")
  +
, ((0, xK_t), spawnHere "uzbl-browser twistedmatrix.com/documents/current/api/classIndex.html")
  +
, ((0, xK_u), spawnHere "uzbl-browser uzbl.org")
  +
, ((0, xK_e), spawnHere "uzbl-browser http://erldocs.com/")
  +
, ((0, xK_x), spawnHere "uzbl-browser xmonad.org/xmonad-docs/xmonad-contrib/index.html")
  +
])
  +
-- scratchpads
  +
, ("M-p", submap . M.fromList $
  +
[ ((0, xK_h), namedScratchpadAction scratchpads "htop")
  +
, ((0, xK_p), namedScratchpadAction scratchpads "python")
  +
, ((0, xK_n), namedScratchpadAction scratchpads "skynet")
  +
, ((0, xK_d), namedScratchpadAction scratchpads "devmtp")
  +
, ((0, xK_a), namedScratchpadAction scratchpads "andromeda")
  +
])
  +
  +
-- alsa volume
 
, ("M-C-e", spawn "amixer set Master 2%-")
 
, ("M-C-e", spawn "amixer set Master 2%-")
 
, ("M-C-u", spawn "amixer set Master 2%+")
 
, ("M-C-u", spawn "amixer set Master 2%+")
-- CycleWS
 
, ("M-s", nextWS)
 
, ("M-n", prevWS)
 
-- Swap Workspaces
 
, ("M-S-s", swapTo Next)
 
, ("M-S-n", swapTo Prev)
 
-- Prompt
 
, ("M-C-p", runOrRaisePrompt defaultXPConfig)
 
, ("M-C-.", shellPrompt defaultXPConfig)
 
, ("M-C-j", jumpPrompt)
 
-- Toggle Struts
 
, ("M-S-s", sendMessage ToggleStruts)
 
-- Topics
 
, ("M-a", currentTopicAction myTopicConfig)
 
, ("M-g", promptedGoto)
 
, ("M-c", promptedGotoOtherScreen)
 
, ("M-S-g", promptedShift)
 
-- Restart
 
, ("M-q", spawn myRestart)
 
]
 
++
 
-- Change Xinerama bindings
 
[ ("M-"++key, screenWorkspace sc >>= flip whenJust (windows . f))
 
| (key, sc) <- zip ["w", "v", "z"] [0..]
 
, (f, m) <- [(W.view, 0)]]
 
   
spawnShell :: X ()
+
-- lock
spawnShell = currentTopicDir myTopicConfig >>= spawnShellIn
+
, ("M-S-x", spawn "xscreensaver-command -lock")
   
spawnShellIn :: Dir -> X ()
+
-- prompt
spawnShellIn dir = spawn $ myTerminal ++ " -title urxvt -e sh -c 'cd ''" ++ dir ++ "'' && " ++ myShell ++ "'"
+
, ("M-C-p", runOrRaisePrompt myXPConfig)
   
goto :: Topic -> X ()
+
-- toggle Struts
goto = switchTopic myTopicConfig
+
, ("M-C-s", sendMessage ToggleStruts)
 
promptedGoto :: X ()
 
promptedGoto = workspacePrompt myXPConfig goto
 
   
promptedGotoOtherScreen :: X ()
+
-- zoom
promptedGotoOtherScreen =
+
, ("M-S-i", sendMessage Mag.MagnifyMore)
workspacePrompt myXPConfig $ \ws -> do
+
, ("M-S-o", sendMessage Mag.MagnifyLess)
nextScreen
+
, ("M-S-z", sendMessage Mag.Toggle)
goto ws
 
   
promptedShift :: X ()
+
-- reflectoggle
promptedShift = workspacePrompt myXPConfig $ windows . W.shift
+
, ("M-x", sendMessage $ Toggle REFLECTX)
  +
, ("M-y", sendMessage $ Toggle REFLECTY)
   
jumpPrompt :: X ()
+
-- minimize
jumpPrompt = inputPrompt defaultXPConfig ("Jump") ?+ spawnJump
+
, ("M-c", withFocused minimizeWindow)
  +
, ("M-g", sendMessage RestoreNextMinimizedWin)
   
spawnJump :: String -> X ()
+
-- boring Windows
spawnJump s = spawn ("nyxmms2 jump artist:" ++ s)
+
, ("M-j", focusDown)
  +
, ("M-k", focusUp)
  +
, ("M-m", focusMaster)
  +
  +
-- toggleLayouts
  +
, ("M-n", sendMessage (Tog.ToggleLayout))
  +
  +
-- restart
  +
, ("M-q", spawn myRestart)
  +
]
  +
++
  +
  +
-- Change Xinerama bindings
  +
[ ("M-"++key, screenWorkspace sc >>= flip whenJust (windows . f))
  +
|(key, sc) <- zip ["w", "v", "z"] [0..]
  +
, (f, m) <- [(W.view, 0)]]
   
 
-- Helper functions
 
-- Helper functions
Line 213: Line 214:
 
myRestart = "for pid in `pgrep dzen2`; do kill -9 $pid; done && xmonad --recompile && xmonad --restart"
 
myRestart = "for pid in `pgrep dzen2`; do kill -9 $pid; done && xmonad --recompile && xmonad --restart"
   
-- TopicSpace things
 
myTopics :: [Topic]
 
myTopics =
 
[ "web"
 
, "mail"
 
, "term"
 
, "music"
 
, "im"
 
, "irc"
 
, "dev"
 
, "mon"
 
]
 
 
myTopicConfig :: TopicConfig
 
myTopicConfig = TopicConfig
 
{ topicDirs = M.fromList $
 
[ ("music", "~/music")
 
]
 
, defaultTopicAction = const $ spawnShell
 
, defaultTopic = "web"
 
, maxTopicHistory = 10
 
, topicActions = M.fromList $
 
[ ("web", spawn myBrowser)
 
, ("mail", spawn "urxvtc -e sup")
 
, ("term", spawnShell )
 
, ("im", spawn "pidgin")
 
, ("music", spawn "urxvtc -e nyxmms2")
 
, ("irc", spawn "urxvtc -e irssi")
 
, ("dev", spawnShell )
 
, ("mon", spawn "urxvtc -e htop")
 
]
 
}
 
 
</haskell>
 
</haskell>

Latest revision as of 19:45, 9 February 2012

import XMonad
import qualified XMonad.StackSet as W
import qualified Data.Map        as M
import Control.Monad
import System.IO
import System.IO.Unsafe
import Data.List
import Data.Ratio ((%))
import XMonad.ManageHook
-- Actions
import XMonad.Actions.CycleWS
import XMonad.Actions.SpawnOn
import XMonad.Actions.OnScreen
import XMonad.Actions.SwapWorkspaces
import XMonad.Actions.Submap
import XMonad.Actions.Search
import XMonad.Actions.UpdatePointer
import XMonad.Actions.SpawnOn
-- Hooks
import XMonad.Hooks.ManageHelpers
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.SetWMName
import XMonad.Hooks.FadeInactive
import XMonad.Hooks.UrgencyHook hiding (Never)
import XMonad.Hooks.ICCCMFocus
-- Layouts
import XMonad.Layout.PerWorkspace
import XMonad.Layout.IM
import XMonad.Layout.Grid
import XMonad.Layout.TwoPane
import XMonad.Layout.NoBorders
import XMonad.Layout.Reflect
import XMonad.Layout.Tabbed
import qualified XMonad.Layout.Magnifier as Mag
import XMonad.Layout.MultiToggle
import XMonad.Layout.Minimize
import XMonad.Layout.BoringWindows
import qualified XMonad.Layout.ToggleLayouts as Tog
-- Prompts
import XMonad.Prompt
import XMonad.Prompt.Input
import XMonad.Prompt.Workspace
import XMonad.Prompt.Shell
import XMonad.Prompt.XMonad
import XMonad.Prompt.RunOrRaise
import XMonad.Prompt.AppendFile
-- Util
import XMonad.Util.NamedScratchpad
import XMonad.Util.Run(spawnPipe)
import XMonad.Util.EZConfig(additionalKeysP, additionalKeys)
 
-- Simple configuration
myBorderWidth = 3
myBrowser = "uzbl-browser"
myTerminal = "urxvtc"
myShell = "zsh"
myModMask = mod4Mask
myIconDir = "/home/scott/.dzen/dzenIcons/"
myStatusBar = "dzen2 -xs 2  -x '0' -y '0' -h '18' -w '750' -ta 'l' -bg '" ++ myDBGColor ++ "' -fn '" ++ myFont ++ "'"
myLeft      = ".dzen/left.zsh | dzen2 -xs 2 -x '750' -y '0' -h '18' -w '530' -ta 'r' -bg '" ++ myDBGColor ++ "' -fg '" ++ myFontCol ++ "' -fn '" ++ myFont ++ "'"
myFont = "-*-terminus-medium-*-*-*-12-120-75-75-*-*-iso8859-*"
myFont2 = "-*-terminus-bold-*-*-*-16-160-72-72-*-*-iso8859-*"
 
myWorkspaces = ["web", "de", "V", "v", "t", "Φ", "com", "music", "vm"]
color1 = "#262621"
color2 = "#a3d930"
color3 = "#fdfdfd"
color4 = "#38a2d6"
color5 = "#1793d1"
 
myDFGColor = color4
myDBGColor = color1
 
myFFGColor = color3
myFBGColor = color4
 
myVFGColor = color3
myVBGColor = color1
 
myUFGColor = color1
myUBGColor = color2
 
myIFGColor = color3
myIBGColor = color1
 
mySColor   = color5
myBorder   = "#121212"
myFBorder  = color2
myFontCol  = color5
 
 
--
-- main
--
 
main = do
    dzen <- spawnPipe myStatusBar
    other <- spawnPipe myLeft
    xmonad $ withUrgencyHook dzenUrgencyHook {args = ["-bg", "green", "-xs", "0"] } $ defaultConfig
	{ manageHook         = manageHook defaultConfig <+> namedScratchpadManageHook scratchpads<+> myManageHook
	, layoutHook         = mylayoutHook
	, startupHook        = setWMName "LG3D"
	, terminal           = myTerminal
	, modMask            = myModMask
	, borderWidth        = myBorderWidth
	, focusFollowsMouse  = True
	, normalBorderColor  = myBorder
	, focusedBorderColor = myFBorder
	, workspaces         = myWorkspaces 
	, logHook            = myLogHook >> (dynamicLogWithPP $ myDzenPP dzen )
	} `additionalKeysP` myKeys
 
-- End Main
 
 
-- Layout Hook
mylayoutHook = mkToggle (single REFLECTX) $ mkToggle (single REFLECTY) $
                    boringWindows $ minimize $ Mag.magnifierOff $
                    smartBorders $ avoidStruts $ lessBorders (Combine Difference Screen OnlyFloat)
                    (Tog.toggleLayouts Full (Mirror tiled ||| Grid ||| onWorkspace "web" tabbedLayout tiled))
    where
        fullscreenLayout = smartBorders Full
        tiled = Tall nmaster delta ratio
        nmaster = 1
        delta = 3 / 100
        ratio = 11 / 20
        tabbedLayout = tabbed shrinkText myTabConfig
        reflected =  reflectHoriz $ tiled
 
-- Scratchpads
scratchpads = [
    NS "htop" "urxvtc -e htop" (title =? "htop") (customFloating $ W.RationalRect 0 0 1 (5/12)),
    NS "python" "urxvtc -e python" (title =? "python") (customFloating $ W.RationalRect 0 0 1 (5/12)),
    NS "skynet" "urxvtc -title skynet -e ssh skynet -t screen -Dr" (title =? "skynet") (customFloating $ W.RationalRect 0 0 1 (5/12)),
    NS "devmtp" "urxvtc -title devmtp -e ssh devmtp -t screen -Dr" (title =? "devmtp") (customFloating $ W.RationalRect 0 0 1 (5/12)),
    NS "andromeda" "urxvtc -title andromeda -e ssh andromeda -t screen -Dr" (title =? "andromeda") (customFloating $ W.RationalRect 0 0 1 (5/12))
    ]
-- Manage hook
myManageHook = composeAll
    [  className =? "Xmessage"  --> doFloat 
      ,className =? "Dialogue"  --> doFloat 
    ] 
        <+> (fmap not isDialog --> doF avoidMaster)
		<+> composeOne [ isFullscreen -?> doFullFloat ]
 
-- Log Hook
myLogHook = takeTopFocus >> fadeInactiveLogHook fadeAmount >> updatePointer (Relative 0.2 0.5)
    where fadeAmount = 0.90
 
-- XP Config
myXPConfig :: XPConfig
myXPConfig = defaultXPConfig { font = myFont
                             , height = 22
                             , bgColor = myDBGColor
                             , fgColor = myDFGColor
                             , fgHLight = myFFGColor
                             , bgHLight = myFBGColor
                             , historySize = 10 }
 
myTabConfig = defaultTheme   { fontName = myFont
                              , activeColor = myFBGColor
                              , inactiveColor = myDBGColor
                              , activeTextColor = myFFGColor
                              , inactiveTextColor = myDFGColor }
 
 
-- Pretty Printing
myDzenPP h = defaultPP
     {  ppCurrent         = dzenColor myFFGColor myFBGColor . wrap ("^i(" ++ myIconDir ++ "/dzen_bitmaps/has_win.xbm)") ""
      , ppVisible         = dzenColor myVFGColor myVBGColor . wrap ("^i(" ++ myIconDir ++ "/dzen_bitmaps/has_win.xbm)") ""
      , ppHidden          = dzenColor myDFGColor myDBGColor . wrap ("^i(" ++ myIconDir ++ "/dzen_bitmaps/has_win.xbm)") "" . filterNSP
      , ppHiddenNoWindows = dzenColor myDFGColor myDBGColor . wrap ("^i(" ++ myIconDir ++ "/dzen_bitmaps/has_win_nv.xbm)") ""  .filterNSP
      , ppUrgent          = dzenColor myUFGColor myUBGColor . wrap ("^i(" ++ myIconDir ++ "/info_03.xbm)") "" . dzenStrip
      , ppTitle           = dzenColor myDFGColor myDBGColor . trim . shorten 20
      , ppLayout          = dzenColor myDFGColor myDBGColor .
                            -- None of these match anymore, need to strip off Mag/Toggle/Reflect
                            (\x -> case x of
                            "Mirror Tall" -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/mtall.xbm)"
                            "Tall"	  -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/tall.xbm)"
                            "Full"	  -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/full.xbm)"
                            "Tabbed Simplest"	  -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/full.xbm)"
                            "Grid"	  -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/grid.xbm)"
                            "TwoPane"	  -> "^fg(" ++ myIFGColor ++ ")^i(" ++ myIconDir ++ "/dzen_bitmaps/two_pane.xbm)"
                            _ -> x
                            )
      , ppSep             = "||"
      , ppOutput          = hPutStrLn h }
      where
        filterNSP ws = if ws /= "NSP" then ws else ""
 
 
-- Key Bindings 
myKeys = [ ("M-u",	spawnHere myBrowser)  	
         -- run
         , ("M-r",  submap . M.fromList $
            [ ((0, xK_i),  spawnHere "/opt/idea/bin/idea.sh")
            , ((0, xK_c),  spawnHere "google-chrome")
            ])
 
         -- web apps
         , ("M-a",  submap . M.fromList $
            [ ((0, xK_p),  spawnHere "google-chrome http://plus.google.com")
            , ((0, xK_f),  spawnHere "google-chrome http://facebook.com")
            , ((0, xK_t),  spawnHere "google-chrome http://www.toodledo.com/tasks/index.php")
            , ((0, xK_g),  spawnHere "google-chrome http://gmail.com")
            , ((0, xK_m),  spawnHere "google-chrome http://mint.com")
            ])
 
         -- bookmarks
         , ("M-b",  submap . M.fromList $
            [ ((0, xK_r),    spawnHere "uzbl-browser reddit.com")
            ])
         -- searches
         , ("M-s",         promptSearchBrowser myXPConfig myBrowser google)
         , ("M-S-s",      submap . M.fromList $
            [ ((0, xK_a),    promptSearchBrowser myXPConfig myBrowser amazon)
            , ((0, xK_c),    promptSearchBrowser myXPConfig myBrowser codesearch)
            , ((0, xK_d),    promptSearchBrowser myXPConfig myBrowser dictionary)
            , ((0, xK_g),    promptSearchBrowser myXPConfig myBrowser google)
            , ((0, xK_i),    promptSearchBrowser myXPConfig myBrowser imdb)
            , ((0, xK_m),    promptSearchBrowser myXPConfig myBrowser maps)
            , ((0, xK_t),    promptSearchBrowser myXPConfig myBrowser thesaurus)
            , ((0, xK_y),    promptSearchBrowser myXPConfig myBrowser youtube)
            ])
         -- documentation
         , ("M-d",  submap . M.fromList $
            [ ((0, xK_p),    spawnHere "uzbl-browser http://docs.python.org/modindex.html")
            , ((0, xK_t),    spawnHere "uzbl-browser twistedmatrix.com/documents/current/api/classIndex.html")
            , ((0, xK_u),    spawnHere "uzbl-browser uzbl.org")
            , ((0, xK_e),    spawnHere "uzbl-browser http://erldocs.com/")
            , ((0, xK_x),    spawnHere "uzbl-browser xmonad.org/xmonad-docs/xmonad-contrib/index.html")
            ])
        -- scratchpads
         , ("M-p",  submap . M.fromList $
            [ ((0, xK_h),    namedScratchpadAction scratchpads "htop")
            , ((0, xK_p),    namedScratchpadAction scratchpads "python")
            , ((0, xK_n),    namedScratchpadAction scratchpads "skynet")
            , ((0, xK_d),    namedScratchpadAction scratchpads "devmtp")
            , ((0, xK_a),    namedScratchpadAction scratchpads "andromeda")
            ])
 
         -- alsa volume
         , ("M-C-e",	spawn "amixer set Master 2%-")
         , ("M-C-u",	spawn "amixer set Master 2%+")
 
         -- lock
         , ("M-S-x",	spawn "xscreensaver-command -lock")
 
         -- prompt
         , ("M-C-p",	runOrRaisePrompt myXPConfig)
 
         -- toggle Struts
         , ("M-C-s",	sendMessage ToggleStruts)
 
         -- zoom
         , ("M-S-i",	sendMessage Mag.MagnifyMore)
         , ("M-S-o",	sendMessage Mag.MagnifyLess)
         , ("M-S-z",	sendMessage Mag.Toggle)
 
         -- reflectoggle
         , ("M-x",	sendMessage $ Toggle REFLECTX)
         , ("M-y",	sendMessage $ Toggle REFLECTY)
 
         -- minimize
         , ("M-c",	withFocused minimizeWindow)
         , ("M-g",	sendMessage RestoreNextMinimizedWin)
 
         -- boring Windows
         , ("M-j",	focusDown)
         , ("M-k",	focusUp)
         , ("M-m",	focusMaster)
 
         -- toggleLayouts
         , ("M-n",     sendMessage (Tog.ToggleLayout))
 
         -- restart
         , ("M-q",       spawn myRestart)
         ]
         ++	
 
         -- Change Xinerama bindings
         [ ("M-"++key, screenWorkspace sc >>= flip whenJust (windows . f))
             |(key, sc) <- zip ["w", "v", "z"] [0..]
             , (f, m) <- [(W.view, 0)]] 
 
-- Helper functions
--
-- Avoid changing master on new window creation
avoidMaster :: W.StackSet i l a s sd -> W.StackSet i l a s sd
avoidMaster = W.modify' $ \c -> case c of
	W.Stack t [] (r:rs) -> W.Stack t [r] rs
	otherwise			-> c
 
-- Kill zombie dzens before normal xmonad restart
myRestart :: String
myRestart = "for pid in `pgrep dzen2`; do kill -9 $pid; done && xmonad --recompile && xmonad --restart"