Xmonad/Config archive/sereven's xmonad.hs one-host

From HaskellWiki
< Xmonad‎ | Config archive
Revision as of 08:39, 2 November 2008 by Sereven (talk | contribs) (Cut till fit in xselection)

Jump to: navigation, search
import XMonad
import qualified XMonad.StackSet as W
------                                          --
import qualified Data.Map as M
import Data.Ratio ((%)) -- for Layout.IM
------                                          --
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers(doCenterFloat)
import XMonad.Hooks.UrgencyHook
import XMonad.Hooks.DynamicLog
------                                          --
import XMonad.Actions.CycleWS
import XMonad.Actions.WindowGo
import XMonad.Actions.Warp
------                                          --
import XMonad.Layout.IM
import XMonad.Layout.Reflect
import XMonad.Layout.PerWorkspace
import XMonad.Layout.ResizableTile
import XMonad.Layout.WindowNavigation
import XMonad.Layout.NoBorders
import qualified XMonad.Layout.ToggleLayouts as TL
------                                          --
import XMonad.Prompt
import XMonad.Prompt.Shell
import XMonad.Prompt.RunOrRaise
------                                          --
import XMonad.Util.Run
import XMonad.Util.Scratchpad
import XMonad.Util.EZConfig


-- "Make it so, Mr. X!" --------------------

main = do
    dz <- spawnPipe $ dzenWithParams 0 1600 darkXPC
    let conf  = sConfig "/home/gvg" dz
    let sKeys = keysWithPath "/home/gvg" conf
    xmonad $ withUrgencyHook NoUrgencyHook $
      conf {startupHook = return () >> checkKeymap conf sKeys}
      `additionalKeysP` sKeys

    -- using this XConfig

sConfig hm dzh = defaultConfig
    { workspaces         = sWorkspaces
    , manageHook         = sManageHook
    , layoutHook         = sLayout
    , logHook            = dynamicLogWithPP $ dzdarkPP hm dzh
    , borderWidth        = 1
    , focusedBorderColor = "cornsilk3"
    , normalBorderColor  = "gray10"
    , focusFollowsMouse  = True
    , modMask            = mod4Mask
    , terminal           = "urxvtc"
    }


-- (frequently edited bits nearer the top) -------

keysWithPath hm cfg =

    [ ("M-<F1>",  shellPrompt darkXPC)
    , ("M-<F2>",  runOrRaisePrompt darkXPC)
    , ("M-<F3>",  scratchpadSpawnAction cfg)
    , ("M-<F12>", spawn "xscreensaver-command -lock")

    , ("M-x f", runOrRaise "firefox" (className =? "Firefox"))
    , ("M-x o", runOrRaise "opera" (className =? "Opera"))
    , ("M-x r", runOrRaise (hm ++ "/bin/shfmRun") (title =? "shellfm"))
    , ("M-x h", runOrRaise "hback" (className =? "Hback"))
    , ("M-x g", spawn "gimp")
    ]
    ++ -- vi directional window navigation similar to XMonad defaults
    [ ("M-k", sendMessage $ Go U)
    , ("M-j", sendMessage $ Go D)
    , ("M-h", sendMessage $ Go L)
    , ("M-l", sendMessage $ Go R)
    , ("M-S-k", sendMessage $ Swap U)     -- shift shifts windows
    , ("M-S-j", sendMessage $ Swap D)
    , ("M-S-h", sendMessage $ Swap L)
    , ("M-S-l", sendMessage $ Swap R)
    , ("M-C-k", sendMessage MirrorExpand) -- ctrl controls size
    , ("M-C-j", sendMessage MirrorShrink)
    , ("M-C-h", sendMessage Shrink)
    , ("M-C-l", sendMessage Expand)
    ]
    ++ -- mod-<key> and mod-shift-<key> are as default (plus 0 and = too)
       -- mod-ctrl-<key> shifts focused window *and* view to <key>'s ws
    [ (addtlmods ++ "M-" ++ [key], action tag)
    |   (tag, key)  <- zip sWorkspaces "1234567890="
      , (addtlmods, action) <- [ ("", windows . W.greedyView)
                               , ("S-", windows . W.shift)
                               , ("C-", \x -> (windows . W.shift) x >> (windows . W.view) x)]
    ]
    ++ --  mod + m + {left arrow or 'a' key} does action with ws to "left"
    [ (m ++ "M-" ++ key, action) | key <- ["<L>","a"]
      , (m, action) <- [ ("", prevWS), ("S-", shiftToPrev), ("C-", shiftToPrev >> prevWS)]
    ]
    ++ -- mod + m + {right arrow or 'd' key} does action with ws to "right"
    [ (m ++ "M-" ++ key, action) | key  <- ["<R>","d"]
      , (m, action) <- [ ("", nextWS), ("S-", shiftToNext), ("C-", shiftToNext >> nextWS)]
    ]
    ++
    [ ("M-<Space>", sendMessage TL.ToggleLayout ) -- noBorders Full
    , ("M-b", sendMessage ToggleStruts)
    , ("M-C-b", warpToScreen 0 (1/2) 0) -- open XM dzen slave; exit mouse manually to collapse :(
    , ("M-S-b", warpToScreen 0 0 0)  -- open sys dzen slave; exit mouse manually to collapse :(
    , ("M-m", warpToWindow 1 1) -- banish mouse to lower right of focused window
    ]

sWorkspaces = ["'%", "%", "%'"] ++ ["'*", "*", "*'"] ++ ["c", "m", "#"] ++ ["@", "SP"]

sManageHook = composeAll
    [ doF avoidMaster
    , scratchpadManageHookDefault

    , title =? "shellfm"        --> doShift "'*"
    , className =? "Gimp"       --> doShift "*" -- don't float, IM layout
    , className =? "MPlayer"    --> doShift "*'"

    , title =? ""               --> doFloat     -- SOE graphics
    , title =? "shellfm"        --> doFloat
    , className =? "Hback"      --> doCenterFloat
    , className =? "MPlayer"    --> doFloat
    , className =? "XFontSel"   --> doCenterFloat
    , className =? "Xmessage"   --> doCenterFloat
    ]
  where 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

sLayout  =
    avoidStruts $ configurableNavigation (noNavigateBorders) $
    TL.toggleLayouts (noBorders Full) $
    modWorkspace "*" reflectHoriz $ withIM (11%64) (Role "gimp-toolbox") $
    ResizableTall 2         -- default number of masters
                  (1/118)   -- resize increment
                  (11/20)   -- horizontal ratio: mstr/(mstr+slv)?
                  [5/4 -- master column ~ top/bottom?
                  ,5/4 -- no effect w/ 2 masters
                  ,5/4 -- slave  column ~ top/bottom
                  ]    -- then defaults to (repeat 1)

    -- [gimp] -- Combining gimp-toolbox and gimp-dock into one works
    -- well in IM layout roster column. Drag panes from gimp-dock or
    -- toolbox to top separator or bar of toolbox to add and re-arrange.


-- (dzen and prompt XPConfig) --------------

darkXPC = defaultXPConfig
    { font = "-*-dejavu sans mono-medium-r-*-*-17-*-*-*-*-*-*-*"
    , height   = 22
    , bgColor  = "black"
    , fgColor  = "cornsilk3"
    , bgHLight = "cornsilk3"
    , fgHLight = "black"
    , promptBorderWidth = 0
    }

-- adjust dzen position & width to screen; use XPConfig theming
dzenWithParams :: Int -> Int -> XPConfig -> String
dzenWithParams sx sw xpc =
    "dzen2 -x "  ++ show xpos
      ++ " -w "  ++ show width
      ++ " -h "  ++ (show $ height xpc)
      ++ " -fn '" ++ (font    xpc) ++ "'"
      ++ " -bg '" ++ (bgColor xpc) ++ "'"
      ++ " -fg '" ++ (fgColor xpc) ++ "'"
      ++ " -ta l"
      -- normal dzen config --
      ++ " -e 'onstart=lower'"
  where xpos  = sx +      sw * 11 `div` 32        -- a`div`b screenwidth empty to left
        width = sx + sw - sw * 7  `div` 64 - xpos -- and c`div`d to right
                                                  -- (space for .xinіtrc bar and tray)
 
stripDzen s = aux s [] -- strip dzen formatting to undo ppHidden
  where aux [] acc = acc
        aux x  acc = (\(good,bad) -> aux (dropDzen bad) (acc++good)) $ span (/= '^') x
            where dropDzen b = drop 1 $ dropWhile (/= ')') b
            -- dropDzen doesn't properly handle "^^" or non-dzen ')' in text

dzdarkPP  hm dzIn = defaultPP
    { ppCurrent         = wrap "^fg(#4d5)^p(;+7)^r(5x5)^p(+2;-7)^fg()" ""  . dzenColor "#bca" "" 
    , ppVisible         = ("^fg(#ab9)^p(;+7)^ro(5x5)^p(+2;-7)^fg()" ++)
    , ppHidden          = dzenColor "#786" ""
    , ppHiddenNoWindows = dzenColor "#554" ""
    , ppUrgent          = dzenColor "#d54" "" . (\s -> stripDzen s)
    , ppWsSep           = kernedsp
    , ppSep             = ""
    , ppExtras          = [xmonicon]
    , ppOrder           = \(ws:_:_:xs) ->  ["    "] ++ [ws] ++ xs
    , ppOutput          = hPutStrLn dzIn
    }
  where kernedsp = "^p(+12)"
        xpm path = wrap ("^i(" ++ path ++ "/.dzen/icons/") ".xpm)"
        xmonicon = io $ return . Just $
            kernedsp ++ "^p(;4)" ++ xpm hm "xmonad16" ++ "^p(;-4)" ++ kernedsp

    -- for layouts and titles use something like ppOrder = \(ws:l:t:xs) ->  [l,ws,t] ++ xs