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.)
(Updated for 0.7.)
Line 1: Line 1:
<haskell>--
+
<haskell>import XMonad
-- ~/.xmonad/xmonad.hs
+
import System.Exit
--
+
import XMonad.Hooks.DynamicLog
 
+
import XMonad.Hooks.ManageDocks
-- import the necessary libraries
+
import XMonad.Util.Run (spawnPipe)
 
+
import System.IO (hPutStrLn)
import XMonad
+
import XMonad.ManageHook
+
import XMonad.Operations
+
import XMonad.Actions.CycleWS
+
import XMonad.Actions.DwmPromote
+
import XMonad.Actions.RotSlaves
+
import XMonad.Actions.RotView
+
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 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\""
+
dmenuExec =
myIconsDir  = "/home/deniz/usr/share/dzen2/icons"
+
    "exe=`dmenu_path | dmenu -b -nb black -nf white -sb gray -sf black` && eval \"exec $exe\""
myStatusBar = "dzen2 -fn '-*-terminus-*-*-*-*-12-*-*-*-*-*-*-*' -bg '#222222' -fg '#777777' -h 16 -w 1280 -sa c -e '' -ta l"
+
  
main = do din <- spawnPipe myStatusBar
+
myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
          xmonad $ defaultConfig
+
    [ ((modMask,               xK_Return), spawn $ XMonad.terminal conf)
                    { borderWidth        = 2
+
    , ((modMask,              xK_p    ), spawn dmenuExec)
                    , normalBorderColor  = "#000000"
+
    , ((modMask .|. shiftMask, xK_c    ), kill)
                    , focusedBorderColor = "#dddddd"
+
    , ((modMask,               xK_space ), sendMessage NextLayout)
                    , workspaces        =
+
    , ((modMask .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
                        ["1:main", "2:web", "3:dev"] ++
+
    , ((modMask,              xK_n    ), refresh)
                        map show [4..7] ++ ["8:warez","9:music"]
+
    , ((modMask,              xK_Tab  ), windows W.focusDown)
                    , terminal          = "urxvtc"
+
    , ((modMask,               xK_j    ), windows W.focusDown)
                    , modMask           = mod4Mask
+
    , ((modMask,              xK_e    ), windows W.focusDown)
                    , defaultGaps        = [(16,16,0,0)]
+
    , ((modMask,              xK_Right ), windows W.focusDown)
                    , manageHook        = myManageHook
+
    , ((modMask,              xK_k    ), windows W.focusUp  )
                    , logHook            = dynamicLogWithPP $ myPP din
+
    , ((modMask,              xK_Left  ), windows W.focusUp  )
                    , layoutHook        = toggleLayouts (noBorders Full) $
+
    , ((modMask,              xK_m    ), windows W.focusMaster  )
                                            -- smartBorders $ -- no borders if only window in ws (causes flickering)
+
    , ((modMask .|. shiftMask, xK_Return), windows W.swapMaster)
                                            tiled |||
+
    , ((modMask .|. shiftMask, xK_e    ), windows W.swapDown  )
                                            Mirror tiled
+
    , ((modMask .|. shiftMask, xK_j    ), windows W.swapDown  )
                                            ||| Full
+
    , ((modMask .|. shiftMask, xK_k    ), windows W.swapUp    )
                                            ||| Grid
+
    , ((modMask,              xK_h    ), sendMessage Shrink)
                                            ||| tabbed shrinkText defaultTConf
+
    , ((modMask,              xK_l    ), sendMessage Expand)
                                            ||| maximize (Tall 1 (3%100) (1%2))
+
    , ((modMask,              xK_t    ), withFocused $ windows . W.sink)
                    , keys               = \c -> myKeys c `M.union` keys defaultConfig c
+
    , ((modMask              , xK_b    ), sendMessage ToggleStruts)
                    , mouseBindings      = \c -> myMouse c `M.union` mouseBindings defaultConfig c
+
    , ((modMask .|. shiftMask, xK_q    ), io (exitWith ExitSuccess))
                    }
+
    , ((modMask              , xK_q    ),
                    where
+
          broadcastMessage ReleaseResources >> restart "xmonad" True)
                      tiled  = Tall nmaster delta ratio
+
    ]
                      nmaster = 1
+
    ++
                      ratio  = 50%100
+
    [((m .|. modMask, k), windows $ f i)
                      delta  = 5%100
+
        | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
 +
        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
  
-- application control
+
myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
--
+
     [ ((modMask, button1), (\w -> focus w >> mouseMoveWindow w))
myManageHook :: ManageHook
+
     , ((modMask, button2), (\w -> focus w >> windows W.swapMaster))
myManageHook = composeAll . concat $
+
     , ((modMask, button3), (\w -> focus w >> mouseResizeWindow w))
     [ [ className  =? c                --> doFloat | c <- myFloats]
+
    , [ 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") ]
+
 
     ]
 
     ]
 +
 +
myLayout = avoidStruts (tall ||| Mirror tall ||| Full)
 +
  where
 +
    tall  = Tall nmaster delta ratio
 +
    nmaster = 1
 +
    ratio  = 1/2
 +
    delta  = 2/100
 +
 +
myManageHook = composeAll
 +
    [ className =? "MPlayer"        --> doFloat
 +
    , className =? "Gimp"          --> doFloat
 +
    , resource  =? "desktop_window" --> doIgnore
 +
    , resource  =? "kdesktop"      --> doIgnore ] <+> manageDocks
 +
 +
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
 
     where
        myIgnores       = []
+
       icon h = "^i(/home/deniz/usr/share/dzen2/icons/" ++ h ++ ")"
        myFloats        = ["feh",
+
      fill :: String -> Int -> String
                          "GIMP",
+
      fill h i = "^p(" ++ show i ++ ")" ++ h ++ "^p(" ++ show i ++ ")"
                          "gimp",
+
                          "Pidgin",
+
                          "Dia"]
+
        myOtherFloats  = ["Bon Echo Preferences",
+
                          "Mail/News Preferences",
+
                          "Bon Echo - Restore Previous Session"]
+
  
-- modify/add default key binds
+
myStatusBar = "dzen2 -fn '-*-terminus-*-*-*-*-12-*-*-*-*-*-*-*' -bg '#222222' -fg '#777777' -h 16 -w 1280 -sa c -e '' -ta l"
--
+
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
+
main = do din <- spawnPipe myStatusBar
--
+
          xmonad $ defaultConfig {
myMouse (XConfig {modMask = modm}) = M.fromList $
+
                     
           [ ((modm, button3), (\w -> focus w >> Flex.mouseResizeWindow w))
+
                      terminal          = "urxvtc",
          , ((modm, button4), (\_ -> rotView True))
+
                      focusFollowsMouse  = True,
          , ((modm, button5), (\_ -> rotView False))
+
                      borderWidth        = 1,
          ]
+
                      modMask           = mod4Mask,
 +
                      numlockMask        = mod2Mask,
 +
                      workspaces        = ["irc","web","dev","4","5","6","7","warez","music"],
 +
                      normalBorderColor  = "#000000",
 +
                      focusedBorderColor = "#ff0000",
  
-- dynamiclog pretty printer for dzen
+
                      -- key bindings
-- ironic that this is "pretty printer" with such fugly code.
+
                       keys              = myKeys,
myPP h = defaultPP
+
                       mouseBindings      = myMouseBindings,
        { 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
+
        }
+
  
 +
                      -- hooks, layouts
 +
                      layoutHook        = myLayout,
 +
                      manageHook        = myManageHook,
 +
                      logHook            = myLogHook din
 +
                    }
 
</haskell>
 
</haskell>

Revision as of 11:34, 1 April 2008

import XMonad
import System.Exit
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Util.Run (spawnPipe)
import System.IO (hPutStrLn)
 
import qualified XMonad.StackSet as W
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 $
    [ ((modMask,               xK_Return), spawn $ XMonad.terminal conf)
    , ((modMask,               xK_p     ), spawn dmenuExec)
    , ((modMask .|. shiftMask, xK_c     ), kill)
    , ((modMask,               xK_space ), sendMessage NextLayout)
    , ((modMask .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
    , ((modMask,               xK_n     ), refresh)
    , ((modMask,               xK_Tab   ), windows W.focusDown)
    , ((modMask,               xK_j     ), windows W.focusDown)
    , ((modMask,               xK_e     ), windows W.focusDown)
    , ((modMask,               xK_Right ), windows W.focusDown)
    , ((modMask,               xK_k     ), windows W.focusUp  )
    , ((modMask,               xK_Left  ), windows W.focusUp  )
    , ((modMask,               xK_m     ), windows W.focusMaster  )
    , ((modMask .|. shiftMask, xK_Return), windows W.swapMaster)
    , ((modMask .|. shiftMask, xK_e     ), windows W.swapDown  )
    , ((modMask .|. shiftMask, xK_j     ), windows W.swapDown  )
    , ((modMask .|. shiftMask, xK_k     ), windows W.swapUp    )
    , ((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 $
    [ ((modMask, button1), (\w -> focus w >> mouseMoveWindow w))
    , ((modMask, button2), (\w -> focus w >> windows W.swapMaster))
    , ((modMask, button3), (\w -> focus w >> mouseResizeWindow w))
    ]
 
myLayout = avoidStruts (tall ||| Mirror tall ||| Full)
  where
     tall   = Tall nmaster delta ratio
     nmaster = 1
     ratio   = 1/2
     delta   = 2/100
 
myManageHook = composeAll
    [ className =? "MPlayer"        --> doFloat
    , className =? "Gimp"           --> doFloat
    , resource  =? "desktop_window" --> doIgnore
    , resource  =? "kdesktop"       --> doIgnore ] <+> manageDocks
 
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"
 
main = do din <- spawnPipe myStatusBar
          xmonad $ defaultConfig {
 
                       terminal           = "urxvtc",
                       focusFollowsMouse  = True,
                       borderWidth        = 1,
                       modMask            = mod4Mask,
                       numlockMask        = mod2Mask,
                       workspaces         = ["irc","web","dev","4","5","6","7","warez","music"],
                       normalBorderColor  = "#000000",
                       focusedBorderColor = "#ff0000",
 
                       -- key bindings
                       keys               = myKeys,
                       mouseBindings      = myMouseBindings,
 
                       -- hooks, layouts
                       layoutHook         = myLayout,
                       manageHook         = myManageHook,
                       logHook            = myLogHook din
                     }