Personal tools

Xmonad/Config archive/twifkak's xmonad.hs

From HaskellWiki

< Xmonad | Config archive(Difference between revisions)
Jump to: navigation, search
(latest version of my config -- requires 1-minute-ago darcs)
m (fixed postfix operator nonsense for 6.10)
 
(5 intermediate revisions by one user not shown)
Line 1: Line 1:
 
<haskell>
 
<haskell>
  +
{-# LANGUAGE PatternGuards #-}
  +
 
-- XMonad Core
 
-- XMonad Core
 
import XMonad
 
import XMonad
import XMonad.Layouts
 
import XMonad.Operations
 
 
import qualified XMonad.StackSet as W
 
import qualified XMonad.StackSet as W
   
 
-- GHC hierarchical libraries
 
-- GHC hierarchical libraries
import Data.Bits ((.|.))
 
 
import qualified Data.Map as M
 
import qualified Data.Map as M
import Data.Ratio ((%))
+
import Data.IORef
import Graphics.X11.Xlib
 
import Graphics.X11.Xlib.Extras
 
   
 
-- Contribs
 
-- Contribs
 
import XMonad.Actions.CycleWS
 
import XMonad.Actions.CycleWS
  +
import XMonad.Actions.Promote
 
import XMonad.Actions.SwapWorkspaces
 
import XMonad.Actions.SwapWorkspaces
 
import XMonad.Actions.Submap
 
import XMonad.Actions.Submap
 
import XMonad.Actions.WindowBringer
 
import XMonad.Actions.WindowBringer
  +
import XMonad.Actions.WindowNavigation
 
import XMonad.Hooks.UrgencyHook
 
import XMonad.Hooks.UrgencyHook
  +
import XMonad.Hooks.SetWMName
  +
import XMonad.Layout.LayoutScreens
 
import XMonad.Layout.NoBorders
 
import XMonad.Layout.NoBorders
 
import XMonad.Layout.Tabbed
 
import XMonad.Layout.Tabbed
  +
import XMonad.Layout.TwoPane
 
import XMonad.Layout.WindowNavigation
 
import XMonad.Layout.WindowNavigation
  +
import XMonad.Prompt
  +
import XMonad.Prompt.Shell
  +
import XMonad.Prompt.Window
 
import XMonad.Util.EZConfig
 
import XMonad.Util.EZConfig
   
-- Get ready!
+
main = (xmonad =<<)
main = xmonad $ withUrgencyHook dzenUrgencyHook { args = ["-bg", "darkgreen", "-xs", "1"] }
+
$ withWindowNavigation (xK_w, xK_a, xK_s, xK_d)
$ defaultConfig
+
$ withUrgencyHookC dzenUrgencyHook { args = ["-bg", "darkgreen", "-xs", "1"],
{ workspaces = workspaces'
+
duration = seconds 1 }
, modMask = modMask'
+
urgencyConfig { remindWhen = Every (1 `minutes`) } -- only in post-0.8 darcs
, numlockMask = 0
+
$ defaultConfig
, layoutHook = layoutHook'
+
{ normalBorderColor = "#222222"
, terminal = "urxvtc || urxvt"
+
, focusedBorderColor = "#AA0000"
, mouseBindings = mouseBindings'
+
, workspaces = workspaces'
, eventHook = noFollow
+
, modMask = modMask'
, logHook = withUrgents (io . print)
+
, numlockMask = 0
}
+
, layoutHook = layoutHook'
`additionalKeys` keys'
+
, focusFollowsMouse = False
  +
, terminal = "urxvtc || urxvt"
  +
, mouseBindings = mouseBindings'
  +
, startupHook = setWMName "LG3D"
  +
}
  +
`additionalKeys` keys'
   
 
modMask' = mod4Mask
 
modMask' = mod4Mask
Line 42: Line 49:
 
layoutHook' =
 
layoutHook' =
 
configurableNavigation noNavigateBorders $
 
configurableNavigation noNavigateBorders $
  +
smartBorders $
 
layouts
 
layouts
   
Line 47: Line 55:
 
tiled
 
tiled
 
||| Mirror tiled
 
||| Mirror tiled
||| noBorders (tabbed shrinkText
+
||| noBorders (tabbedAlways shrinkText
defaultTConf { fontName = "-*-terminus-medium-r-normal--12-*-iso8859-1" })
+
defaultTheme { fontName = "-*-terminus-medium-r-normal--12-*-iso8859-1" })
 
where
 
where
 
tiled = Tall nmaster delta ratio
 
tiled = Tall nmaster delta ratio
 
nmaster = 2 -- The default number of windows in the master pane
 
nmaster = 2 -- The default number of windows in the master pane
ratio = 1%2 -- Default proportion of screen occupied by master pane
+
ratio = 1/2 -- Default proportion of screen occupied by master pane
delta = 3%100 -- Percent of screen to increment by when resizing panes
+
delta = 3/100 -- Percent of screen to increment by when resizing panes
   
noFollow CrossingEvent {} = return False
+
xpConfig = defaultXPConfig { position = Top }
noFollow _ = return True
+
winXpConfig = xpConfig { autoComplete = Just (seconds 0.5) }
   
 
keys' =
 
keys' =
[ ((modMask' .|. shiftMask, xK_d ), spawn "echo date | dzen2 -p 2 -xs 1") -- %! Print current date
+
[ ((modMask' , xK_p ), shellPrompt xpConfig )
, ((modMask' .|. mod1Mask, xK_m ), submap $ M.fromList -- %! MPD prefix key
+
, ((modMask' , xK_F1 ), spawn "date | dzen2 -p 2 -xs 1") -- %! Print current date
  +
, ((modMask' .|. mod1Mask , xK_m ), submap $ M.fromList -- %! MPD prefix key
 
[ ((modMask' .|. mod1Mask, xK_p ), spawn "mpc toggle") -- %! MPD: Toggle pause/play
 
[ ((modMask' .|. mod1Mask, xK_p ), spawn "mpc toggle") -- %! MPD: Toggle pause/play
 
, ((modMask' .|. mod1Mask, xK_m ), spawn "mpc | head -1 | dzen2 -p 2 -xs 1") -- %! MPD: Print the currently playing song
 
, ((modMask' .|. mod1Mask, xK_m ), spawn "mpc | head -1 | dzen2 -p 2 -xs 1") -- %! MPD: Print the currently playing song
Line 67: Line 75:
 
] )
 
] )
 
, ((modMask' .|. mod1Mask, xK_space ), withFocused $ \w -> hide w >> reveal w >> setFocusX w) -- %! force the window to redraw itself
 
, ((modMask' .|. mod1Mask, xK_space ), withFocused $ \w -> hide w >> reveal w >> setFocusX w) -- %! force the window to redraw itself
  +
, ((modMask' , xK_Return ), promote)
 
, ((modMask' , xK_i ), prevWS)
 
, ((modMask' , xK_i ), prevWS)
 
, ((modMask' , xK_o ), nextWS)
 
, ((modMask' , xK_o ), nextWS)
 
, ((modMask' .|. shiftMask, xK_i ), shiftToPrev)
 
, ((modMask' .|. shiftMask, xK_i ), shiftToPrev)
 
, ((modMask' .|. shiftMask, xK_o ), shiftToNext)
 
, ((modMask' .|. shiftMask, xK_o ), shiftToNext)
, ((modMask', xK_a ), sendMessage $ Go L)
+
, ((modMask' .|. mod1Mask , xK_i ), swapTo Prev)
, ((modMask', xK_w ), sendMessage $ Go U)
+
, ((modMask' .|. mod1Mask , xK_o ), swapTo Next)
, ((modMask', xK_s ), sendMessage $ Go D)
+
, ((modMask' , xK_c ), windowPromptGoto winXpConfig)
, ((modMask', xK_d ), sendMessage $ Go R)
+
, ((modMask' , xK_b ), windowPromptBring winXpConfig)
, ((modMask' .|. shiftMask, xK_g ), gotoMenu)
 
, ((modMask' .|. shiftMask, xK_b ), bringMenu)
 
 
, ((modMask' , xK_BackSpace), focusUrgent)
 
, ((modMask' , xK_BackSpace), focusUrgent)
  +
, ((modMask' .|. shiftMask, xK_BackSpace), clearUrgents) -- only in post-0.8 darcs
  +
  +
-- Fake multimonitor
  +
, ((modMask' .|. mod1Mask , xK_n ), layoutScreens 2 (TwoPane 0.5 0.5))
  +
, ((modMask' .|. mod1Mask , xK_b ), rescreen)
 
]
 
]
 
++
 
++
Line 97: Line 111:
 
mouseBindings' (XConfig {XMonad.modMask = modMask}) = M.fromList $
 
mouseBindings' (XConfig {XMonad.modMask = modMask}) = M.fromList $
 
-- ctrl-shift-button1 %! Set the window to floating mode and move by dragging
 
-- ctrl-shift-button1 %! Set the window to floating mode and move by dragging
[ ((controlMask .|. shiftMask, button1), (\w -> focus w >> mouseMoveWindow w))
+
[ ((controlMask .|. shiftMask, button1), (\w -> focus w >> mouseMoveWindow w >>
  +
windows W.shiftMaster))
   
 
-- ctrl-shift-button2 %! Raise the window to the top of the stack
 
-- ctrl-shift-button2 %! Raise the window to the top of the stack
, ((controlMask .|. shiftMask, button2), (\w -> focus w >> windows W.swapMaster))
+
, ((controlMask .|. shiftMask, button2), (\w -> focus w >> windows W.shiftMaster))
   
 
-- ctrl-shift-button3 %! Set the window to floating mode and resize by dragging
 
-- ctrl-shift-button3 %! Set the window to floating mode and resize by dragging
, ((controlMask .|. shiftMask, button3), (\w -> focus w >> mouseResizeWindow w))
+
, ((controlMask .|. shiftMask, button3), (\w -> focus w >> mouseResizeWindow w >>
  +
windows W.shiftMaster))
 
]
 
]
 
</haskell>
 
</haskell>

Latest revision as of 23:34, 2 January 2009

{-# LANGUAGE PatternGuards #-}
 
-- XMonad Core
import XMonad
import qualified XMonad.StackSet as W
 
-- GHC hierarchical libraries
import qualified Data.Map as M
import Data.IORef
 
-- Contribs
import XMonad.Actions.CycleWS
import XMonad.Actions.Promote
import XMonad.Actions.SwapWorkspaces
import XMonad.Actions.Submap
import XMonad.Actions.WindowBringer
import XMonad.Actions.WindowNavigation
import XMonad.Hooks.UrgencyHook
import XMonad.Hooks.SetWMName
import XMonad.Layout.LayoutScreens
import XMonad.Layout.NoBorders
import XMonad.Layout.Tabbed
import XMonad.Layout.TwoPane
import XMonad.Layout.WindowNavigation
import XMonad.Prompt
import XMonad.Prompt.Shell
import XMonad.Prompt.Window
import XMonad.Util.EZConfig
 
main = (xmonad =<<)
       $ withWindowNavigation (xK_w, xK_a, xK_s, xK_d)
       $ withUrgencyHookC dzenUrgencyHook { args = ["-bg", "darkgreen", "-xs", "1"],
                                            duration = seconds 1 }
                          urgencyConfig { remindWhen = Every (1 `minutes`) } -- only in post-0.8 darcs
       $ defaultConfig
         { normalBorderColor  = "#222222"
         , focusedBorderColor = "#AA0000"
         , workspaces         = workspaces'
         , modMask            = modMask'
         , numlockMask        = 0
         , layoutHook         = layoutHook'
         , focusFollowsMouse  = False
         , terminal           = "urxvtc || urxvt"
         , mouseBindings      = mouseBindings'
         , startupHook        = setWMName "LG3D"
         }
         `additionalKeys` keys'
 
modMask'    = mod4Mask
 
workspaces' = map show $ [1 .. 9 :: Int] ++ [0]
 
layoutHook' =
    configurableNavigation noNavigateBorders $
    smartBorders $
    layouts
 
layouts =
        tiled
    ||| Mirror tiled
    ||| noBorders (tabbedAlways shrinkText
                          defaultTheme { fontName = "-*-terminus-medium-r-normal--12-*-iso8859-1" })
  where
     tiled   = Tall nmaster delta ratio
     nmaster = 2     -- The default number of windows in the master pane
     ratio   = 1/2   -- Default proportion of screen occupied by master pane
     delta   = 3/100 -- Percent of screen to increment by when resizing panes
 
xpConfig = defaultXPConfig { position = Top }
winXpConfig = xpConfig { autoComplete = Just (seconds 0.5) }
 
keys' =
    [ ((modMask'              , xK_p        ), shellPrompt xpConfig )
    , ((modMask'              , xK_F1       ), spawn "date | dzen2 -p 2 -xs 1") -- %! Print current date
    , ((modMask' .|. mod1Mask , xK_m        ), submap $ M.fromList -- %! MPD prefix key
        [ ((modMask' .|. mod1Mask,  xK_p        ), spawn "mpc toggle") -- %! MPD: Toggle pause/play
        , ((modMask' .|. mod1Mask,  xK_m        ), spawn "mpc | head -1 | dzen2 -p 2 -xs 1") -- %! MPD: Print the currently playing song
        , ((modMask' .|. mod1Mask,  xK_comma    ), spawn "mpc prev") -- %! MPD: Go to previous song
        , ((modMask' .|. mod1Mask,  xK_period   ), spawn "mpc next") -- %! MPD: Go to next song
        ] )
    , ((modMask' .|. mod1Mask,  xK_space    ), withFocused $ \w -> hide w >> reveal w >> setFocusX w) -- %! force the window to redraw itself
    , ((modMask'              , xK_Return   ), promote)
    , ((modMask'              , xK_i        ), prevWS)
    , ((modMask'              , xK_o        ), nextWS)
    , ((modMask' .|. shiftMask, xK_i        ), shiftToPrev)
    , ((modMask' .|. shiftMask, xK_o        ), shiftToNext)
    , ((modMask' .|. mod1Mask , xK_i        ), swapTo Prev)
    , ((modMask' .|. mod1Mask , xK_o        ), swapTo Next)
    , ((modMask'              , xK_c        ), windowPromptGoto  winXpConfig)
    , ((modMask'              , xK_b        ), windowPromptBring winXpConfig)
    , ((modMask'              , xK_BackSpace), focusUrgent)
    , ((modMask' .|. shiftMask, xK_BackSpace), clearUrgents) -- only in post-0.8 darcs
 
    -- Fake multimonitor
    , ((modMask' .|. mod1Mask , xK_n        ), layoutScreens 2 (TwoPane 0.5 0.5))
    , ((modMask' .|. mod1Mask , xK_b        ), rescreen)
    ]
    ++
    -- modMask'-[1..0] %! Switch to workspace N
    -- modMask'-shift-[1..0] %! Move client to workspace N
    [((m .|. modMask', k), windows $ f i)
        | (i, k) <- zip workspaces' $ [xK_1 .. xK_9] ++ [xK_0]
        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
    ++
    -- modMask'-{e,r} %! Switch to physical/Xinerama screens 1 or 2
    -- modMask'-shift-{e,r} %! Move client to screen 1 or 2
    [((m .|. modMask', key), screenWorkspace sc >>= flip whenJust (windows . f))
        | (key, sc) <- zip [xK_e, xK_r] [0..]
        , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
    ++
    [((modMask' .|. mod1Mask, k), windows $ swapWithCurrent i)
        | (i, k) <- zip workspaces' $ [xK_1 .. xK_9] ++ [xK_0]]
 
-- I have "Emulate three button mouse" turned on in Darwin X11, so mod4 (Apple) right-clicks.
-- Use ctrl-shift, instead.
mouseBindings' (XConfig {XMonad.modMask = modMask}) = M.fromList $
    -- ctrl-shift-button1 %! Set the window to floating mode and move by dragging
    [ ((controlMask .|. shiftMask, button1), (\w -> focus w >> mouseMoveWindow w >>
                                                               windows W.shiftMaster))
 
    -- ctrl-shift-button2 %! Raise the window to the top of the stack
    , ((controlMask .|. shiftMask, button2), (\w -> focus w >> windows W.shiftMaster))
 
    -- ctrl-shift-button3 %! Set the window to floating mode and resize by dragging
    , ((controlMask .|. shiftMask, button3), (\w -> focus w >> mouseResizeWindow w >>
                                                               windows W.shiftMaster))
    ]