Personal tools

Xmonad/Config archive/skorpan's xmonad.hs

From HaskellWiki

< Xmonad | Config archive(Difference between revisions)
Jump to: navigation, search
(Updated for 0.7.)
(Updating.)
 
(One intermediate revision by one user not shown)
Line 1: Line 1:
<haskell>import XMonad
+
<haskell>import System.Exit
import System.Exit
+
import XMonad
 
import XMonad.Hooks.DynamicLog
 
import XMonad.Hooks.DynamicLog
 
import XMonad.Hooks.ManageDocks
 
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run (spawnPipe)
+
import XMonad.Layout.NoBorders
import System.IO (hPutStrLn)
+
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 XMonad.StackSet as W
 
import qualified Data.Map        as M
 
import qualified Data.Map        as M
  
dmenuExec =
 
    "exe=`dmenu_path | dmenu -b -nb black -nf white -sb gray -sf black` && eval \"exec $exe\""
 
  
myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
+
myKeys c = mkKeymap c $
    [ ((modMask,              xK_Return), spawn $ XMonad.terminal conf)
+
          [ ("M-<Return>",   spawn $ XMonad.terminal c)
    , ((modMask,              xK_p    ), spawn dmenuExec)
+
          , ("M-<Space>",   sendMessage NextLayout)
    , ((modMask .|. shiftMask, xK_c    ), kill)
+
          , ("M-<Tab>",     windows W.focusDown)
    , ((modMask,              xK_space ), sendMessage NextLayout)
+
          , ("M-S-<Return>", windows W.swapMaster)
    , ((modMask .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
+
          , ("M-S-c",       kill)
    , ((modMask,              xK_n    ), refresh)
+
          , ("M-S-q",       io (exitWith ExitSuccess))
    , ((modMask,              xK_Tab  ), windows W.focusDown)
+
          , ("M-b",         sendMessage ToggleStruts)
    , ((modMask,              xK_j    ), windows W.focusDown)
+
          , ("M-h",         sendMessage Shrink)
    , ((modMask,               xK_e    ), windows W.focusDown)
+
          , ("M-l",         sendMessage Expand)
    , ((modMask,              xK_Right ), windows W.focusDown)
+
          , ("M-n",         refresh)
    , ((modMask,              xK_k    ), windows W.focusUp  )
+
          , ("M-q",         broadcastMessage ReleaseResources >> restart "xmonad" True)
    , ((modMask,               xK_Left  ), windows W.focusUp  )
+
          , ("M-t",         withFocused $ windows . W.sink)
    , ((modMask,               xK_m    ), windows W.focusMaster  )
+
          , ("M-x",          shellPrompt defaultXPConfig)]
    , ((modMask .|. shiftMask, xK_Return), windows W.swapMaster)
+
          ++
    , ((modMask .|. shiftMask, xK_e    ), windows W.swapDown  )
+
          [(m ++ k, windows $ f w)
    , ((modMask .|. shiftMask, xK_j    ), windows W.swapDown  )
+
                | (w, k) <- zip (XMonad.workspaces c) (map show [1..9])
    , ((modMask .|. shiftMask, xK_k    ), windows W.swapUp    )
+
          , (m, f) <- [("M-",W.greedyView), ("M-S-",W.shift)]]
    , ((modMask,              xK_h    ), sendMessage Shrink)
+
 
    , ((modMask,              xK_l    ), sendMessage Expand)
+
    , ((modMask,              xK_t    ), withFocused $ windows . W.sink)
+
    , ((modMask              , xK_b    ), sendMessage ToggleStruts)
+
    , ((modMask .|. shiftMask, xK_q    ), io (exitWith ExitSuccess))
+
    , ((modMask              , xK_q    ),
+
          broadcastMessage ReleaseResources >> restart "xmonad" True)
+
    ]
+
    ++
+
    [((m .|. modMask, k), windows $ f i)
+
        | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
+
        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
+
  
 
myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
 
myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
Line 49: Line 39:
 
     ]
 
     ]
  
myLayout = avoidStruts (tall ||| Mirror tall ||| Full)
+
 
 +
myLayoutHook = smartBorders $ avoidStruts $ tiled ||| Mirror tiled ||| Full
 
   where
 
   where
     tall   = Tall nmaster delta ratio
+
     tiled   = Tall nmaster delta ratio
 
     nmaster = 1
 
     nmaster = 1
 
     ratio  = 1/2
 
     ratio  = 1/2
     delta  = 2/100
+
     delta  = 4/100
 +
 
  
 
myManageHook = composeAll
 
myManageHook = composeAll
    [ className =? "MPlayer"       --> doFloat
+
              [ floatC "MPlayer"
     , className =? "Gimp"          --> doFloat
+
              , floatC "Gimp"
     , resource  =? "desktop_window" --> doIgnore
+
              , moveToC "Conkeror" "2"
    , resource =? "kdesktop"      --> doIgnore ] <+> manageDocks
+
              ]
 +
     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 h = dynamicLogWithPP $ defaultPP {
 
              ppCurrent  = dzenColor "black" "white" . pad
 
            , ppVisible  = dzenColor "white" "#333333" . pad
 
            , ppHidden  = dzenColor "white"  "#333333" . pad
 
            , ppHiddenNoWindows = dzenColor "#777777"  "#333333" . pad
 
            , ppUrgent  = dzenColor "red" "yellow"
 
            , ppWsSep    = ""
 
            , ppSep      = ""
 
            , ppLayout  = dzenColor "white" "#333333" .
 
                          (\ x -> fill (case x of
 
                                          "Tall"              -> icon "tall.xbm"
 
                                          "Mirror Tall"        -> icon "mtall.xbm"
 
                                          "Full"              -> icon "full.xbm"
 
                                          _                    -> pad x) 4)
 
            , ppTitle    = ("^fg(white) " ++) . dzenEscape
 
            , ppOutput  = hPutStrLn h
 
            }
 
    where
 
      icon h = "^i(/home/deniz/usr/share/dzen2/icons/" ++ h ++ ")"
 
      fill :: String -> Int -> String
 
      fill h i = "^p(" ++ show i ++ ")" ++ h ++ "^p(" ++ show i ++ ")"
 
  
myStatusBar = "dzen2 -fn '-*-terminus-*-*-*-*-12-*-*-*-*-*-*-*' -bg '#222222' -fg '#777777' -h 16 -w 1280 -sa c -e '' -ta l"
+
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 din <- spawnPipe myStatusBar
+
 
 +
main = do xmobar <- spawnPipe "xmobar"
 
           xmonad $ defaultConfig {
 
           xmonad $ defaultConfig {
                     
 
 
                       terminal          = "urxvtc",
 
                       terminal          = "urxvtc",
 
                       focusFollowsMouse  = True,
 
                       focusFollowsMouse  = True,
                       borderWidth        = 1,
+
                       borderWidth        = 2,
 
                       modMask            = mod4Mask,
 
                       modMask            = mod4Mask,
                       numlockMask        = mod2Mask,
+
                       numlockMask        = 0,
                       workspaces        = ["irc","web","dev","4","5","6","7","warez","music"],
+
                       workspaces        = [ show x | x <- [1..9] ],
                       normalBorderColor  = "#000000",
+
                       normalBorderColor  = "#444",
                       focusedBorderColor = "#ff0000",
+
                       focusedBorderColor = "#f00",
 
+
                      -- key bindings
+
 
                       keys              = myKeys,
 
                       keys              = myKeys,
 
                       mouseBindings      = myMouseBindings,
 
                       mouseBindings      = myMouseBindings,
 
+
                       layoutHook        = myLayoutHook,
                      -- hooks, layouts
+
                       layoutHook        = myLayout,
+
 
                       manageHook        = myManageHook,
 
                       manageHook        = myManageHook,
                       logHook            = myLogHook din
+
                       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
                     }