Personal tools

Xmonad/Config archive/skorpan's xmonad.hs

From HaskellWiki

< Xmonad | Config archive(Difference between revisions)
Jump to: navigation, search
(haskell tags)
(Updating.)
 
(3 intermediate revisions by one user not shown)
Line 1: Line 1:
<haskell>--
+
<haskell>import System.Exit
-- ~/.xmonad/xmonad.hs
 
--
 
 
-- import the necessary libraries
 
 
 
import XMonad
 
import XMonad
import XMonad.ManageHook
+
import XMonad.Hooks.DynamicLog
import XMonad.Operations
+
import XMonad.Hooks.ManageDocks
import XMonad.Actions.CycleWS
+
import XMonad.Layout.NoBorders
import XMonad.Actions.DwmPromote
+
import XMonad.Prompt (defaultXPConfig)
import XMonad.Actions.RotSlaves
+
import XMonad.Prompt.Shell (shellPrompt)
import XMonad.Actions.RotView
+
import XMonad.Util.EZConfig
import XMonad.Actions.SinkAll
 
import XMonad.Hooks.DynamicLog ( PP(..), dynamicLogWithPP, dzenColor, wrap, defaultPP )
 
import XMonad.Hooks.UrgencyHook
 
import XMonad.Layout.Grid
 
import XMonad.Layout.Maximize
 
import XMonad.Layout.NoBorders ( noBorders, smartBorders )
 
import XMonad.Layout.Tabbed
 
import XMonad.Layout.ToggleLayouts
 
 
import XMonad.Util.Run
 
import XMonad.Util.Run
   
 
import qualified XMonad.StackSet as W
 
import qualified XMonad.StackSet as W
import qualified XMonad.Actions.FlexibleResize as Flex
+
import qualified Data.Map as M
import qualified Data.Map as M
 
import Data.Bits ((.|.))
 
import Data.Ratio
 
import Graphics.X11
 
import System.IO
 
   
dmenuExec = "exe=`dmenu_path | dmenu -b -fn '-*-terminus-*-r-normal-*-*-120-*-*-*-*-iso8859-*' -nb '#000000' -nf '#FFFFFF' -sb '#333333'` && eval \"exec $exe\""
 
myIconsDir = "/home/deniz/usr/share/dzen2/icons"
 
myStatusBar = "dzen2 -bg '#222222' -fg '#777777' -h 16 -w 640 -sa c -e '' -fn '-*-terminus-*-r-normal-*-*-120-*-*-*-*-iso8859-*' -ta l"
 
 
main = do din <- spawnPipe myStatusBar
 
xmonad $ defaultConfig
 
{ borderWidth = 2
 
, normalBorderColor = "#555555"
 
, focusedBorderColor = "#dddddd"
 
, workspaces =
 
["1:main", "2:web", "3:dev"] ++
 
map show [4..7] ++ ["8:warez","9:music"]
 
, terminal = "urxvt"
 
, modMask = mod4Mask
 
, defaultGaps = [(16,0,0,0)]
 
, manageHook = manageHook defaultConfig <+> myManageHook
 
, logHook = dynamicLogWithPP $ myPP din
 
, layoutHook = toggleLayouts (noBorders Full) $
 
smartBorders $
 
tiled |||
 
Mirror tiled
 
||| Full
 
||| Grid
 
||| tabbed shrinkText defaultTConf
 
||| maximize (Tall 1 (3%100) (1%2))
 
, keys = \c -> myKeys c `M.union` keys defaultConfig c
 
, mouseBindings = \c -> myMouse c `M.union` mouseBindings defaultConfig c
 
}
 
where
 
tiled = Tall nmaster delta ratio
 
nmaster = 1
 
ratio = 50%100
 
delta = 5%100
 
   
-- application control
+
myKeys c = mkKeymap c $
--
+
[ ("M-<Return>", spawn $ XMonad.terminal c)
myManageHook :: ManageHook
+
, ("M-<Space>", sendMessage NextLayout)
myManageHook = composeAll . concat $
+
, ("M-<Tab>", windows W.focusDown)
[ [ className =? c --> doFloat | c <- myFloats]
+
, ("M-S-<Return>", windows W.swapMaster)
, [ title =? t --> doFloat | t <- myOtherFloats]
+
, ("M-S-c", kill)
, [ resource =? r --> doIgnore | r <- myIgnores]
+
, ("M-S-q", io (exitWith ExitSuccess))
, [ className =? "Firefox-bin" --> doF (W.shift "2:web") ]
+
, ("M-b", sendMessage ToggleStruts)
  +
, ("M-h", sendMessage Shrink)
  +
, ("M-l", sendMessage Expand)
  +
, ("M-n", refresh)
  +
, ("M-q", broadcastMessage ReleaseResources >> restart "xmonad" True)
  +
, ("M-t", withFocused $ windows . W.sink)
  +
, ("M-x", shellPrompt defaultXPConfig)]
  +
++
  +
[(m ++ k, windows $ f w)
  +
| (w, k) <- zip (XMonad.workspaces c) (map show [1..9])
  +
, (m, f) <- [("M-",W.greedyView), ("M-S-",W.shift)]]
  +
  +
  +
myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
  +
[ ((modMask, button1), (\w -> focus w >> mouseMoveWindow w))
  +
, ((modMask, button2), (\w -> focus w >> windows W.swapMaster))
  +
, ((modMask, button3), (\w -> focus w >> mouseResizeWindow w))
 
]
 
]
where
 
myIgnores = []
 
myFloats = ["feh",
 
"GIMP",
 
"gimp"]
 
myOtherFloats = ["Bon Echo Preferences",
 
"Mail/News Preferences",
 
"Bon Echo - Restore Previous Session",
 
"MPlayer"]
 
   
-- modify/add default key binds
 
--
 
myKeys conf@(XConfig {modMask = modm}) = M.fromList $
 
[ ((modm, xK_p ), spawn dmenuExec)
 
, ((modm, xK_x ), sendMessage ToggleLayout)
 
, ((modm, xK_z ), toggleWS)
 
, ((modm, xK_Left ), windows W.focusUp)
 
, ((modm, xK_Right ), windows W.focusDown)
 
, ((modm, xK_Up ), windows W.focusUp)
 
, ((modm, xK_Down ), windows W.focusDown)
 
, ((modm, xK_Return ), spawn $ XMonad.terminal conf)
 
, ((modm .|. shiftMask, xK_Tab ), rotSlavesUp)
 
, ((modm .|. shiftMask, xK_Right ), rotView True)
 
, ((modm .|. shiftMask, xK_Left ), rotView False)
 
]
 
 
-- modify/add default mouse binds
 
--
 
myMouse (XConfig {modMask = modm}) = M.fromList $
 
[ ((modm, button3), (\w -> focus w >> Flex.mouseResizeWindow w))
 
, ((modm, button4), (\_ -> rotView True))
 
, ((modm, button5), (\_ -> rotView False))
 
]
 
   
-- dynamiclog pretty printer for dzen
+
myLayoutHook = smartBorders $ avoidStruts $ tiled ||| Mirror tiled ||| Full
-- ironic that this is "pretty printer" with such fugly code.
+
where
myPP h = defaultPP
+
tiled = Tall nmaster delta ratio
{ ppCurrent = wrap "^fg(#ffffff)^bg(#888888)^p(3)" "^p(2)^fg()^bg()" . \wsId ->
+
nmaster = 1
if (':' `elem` wsId) then
+
ratio = 1/2
drop 2 wsId
+
delta = 4/100
else wsId
+
, ppVisible = wrap "^bg(grey30)^fg(grey75)^p(2)" "^p(2)^fg()^bg()"
+
, ppHidden = wrap "^fg(#ffffff)^bg()^p(2)" "^p(3)^fg()^bg()" . \wsId ->
+
myManageHook = composeAll
if (':' `elem` wsId) then
+
[ floatC "MPlayer"
drop 2 wsId
+
, floatC "Gimp"
else wsId
+
, moveToC "Conkeror" "2"
, ppHiddenNoWindows = id . \wsId ->
+
]
if (':' `elem` wsId) then
+
where moveToC c w = className =? c --> doF (W.shift w)
drop 2 wsId
+
moveToT t w = title =? t --> doF (W.shift w)
else wsId
+
floatC c = className =? c --> doFloat
, ppSep = " ^fg(#ffffff)^r(2x2)^p(2)^fg() "
+
, ppWsSep = " "
+
, ppLayout = (\x -> case x of
+
myLogHook xmobar = dynamicLogWithPP $ defaultPP {
"Tall" ->
+
ppOutput = hPutStrLn xmobar
" ^i(" ++ myIconsDir ++ "/tall.xbm) "
+
, ppTitle = xmobarColor "white" "" . shorten 110
"Mirror Tall" ->
+
, ppCurrent = xmobarColor "white" "black" . pad
" ^i(" ++ myIconsDir ++ "/mtall.xbm) "
+
, ppHidden = pad
"Full" ->
+
, ppHiddenNoWindows = \w -> xmobarColor "#444" "" (" " ++ w ++ " ")
" ^i(" ++ myIconsDir ++ "/full.xbm) "
+
, ppSep = xmobarColor "#555" "" " / "
"Grid" ->
+
, ppWsSep = ""
" ^i(" ++ myIconsDir ++ "/grid.xbm) "
+
, ppLayout = \x -> case x of
"Tabbed" ->
+
"Tall" -> "T"
" ^i(" ++ myIconsDir ++ "/tabbed.xbm) "
+
"Mirror Tall" -> "M"
"Maximize Tall" ->
+
"Full" -> "F"
" ^i(" ++ myIconsDir ++ "/maximize.xbm) "
+
_ -> "?"
)
+
}
, ppTitle = dzenColor "white" ""
+
, ppOutput = hPutStrLn h
+
}
+
main = do xmobar <- spawnPipe "xmobar"
  +
xmonad $ defaultConfig {
  +
terminal = "urxvtc",
  +
focusFollowsMouse = True,
  +
borderWidth = 2,
  +
modMask = mod4Mask,
  +
numlockMask = 0,
  +
workspaces = [ show x | x <- [1..9] ],
  +
normalBorderColor = "#444",
  +
focusedBorderColor = "#f00",
  +
keys = myKeys,
  +
mouseBindings = myMouseBindings,
  +
layoutHook = myLayoutHook,
  +
manageHook = myManageHook,
  +
logHook = myLogHook xmobar
  +
}
 
</haskell>
 
</haskell>

Latest revision as of 17:28, 25 January 2009

import System.Exit
import XMonad
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Layout.NoBorders
import XMonad.Prompt (defaultXPConfig)
import XMonad.Prompt.Shell (shellPrompt)
import XMonad.Util.EZConfig
import XMonad.Util.Run
 
import qualified XMonad.StackSet as W
import qualified Data.Map        as M
 
 
myKeys c = mkKeymap c $
           [ ("M-<Return>",   spawn $ XMonad.terminal c)
           , ("M-<Space>",    sendMessage NextLayout)
           , ("M-<Tab>",      windows W.focusDown)
           , ("M-S-<Return>", windows W.swapMaster)
           , ("M-S-c",        kill)
           , ("M-S-q",        io (exitWith ExitSuccess))
           , ("M-b",          sendMessage ToggleStruts)
           , ("M-h",          sendMessage Shrink)
           , ("M-l",          sendMessage Expand)
           , ("M-n",          refresh)
           , ("M-q",          broadcastMessage ReleaseResources >> restart "xmonad" True)
           , ("M-t",          withFocused $ windows . W.sink)
           , ("M-x",          shellPrompt defaultXPConfig)]
           ++
           [(m ++ k, windows $ f w)
                | (w, k) <- zip (XMonad.workspaces c) (map show [1..9])
           , (m, f) <- [("M-",W.greedyView), ("M-S-",W.shift)]]
 
 
myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
    [ ((modMask, button1), (\w -> focus w >> mouseMoveWindow w))
    , ((modMask, button2), (\w -> focus w >> windows W.swapMaster))
    , ((modMask, button3), (\w -> focus w >> mouseResizeWindow w))
    ]
 
 
myLayoutHook = smartBorders $ avoidStruts $ tiled ||| Mirror tiled ||| Full
  where
     tiled   = Tall nmaster delta ratio
     nmaster = 1
     ratio   = 1/2
     delta   = 4/100
 
 
myManageHook = composeAll
               [ floatC "MPlayer"
               , floatC "Gimp"
               , moveToC "Conkeror" "2"
               ]
    where moveToC c w = className =? c --> doF (W.shift w)
          moveToT t w = title     =? t --> doF (W.shift w)
          floatC  c   = className =? c --> doFloat
 
 
myLogHook xmobar = dynamicLogWithPP $ defaultPP {
                     ppOutput = hPutStrLn xmobar
                   , ppTitle = xmobarColor "white" "" . shorten 110
                   , ppCurrent = xmobarColor "white" "black" . pad
                   , ppHidden = pad
                   , ppHiddenNoWindows = \w -> xmobarColor "#444" "" (" " ++ w ++ " ")
                   , ppSep = xmobarColor "#555" "" " / "
                   , ppWsSep = ""
                   , ppLayout = \x -> case x of
                                        "Tall" -> "T"
                                        "Mirror Tall" -> "M"
                                        "Full" -> "F"
                                        _ -> "?"
                   }
 
 
main = do xmobar <- spawnPipe "xmobar"
          xmonad $ defaultConfig {
                       terminal           = "urxvtc",
                       focusFollowsMouse  = True,
                       borderWidth        = 2,
                       modMask            = mod4Mask,
                       numlockMask        = 0,
                       workspaces         = [ show x | x <- [1..9] ],
                       normalBorderColor  = "#444",
                       focusedBorderColor = "#f00",
                       keys               = myKeys,
                       mouseBindings      = myMouseBindings,
                       layoutHook         = myLayoutHook,
                       manageHook         = myManageHook,
                       logHook            = myLogHook xmobar
                     }