Difference between revisions of "Xmonad/Config archive/sereven's xmonad.hs one-host"

From HaskellWiki
Jump to: navigation, search
m (Clean up, simplified a bit, nicer dzen strip fn, maybe instead of fromMaybe)
m
 
(7 intermediate revisions by one other user not shown)
Line 8: Line 8:
 
import XMonad.Hooks.DynamicLog
 
import XMonad.Hooks.DynamicLog
 
import XMonad.Hooks.ManageDocks
 
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers(doCenterFloat,composeOne,isFullscreen,doFullFloat,(-?>))
+
import XMonad.Hooks.ManageHelpers (doCenterFloat, isFullscreen, doFullFloat)
 
import XMonad.Hooks.UrgencyHook
 
import XMonad.Hooks.UrgencyHook
 
import XMonad.Layout.IM -- (m%n) can be (m/n) don't need Data.Ratio
 
import XMonad.Layout.IM -- (m%n) can be (m/n) don't need Data.Ratio
Line 27: Line 27:
 
import XMonad.Util.WorkspaceCompare (getSortByTag,getSortByIndex)
 
import XMonad.Util.WorkspaceCompare (getSortByTag,getSortByIndex)
   
modKey = mod4Mask
+
modm = mod4Mask
 
sWorkspaces = [ [x] | x <- ['A'..'I'] ] -- /3 MINIMUM/ (easy to mod num wss)
 
sWorkspaces = [ [x] | x <- ['A'..'I'] ] -- /3 MINIMUM/ (easy to mod num wss)
   
ws2 = head . drop 1 $ sWorkspaces
 
  +
ws2 = sWorkspaces !! 1
ws3 = head . drop 2 $ sWorkspaces
 
  +
ws3 = sWorkspaces !! 2
   
 
main = do
 
main = do
Line 37: Line 37:
 
home <- fmap (maybe "/home/svv/" (++"/") . lookup "HOME") getEnvironment
 
home <- fmap (maybe "/home/svv/" (++"/") . lookup "HOME") getEnvironment
 
conf <- withWindowNavigation (xK_k, xK_h, xK_j, xK_l) $
 
conf <- withWindowNavigation (xK_k, xK_h, xK_j, xK_l) $
withUrgencyHook NoUrgencyHook (
+
withUrgencyHook NoUrgencyHook $
 
defaultConfig
 
defaultConfig
{ modMask = modKey
+
{ modMask = modm
 
, focusFollowsMouse = True
 
, focusFollowsMouse = True
 
, terminal = "urxvtc"
 
, terminal = "urxvtc"
Line 49: Line 49:
 
, logHook = dynamicLogWithPP $ dzdarkPP home dz
 
, logHook = dynamicLogWithPP $ dzdarkPP home dz
 
, manageHook = sManageHook
 
, manageHook = sManageHook
} `additionalKeys` sKeys)
+
} `additionalKeys` sKeys `additionalKeysP` sKeysP
`additionalKeysP` sKeysP -- silly to use both, but.. meh..
+
-- silly to use both, but.. meh..
 
xmonad conf
 
xmonad conf
   
 
sKeys = -- need normal bindings for testing ScreenWorkspaces
 
sKeys = -- need normal bindings for testing ScreenWorkspaces
[ ((modKey .|. controlMask, xK_space), sendMessage TL.ToggleLayout )
+
[ ((modm .|. controlMask, xK_space), sendMessage TL.ToggleLayout )
, ((modKey,xK_b) , sendMessage ToggleStruts)
+
, ((modm,xK_b) , sendMessage ToggleStruts)
 
, ((shiftMask,xK_F1), shellPrompt darkXPC)
 
, ((shiftMask,xK_F1), shellPrompt darkXPC)
 
, ((shiftMask,xK_F2), runOrRaisePrompt darkXPC)
 
, ((shiftMask,xK_F2), runOrRaisePrompt darkXPC)
Line 61: Line 61:
   
 
-- for more screens, workspaces, or exploring ion style subframes
 
-- for more screens, workspaces, or exploring ion style subframes
, ((modKey, xK_backslash), selectWorkspace darkXPC)
+
, ((modm, xK_backslash), selectWorkspace darkXPC)
, ((modKey .|. shiftMask ,xK_BackSpace), removeWorkspace)
+
, ((modm .|. shiftMask ,xK_BackSpace), removeWorkspace)
, ((modKey , xK_F8), rescreen)
+
, ((modm , xK_F8), rescreen)
, ((modKey .|. shiftMask, xK_F8), layoutScreens 4 (Tall 2 (1/8) (1/2)))
+
, ((modm .|. shiftMask, xK_F8), layoutScreens 4 (Tall 2 (1/8) (1/2)))
 
]
 
]
   
Line 83: Line 83:
 
]
 
]
   
sManageHook = floatFullscreen <+> composeAll
+
sManageHook = composeAll
 
[ scratchpadManageHookDefault
 
[ scratchpadManageHookDefault
  +
, isFullscreen --> doFullFloat
 
, className =? "Gimp" --> doShift ws3 -- don't float
 
, className =? "Gimp" --> doShift ws3 -- don't float
 
, className =? "MPlayer" --> doShift ws2
 
, className =? "MPlayer" --> doShift ws2
Line 96: Line 97:
 
, className =? "Xmessage" --> doCenterFloat
 
, className =? "Xmessage" --> doCenterFloat
 
]
 
]
where floatFullscreen = composeOne [isFullscreen -?> doFullFloat]
 
   
 
sLayouts =
 
sLayouts =
Line 134: Line 134:
 
dzdarkPP hm dzIn = defaultPP
 
dzdarkPP hm dzIn = defaultPP
 
{ ppOutput = hPutStrLn dzIn
 
{ ppOutput = hPutStrLn dzIn
, ppCurrent = wrap (dzfg hlightCol "^p(;+7)^r(5x5)^p(+2;-7)") "" . dzfg currentCol
+
, ppCurrent = wrap (dzfg "#4d5" box) "" . dzfg "#bca"
, ppVisible = dzfg visibleCol . ("^p(;+7)^ro(5x5)^p(+2;-7)" ++)
+
, ppVisible = dzfg "#ab9" . (emptybox ++)
, ppHidden = dzfg hiddenCol
+
, ppHidden = dzfg "#786"
, ppHiddenNoWindows = dzfg fadedCol
+
, ppHiddenNoWindows = dzfg "#554"
, ppUrgent = dzfg urgentCol . (\s -> stripDzen s)
+
, ppUrgent = dzfg "#d54" . stripDzen
 
, ppWsSep = kernedsp
 
, ppWsSep = kernedsp
 
, ppSep = ""
 
, ppSep = ""
Line 144: Line 144:
 
, ppExtras = [xmonicon]
 
, ppExtras = [xmonicon]
 
, ppOrder = \(ws:_:_:xs) -> [" "] ++ [ws] ++ xs
 
, ppOrder = \(ws:_:_:xs) -> [" "] ++ [ws] ++ xs
} -- for layouts and titles use something like ppOrder = \(ws:l:t:xs) -> [l,ws,t] ++ xs
 
  +
}
 
-- for layouts and titles use something like ppOrder = \(ws:l:t:xs) -> [l,ws,t] ++ xs
 
where dzfg c = dzenColor c ""
 
where dzfg c = dzenColor c ""
hlightCol = "#4d5"
+
box = "^p(;+7)^r(5x5)^p(+2;-7)"
currentCol = "#bca"
+
emptybox = "^p(;+7)^ro(5x5)^p(+2;-7)"
visibleCol = "#ab9"
 
hiddenCol = "#786"
 
fadedCol = "#554"
 
urgentCol = "#d54"
 
 
kernedsp = "^p(+12)"
 
kernedsp = "^p(+12)"
 
xpm path = wrap ("^i(" ++ path ++ ".dzen/icons/") ".xpm)"
 
xpm path = wrap ("^i(" ++ path ++ ".dzen/icons/") ".xpm)"
Line 154: Line 155:
   
 
stripDzen :: String -> String -- strip dzen formatting to undo ppHidden
 
stripDzen :: String -> String -- strip dzen formatting to undo ppHidden
stripDzen s = strip s []
+
stripDzen = strip [] where
where strip [] acc = acc
+
strip keep [] = keep
strip x acc = let good = fst (span ('^' /=) x)
+
strip keep ('^':'^':x) = strip (keep ++ "^") x
bad = snd (span ('^' /=) x)
+
strip keep ('^':x) = strip keep (drop 1 . dropWhile (')' /=) $ x)
in strip (drop 1 . dropWhile (')' /=) $ bad) (acc ++ good)
+
strip keep x = let (good,x') = span ('^' /=) x
  +
in strip (keep ++ good) x'
 
</haskell>
 
</haskell>

Latest revision as of 19:13, 21 February 2010

------ sereven.0.8.base.xmonad.hs ----------------
import XMonad
import qualified XMonad.StackSet as W
import System.Environment (getEnvironment)
import XMonad.Actions.DynamicWorkspaces
import XMonad.Actions.WindowNavigation
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers (doCenterFloat, isFullscreen, doFullFloat)
import XMonad.Hooks.UrgencyHook
import XMonad.Layout.IM -- (m%n) can be (m/n) don't need Data.Ratio
import XMonad.Layout.LayoutScreens
import XMonad.Layout.NoBorders
import XMonad.Layout.PerWorkspace
import XMonad.Layout.Reflect
import XMonad.Layout.ResizableTile
import XMonad.Layout.ToggleLayouts as TL
import XMonad.Layout.TwoPane
import XMonad.Layout.WindowNavigation
import XMonad.Prompt
import XMonad.Prompt.Shell
import XMonad.Prompt.RunOrRaise
import XMonad.Util.EZConfig
import XMonad.Util.Run
import XMonad.Util.Scratchpad
import XMonad.Util.WorkspaceCompare (getSortByTag,getSortByIndex)

modm = mod4Mask
sWorkspaces = [ [x] | x <- ['A'..'I'] ] -- /3 MINIMUM/ (easy to mod num wss)

ws2 = sWorkspaces !! 1
ws3 = sWorkspaces !! 2

main = do
    dz <- spawnPipe $ dzenWith darkXPC
    home <- fmap (maybe "/home/svv/" (++"/") . lookup "HOME") getEnvironment
    conf <- withWindowNavigation (xK_k, xK_h, xK_j, xK_l) $
            withUrgencyHook NoUrgencyHook $
               defaultConfig
                  { modMask            = modm
                  , focusFollowsMouse  = True
                  , terminal           = "urxvtc"
                  , focusedBorderColor = "#694"
                  , normalBorderColor  = "black"
                  , borderWidth        = 1
                  , workspaces         = sWorkspaces
                  , layoutHook         = sLayouts
                  , logHook            = dynamicLogWithPP $ dzdarkPP home dz
                  , manageHook         = sManageHook
                  }  `additionalKeys` sKeys `additionalKeysP` sKeysP
                     -- silly to use both, but.. meh..
    xmonad conf

sKeys = -- need normal bindings for testing ScreenWorkspaces
    [ ((modm .|. controlMask, xK_space), sendMessage TL.ToggleLayout )
    , ((modm,xK_b)    , sendMessage ToggleStruts)
    , ((shiftMask,xK_F1), shellPrompt darkXPC)
    , ((shiftMask,xK_F2), runOrRaisePrompt darkXPC)
    , ((shiftMask,xK_F3), scratchpadSpawnActionTerminal "urxvt -pe tabbed")

    -- for more screens, workspaces, or exploring ion style subframes
    , ((modm,               xK_backslash), selectWorkspace darkXPC)
    , ((modm .|. shiftMask ,xK_BackSpace), removeWorkspace)
    , ((modm               ,   xK_F8), rescreen)
    , ((modm  .|. shiftMask,   xK_F8), layoutScreens 4 (Tall 2 (1/8) (1/2)))
    ]

sKeysP = -- TODO convert to additionalKeys
    [ ("M-C-k", sendMessage MirrorExpand)
    , ("M-C-j", sendMessage MirrorShrink)
    , ("M-C-h", sendMessage Shrink)
    , ("M-C-l", sendMessage Expand)
    ]
    ++ -- workspace and screen keys ------------------------------------
       -- mod-<key> and mod-shift-<key> are as default
       -- 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) -- or W.view)
                               , ("S-", windows . W.shift)
                               , ("C-", \x -> (windows . W.shift) x >> (windows . W.view) x)]
    ]

sManageHook = composeAll
    [ scratchpadManageHookDefault
    , isFullscreen              --> doFullFloat
    , className =? "Gimp"       --> doShift ws3 -- don't float
    , className =? "MPlayer"    --> doShift ws2
    , title =? "shellfm"        --> doShift ws2

    , title =? ""               --> doFloat     -- SOE graphics
    , title =? "shellfm"        --> doFloat
    , className =? "MPlayer"    --> doFloat
    , className =? "Hback"      --> doCenterFloat
    , className =? "XFontSel"   --> doCenterFloat
    , className =? "Xmessage"   --> doCenterFloat
    ]

sLayouts =
    smartBorders . avoidStruts $
    TL.toggleLayouts (noBorders Full) $
    modWorkspace ws3 reflectHoriz $ withIM (11/64) (Role "gimp-toolbox") $
    onWorkspace  ws2 (TwoPane (1/118) (11/15)) $
    ResizableTall 2         -- default number of masters
                  (1/118)   -- resize increment
                  (11/20)   -- horizontal ratio
                  [5/4 -- master column ~ top/bottom
                  ,5/4 -- no effect w/ 2 masters
                  ,5/4 -- slave  column ~ top/bottom
                  ]    -- then defaults to (repeat 1)

-- (theming, font, colors) ------------------
darkXPC :: XPConfig
darkXPC = defaultXPConfig
      { font = "-*-dejavu sans mono-medium-r-*-*-17-*-*-*-*-*-*-*"
      , height   = 28
      , bgColor  = "black"
      , fgColor  = "#684"
      , bgHLight = "#785"
      , fgHLight = "black"
      , promptBorderWidth = 0
      }

-- (dzen) ----------------------------------
dzenWith :: XPConfig -> String
dzenWith xpc = -- use XPConfig theming
    "dzen2 -xs 1 -ta l -h " ++ (show $ height xpc)
      ++ " -fn '" ++ font    xpc ++ "'"
      ++ " -bg '" ++ bgColor xpc ++ "'"
      ++ " -fg '" ++ fgColor xpc ++ "'"
      ++ " -e 'onstart=lower'"

dzdarkPP  hm dzIn = defaultPP
    { ppOutput          = hPutStrLn dzIn
    , ppCurrent         = wrap (dzfg "#4d5" box) ""  . dzfg "#bca"
    , ppVisible         = dzfg "#ab9" . (emptybox ++)
    , ppHidden          = dzfg "#786"
    , ppHiddenNoWindows = dzfg "#554"
    , ppUrgent          = dzfg "#d54" . stripDzen
    , ppWsSep           = kernedsp
    , ppSep             = ""
    , ppSort            = fmap (.scratchpadFilterOutWorkspace) getSortByIndex
    , ppExtras          = [xmonicon]
    , ppOrder           = \(ws:_:_:xs) ->  ["    "] ++ [ws] ++ xs
    }
    -- for layouts and titles use something like ppOrder = \(ws:l:t:xs) ->  [l,ws,t] ++ xs
  where dzfg c      = dzenColor c ""
        box = "^p(;+7)^r(5x5)^p(+2;-7)"
        emptybox = "^p(;+7)^ro(5x5)^p(+2;-7)"
        kernedsp    = "^p(+12)"
        xpm path = wrap ("^i(" ++ path ++ ".dzen/icons/") ".xpm)"
        xmonicon = io $ return . Just $
            kernedsp ++ "^p(;4)" ++ xpm hm "xmonad16" ++ "^p(;-4)" ++ kernedsp

stripDzen :: String -> String -- strip dzen formatting to undo ppHidden
stripDzen = strip [] where
    strip keep [] = keep
    strip keep ('^':'^':x) = strip (keep ++ "^") x
    strip keep ('^':x) = strip keep (drop 1 . dropWhile (')' /=) $ x)
    strip keep x = let (good,x') = span ('^' /=) x
        in strip (keep ++ good) x'