Personal tools

Xmonad/Config archive/skorpan's xmonad.hs

From HaskellWiki

< Xmonad | Config archive(Difference between revisions)
Jump to: navigation, search
(Updating to new configuration.)
(Updating.)
 
(2 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 -fn '-*-terminus-*-*-*-*-12-*-*-*-*-*-*-*' -b -nb '#000000' -nf '#FFFFFF' -sb '#000000'` && eval \"exec $exe\""
 
myIconsDir  = "/home/deniz/usr/share/dzen2/icons"
 
myStatusBar = "dzen2 -fn '-*-terminus-*-*-*-*-12-*-*-*-*-*-*-*' -bg '#222222' -fg '#777777' -h 16 -w 1280 -sa c -e '' -ta l"
 
  
main = do din <- spawnPipe myStatusBar
+
myKeys c = mkKeymap c $
          xmonad $ defaultConfig
+
          [ ("M-<Return>",  spawn $ XMonad.terminal c)
                    { borderWidth        = 2
+
          , ("M-<Space>",    sendMessage NextLayout)
                    , normalBorderColor  = "#000000"
+
          , ("M-<Tab>",     windows W.focusDown)
                    , focusedBorderColor = "#dddddd"
+
          , ("M-S-<Return>", windows W.swapMaster)
                    , workspaces        =
+
          , ("M-S-c",       kill)
                        ["1:main", "2:web", "3:dev"] ++
+
          , ("M-S-q",        io (exitWith ExitSuccess))
                        map show [4..7] ++ ["8:warez","9:music"]
+
          , ("M-b",         sendMessage ToggleStruts)
                    , terminal          = "urxvtc"
+
          , ("M-h",          sendMessage Shrink)
                    , modMask            = mod4Mask
+
          , ("M-l",         sendMessage Expand)
                    , defaultGaps        = [(16,16,0,0)]
+
          , ("M-n",         refresh)
                    , manageHook        = myManageHook
+
          , ("M-q",         broadcastMessage ReleaseResources >> restart "xmonad" True)
                    , logHook            = dynamicLogWithPP $ myPP din
+
          , ("M-t",         withFocused $ windows . W.sink)
                    , layoutHook        = toggleLayouts (noBorders Full) $
+
          , ("M-x",          shellPrompt defaultXPConfig)]
                                            -- smartBorders $ -- no borders if only window in ws (causes flickering)
+
          ++
                                            tiled |||
+
          [(m ++ k, windows $ f w)
                                            Mirror tiled
+
                | (w, k) <- zip (XMonad.workspaces c) (map show [1..9])
                                            ||| Full
+
          , (m, f) <- [("M-",W.greedyView), ("M-S-",W.shift)]]
                                            ||| 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
+
 
--
+
myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
myManageHook :: ManageHook
+
     [ ((modMask, button1), (\w -> focus w >> mouseMoveWindow w))
myManageHook = composeAll . concat $
+
     , ((modMask, button2), (\w -> focus w >> windows W.swapMaster))
     [ [ className  =? c                --> doFloat | c <- myFloats]
+
     , ((modMask, button3), (\w -> focus w >> mouseResizeWindow w))
    , [ title      =? t                --> doFloat | t <- myOtherFloats]
+
    , [ resource    =? r                --> doIgnore | r <- myIgnores]
+
     , [ className  =? "Firefox-bin"    --> doF (W.shift "2:web") ]
+
    , [ className  =? "Ktorrent"        --> doF (W.shift "8:warez") ]
+
     , [ className  =? "Sonata"          --> doF (W.shift "9:music") ]
+
 
     ]
 
     ]
    where
 
        myIgnores      = []
 
        myFloats        = ["feh",
 
                          "GIMP",
 
                          "gimp",
 
                          "Pidgin",
 
                          "Dia"]
 
        myOtherFloats  = ["Bon Echo Preferences",
 
                          "Mail/News Preferences",
 
                          "Bon Echo - Restore Previous Session"]
 
  
-- modify/add default key binds
 
--
 
myKeys conf@(XConfig {modMask = modm}) = M.fromList $
 
          [ ((modm, xK_p                  ), spawn dmenuExec)
 
            -- wtf
 
          , ((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_e                  ), windows W.focusDown)
 
          , ((modm, xK_o                  ), windows W.focusUp)
 
          , ((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
+
myLayoutHook = smartBorders $ avoidStruts $ tiled ||| Mirror tiled ||| Full
--
+
  where
myMouse (XConfig {modMask = modm}) = M.fromList $
+
    tiled  = Tall nmaster delta ratio
          [ ((modm, button3), (\w -> focus w >> Flex.mouseResizeWindow w))
+
    nmaster = 1
          , ((modm, button4), (\_ -> rotView True))
+
    ratio  = 1/2
          , ((modm, button5), (\_ -> rotView False))
+
    delta  = 4/100
          ]
+
  
-- dynamiclog pretty printer for dzen
 
-- ironic that this is "pretty printer" with such fugly code.
 
myPP h = defaultPP
 
        { ppCurrent = wrap "^fg(#ffffff)^bg(#888888)^p(3)" "^p(2)^fg()^bg()" . \wsId ->
 
                      if (':' `elem` wsId) then
 
                          drop 2 wsId
 
                      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 ->
 
                      if (':' `elem` wsId) then
 
                          drop 2 wsId
 
                      else wsId
 
        , ppHiddenNoWindows = id . \wsId ->
 
                              if (':' `elem` wsId) then
 
                                  drop 2 wsId
 
                              else wsId
 
        , ppSep    = " ^fg(#ffffff)^r(2x2)^p(2)^fg() "
 
        , ppWsSep  = " "
 
        , ppLayout  = (\x -> case x of
 
                                "Tall" ->
 
                                    " ^i(" ++ myIconsDir ++ "/tall.xbm) "
 
                                "Mirror Tall" ->
 
                                    " ^i(" ++ myIconsDir ++ "/mtall.xbm) "
 
                                "Full" ->
 
                                    " ^i(" ++ myIconsDir ++ "/full.xbm) "
 
                                "Grid" ->
 
                                    " ^i(" ++ myIconsDir ++ "/grid.xbm) "
 
                                "Tabbed" ->
 
                                    " ^i(" ++ myIconsDir ++ "/tabbed.xbm) "
 
                                "Maximize Tall" ->
 
                                    " ^i(" ++ myIconsDir ++ "/maximize.xbm) "
 
                      )
 
        , ppTitle  = dzenColor "white" ""
 
        , ppOutput  = hPutStrLn h
 
        }
 
  
 +
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
 +
                    }
 
</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
                     }