Personal tools

Xmonad/Config archive/31d1's xmonad.hs

From HaskellWiki

< Xmonad | Config archive(Difference between revisions)
Jump to: navigation, search
(since gwern so nicely caught a change that broke my config, making sure to keep this current)
Line 30: Line 30:
 
import XMonad.Layout.ToggleLayouts
 
import XMonad.Layout.ToggleLayouts
 
import XMonad.Layout.WindowArranger
 
import XMonad.Layout.WindowArranger
  +
import XMonad.Layout.Mosaic
   
 
import XMonad.Prompt
 
import XMonad.Prompt
Line 41: Line 42:
 
import XMonad.Util.WorkspaceCompare
 
import XMonad.Util.WorkspaceCompare
 
import XMonad.Util.XSelection
 
import XMonad.Util.XSelection
  +
  +
-- for dbus (gnome-session hang)
  +
import System.Environment
  +
import System.Cmd
  +
import Control.Concurrent
   
 
myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
 
myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
Line 46: Line 52:
 
-- terminals
 
-- terminals
 
[ ((modMask, xK_Return), spawn $ XMonad.terminal conf)
 
[ ((modMask, xK_Return), spawn $ XMonad.terminal conf)
  +
, ((modMask .|. controlMask, xK_Return), spawn "/home/rupa/bin/randterm")
 
, ((modMask .|. shiftMask, xK_Return), spawn "urxvt -pe tabbed")
 
, ((modMask .|. shiftMask, xK_Return), spawn "urxvt -pe tabbed")
   
Line 52: Line 59:
   
 
-- file manager
 
-- file manager
, ((modMask, xK_Up ), runOrRaise
+
--, ((modMask, xK_Up ), runOrRaise "nautilus ~" (className =? "Nautilus"))
"nautilus ~" (className =? "Nautilus"))
+
--, ((modMask .|. shiftMask, xK_Up ), spawn "nautilus ~")
, ((modMask .|. shiftMask, xK_Up ), spawn "nautilus ~")
+
, ((modMask, xK_Up ), spawn "nautilus ~")
   
 
-- shorturl
 
-- shorturl
Line 124: Line 131:
 
-- Resize viewed windows to the correct size
 
-- Resize viewed windows to the correct size
 
, ((modMask, xK_n ), refresh)
 
, ((modMask, xK_n ), refresh)
  +
-- Reset layout of current workspace
  +
, ((modMask .|. shiftMask, xK_n ), setLayout $ XMonad.layoutHook conf)
  +
  +
  +
-- Mosaic
  +
, ((modMask , xK_a ), sendMessage Taller)
  +
, ((modMask , xK_z ), sendMessage Wider)
  +
, ((modMask .|. controlMask, xK_N ), sendMessage Reset)
  +
   
 
-- toggle focused window fullscreen
 
-- toggle focused window fullscreen
Line 240: Line 256:
 
-- layouts
 
-- layouts
 
myLayout = avoidStruts $ toggleLayouts (noBorders Full)
 
myLayout = avoidStruts $ toggleLayouts (noBorders Full)
(smartBorders (tiled ||| Mirror tiled ||| layoutHints (tabbed shrinkText myTab)))
+
(smartBorders (tiled ||| mosaic 2 [3,2] ||| Mirror tiled ||| layoutHints (tabbed shrinkText myTab)))
 
where
 
where
 
tiled = layoutHints $ ResizableTall nmaster delta ratio []
 
tiled = layoutHints $ ResizableTall nmaster delta ratio []
Line 258: Line 274:
 
, className =? "XVkbd" --> doIgnore
 
, className =? "XVkbd" --> doIgnore
 
, className =? "Cellwriter" --> doIgnore
 
, className =? "Cellwriter" --> doIgnore
  +
, className =? "Gtkdialog" --> doFloat
 
, resource =? "desktop_window" --> doIgnore
 
, resource =? "desktop_window" --> doIgnore
 
, isFullscreen --> doFullFloat
 
, isFullscreen --> doFullFloat
 
-- x y w h
 
-- x y w h
 
, scratchpadManageHook $ W.RationalRect 0 0 1 0.42
 
, scratchpadManageHook $ W.RationalRect 0 0 1 0.42
, manageDocks ]
+
, manageDocks ] <+> manageHook defaultConfig
   
 
-- let Gnome know about Xmonad actions
 
-- let Gnome know about Xmonad actions
 
myLogHook = ewmhDesktopsLogHookCustom scratchpadFilterOutWorkspace >> updatePointer Nearest
 
myLogHook = ewmhDesktopsLogHookCustom scratchpadFilterOutWorkspace >> updatePointer Nearest
   
main = xmonad $ defaultConfig
+
-- main = xmonad $ defaultConfig
{ terminal = "urxvt"
+
-- { terminal = "urxvt"
, borderWidth = 2
+
-- , borderWidth = 2
, normalBorderColor = "black"
+
-- , normalBorderColor = "black"
, focusedBorderColor = "orange"
+
-- , focusedBorderColor = "orange"
, focusFollowsMouse = True
+
-- , focusFollowsMouse = True
, modMask = mod4Mask
+
-- , modMask = mod4Mask
, keys = myKeys
+
-- , keys = myKeys
, mouseBindings = myMouseBindings
+
-- , mouseBindings = myMouseBindings
, layoutHook = myLayout
+
-- , layoutHook = myLayout
, handleEventHook = ewmhDesktopsEventHook
+
-- , handleEventHook = ewmhDesktopsEventHook
, logHook = myLogHook
+
-- , logHook = myLogHook
, manageHook = myManageHook <+> manageHook defaultConfig
+
-- , manageHook = myManageHook
}
+
-- }
  +
  +
-- for dbus (gnome-session hang)
  +
main = do
  +
env <- getEnvironment
  +
case lookup "DESKTOP_AUTOSTART_ID" env of
  +
Just id -> do
  +
forkIO $ (>> return ()) $ rawSystem "dbus-send" ["--session","--print-reply=string","--dest=org.gnome.SessionManager","/org/gnome/SessionManager","org.gnome.SessionManager.RegisterClient","string:xmonad","string:"++id]
  +
return ()
  +
Nothing -> return ()
  +
xmonad $ defaultConfig { terminal = "urxvt"
  +
, borderWidth = 2
  +
, normalBorderColor = "black"
  +
, focusedBorderColor = "orange"
  +
, focusFollowsMouse = True
  +
, modMask = mod4Mask
  +
, keys = myKeys
  +
, mouseBindings = myMouseBindings
  +
, layoutHook = myLayout
  +
, handleEventHook = ewmhDesktopsEventHook
  +
, logHook = myLogHook
  +
, manageHook = myManageHook
  +
}
   
 
</haskell>
 
</haskell>

Revision as of 19:23, 17 September 2009

-- rupa's xmonad.hs (darcs/gnome)
--
-- # .gnomerc
-- export WINDOW_MANAGER=/home/rupa/bin/xmonad
-- # easy way to get binary into gnome's path
-- ln -s /home/rupa/bin/xmonad /usr/local/bin
 
import XMonad
import qualified XMonad.StackSet as W
import qualified Data.Map        as M
import Data.Monoid
 
import XMonad.Actions.CycleWS
import XMonad.Actions.FlexibleResize as Flex
import XMonad.Actions.Search
import XMonad.Actions.UpdatePointer
import XMonad.Actions.WindowGo
import qualified XMonad.Actions.Submap as SM
 
import XMonad.Hooks.DynamicLog
import XMonad.Hooks.EwmhDesktops
import XMonad.Hooks.ManageDocks
import XMonad.Hooks.ManageHelpers
 
import XMonad.Layout.LayoutHints
import XMonad.Layout.NoBorders
import XMonad.Layout.ResizableTile
import XMonad.Layout.Tabbed
import XMonad.Layout.ToggleLayouts
import XMonad.Layout.WindowArranger
import XMonad.Layout.Mosaic
 
import XMonad.Prompt
import XMonad.Prompt.Input
import XMonad.Prompt.RunOrRaise
import XMonad.Prompt.Shell
import XMonad.Prompt.Window
 
import XMonad.Util.Run
import XMonad.Util.Scratchpad
import XMonad.Util.WorkspaceCompare
import XMonad.Util.XSelection
 
-- for dbus (gnome-session hang)
import System.Environment
import System.Cmd
import Control.Concurrent
 
myKeys conf@(XConfig {XMonad.modMask = modMask}) = M.fromList $
 
    -- terminals
    [ ((modMask,                 xK_Return), spawn $ XMonad.terminal conf)
    , ((modMask .|. controlMask, xK_Return), spawn "/home/rupa/bin/randterm")
    , ((modMask .|. shiftMask,   xK_Return), spawn "urxvt -pe tabbed")
 
    -- quake terminal
    , ((modMask,                 xK_Down  ), scratchpadSpawnAction conf)
 
    -- file manager
    --, ((modMask,                 xK_Up    ), runOrRaise "nautilus ~" (className =? "Nautilus"))
    --, ((modMask .|. shiftMask,   xK_Up    ), spawn "nautilus ~")
    , ((modMask,                 xK_Up    ), spawn "nautilus ~")
 
    -- shorturl
    , ((modMask,                 xK_c     ), spawn "/home/rupa/bin/short")
 
    -- shell/window prompts
    , ((modMask,                 xK_space ), runOrRaisePrompt mySP)
    , ((modMask .|. shiftMask,   xK_space ), shellPrompt mySP)
    , ((modMask .|. controlMask, xK_space), windowPromptGoto mySP)
 
    -- browser
    , ((modMask,               xK_b     ), runOrRaise
        "firefox" (className =? "Firefox"))
 
    -- send a mail
    , ((modMask,               xK_x     ), emailPrompt mySP ["[email protected]"])
 
    -- search prompt
    , ((modMask,               xK_p     ), SM.submap $ searchEngineMap $ promptSearch mySP)
    -- search selection
    , ((modMask .|. controlMask, xK_p   ), SM.submap $ searchEngineMap $ selectSearch)
    -- open selection as URL
    , ((modMask .|. shiftMask, xK_p     ), safePromptSelection "firefox")
 
    -- print screen
    , ((0,                     xK_Print ), unsafeSpawn "scrot -e 'mv $f ~/Pictures'")
    -- cap screen
    , ((modMask,               xK_Print ), unsafeSpawn "/home/rupa/ubin/cap")
 
    -- cycle through workspaces
    , ((modMask,               xK_Right ), moveTo Next (WSIs (return $ not . (=="SP") . W.tag)))
    , ((modMask,               xK_Left  ), moveTo Prev (WSIs (return $ not . (=="SP") . W.tag)))
 
    -- move windows through workspaces
    , ((modMask .|. shiftMask, xK_Right ), shiftTo Next (WSIs (return $ not . (=="SP") . W.tag)))
    , ((modMask .|. shiftMask, xK_Left  ), shiftTo Prev (WSIs (return $ not . (=="SP") . W.tag)))
    , ((modMask .|. controlMask, xK_Right), shiftTo Next EmptyWS)
    , ((modMask .|. controlMask, xK_Left), shiftTo Prev EmptyWS)
 
    -- Rotate through layouts
    , ((modMask,               xK_grave ), sendMessage NextLayout
    >> (dynamicLogString myPP >>= \d->safeSpawn "gnome-osd-client" [d]))
 
    -- Move focus to the next/previous window
    , ((modMask,               xK_j     ), windows W.focusDown)
    , ((modMask,               xK_Tab   ), windows W.focusDown)
    , ((mod1Mask,              xK_Tab   ), windows W.focusDown)
    , ((modMask,               xK_k     ), windows W.focusUp)
    , ((modMask .|. shiftMask, xK_Tab   ), windows W.focusUp)
    , ((mod1Mask .|. shiftMask, xK_Tab  ), windows W.focusUp)
 
    -- Swap the focused window with next/prev window
    , ((modMask .|. shiftMask, xK_j     ), windows W.swapDown)
    , ((modMask .|. shiftMask, xK_k     ), windows W.swapUp)
 
    -- Shrink/Expand the master area
    , ((modMask,               xK_h     ), sendMessage Shrink)
    , ((modMask,               xK_l     ), sendMessage Expand)
    , ((modMask .|. shiftMask, xK_h     ), sendMessage MirrorShrink)
    , ((modMask .|. shiftMask, xK_l     ), sendMessage MirrorExpand)
 
    -- Swap the focused window and the master window
    , ((modMask,            xK_semicolon), windows W.swapMaster)
 
    -- Increment/Deincrement the number of windows in the master area
    , ((modMask,               xK_comma ), sendMessage (IncMasterN 1))
    , ((modMask,               xK_period), sendMessage (IncMasterN (-1)))
 
    -- Resize viewed windows to the correct size
    , ((modMask,               xK_n     ), refresh)
    -- Reset layout of current workspace
    , ((modMask .|. shiftMask, xK_n     ), setLayout $ XMonad.layoutHook conf)
 
 
    -- Mosaic
    , ((modMask , xK_a                  ), sendMessage Taller)
    , ((modMask , xK_z                  ), sendMessage Wider)
    , ((modMask .|. controlMask, xK_N   ), sendMessage Reset)
 
 
    -- toggle focused window fullscreen
    , ((modMask,               xK_m     ), sendMessage (Toggle "Full")
    >> (dynamicLogString myPP >>= \d->safeSpawn "gnome-osd-client" [d]))
 
    -- Push window back into tiling
    , ((modMask,               xK_s     ), withFocused $ windows . W.sink)
    --, ((modMask .|. shiftMask, xK_s     ), sendMessage Arrange)
 
    -- toggle the status bar gap
    , ((modMask,               xK_f     ), sendMessage ToggleStruts)
 
    -- close focused window
    , ((modMask              , xK_w     ), kill)
 
    -- Restart xmonad
    , ((modMask              , xK_q     ),
        broadcastMessage ReleaseResources >> restart "xmonad" True)
    ]
 
    ++
    -- mod-[1..9], Switch to workspace N
    -- mod-shift-[1..9], Move client to workspace N
    [ ((m .|. modMask, k), windows $ f i)
        | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)] ]
 
    -- ++
    -- mod-{e,r,t}, Switch to physical/Xinerama screens 1, 2, or 3
    -- mod-shift-{e,r,t}, Move client to screen 1, 2, or 3
    -- [((m .|. modMask, key), screenWorkspace sc >>= flip whenJust (windows . f))
    --    | (key, sc) <- zip [xK_e, xK_r, xK_t] [0..]
    --    , (f, m) <- [(W.view, 0), (W.shift, shiftMask)] ]
 
-- search engines
delicious = searchEngine "delicious" "http://del.icio.us/tag/"
searchEngineMap method = M.fromList $
    [ ((0, xK_d), method delicious)
    , ((0, xK_g), method google)
    , ((0, xK_i), method imdb)
    , ((0, xK_w), method wikipedia) ]
 
myMouseBindings (XConfig {XMonad.modMask = modMask}) = M.fromList $
    -- mod-button1, Set the window to floating mode and move by dragging
    [ ((modMask, button1), (\w -> focus w >> mouseMoveWindow w))
    -- mod-button2, Raise the window to the top of the stack
    , ((modMask, button2), (\w -> focus w >> windows W.swapMaster))
    -- mod-button3, Set the window to floating mode and resize by dragging
    , ((modMask, button3), (\w -> focus w >> Flex.mouseResizeWindow w)) ]
 
-- decoration theme
myDeco = defaultTheme
    { activeColor         = "orange"
    , inactiveColor       = "#222222"
    , urgentColor         = "yellow"
    , activeBorderColor   = "orange"
    , inactiveBorderColor = "#222222"
    , urgentBorderColor   = "yellow"
    , activeTextColor     = "orange"
    , inactiveTextColor   = "#222222"
    , urgentTextColor     = "yellow"
    , decoHeight          = 10 }
 
-- tab theme
myTab = defaultTheme
    { activeColor         = "black"
    , inactiveColor       = "black"
    , urgentColor         = "yellow"
    , activeBorderColor   = "orange"
    , inactiveBorderColor = "#222222"
    , urgentBorderColor   = "black"
    , activeTextColor     = "orange"
    , inactiveTextColor   = "#222222"
    , urgentTextColor     = "yellow" }
 
-- shell prompt theme
mySP = defaultXPConfig
    { bgColor           = "black"
    , fgColor           = "white"
    , bgHLight          = "gray"
    , fgHLight          = "black"
    , borderColor       = "orange"
    , promptBorderWidth = 1
    , position          = Bottom
    , height            = 20
    --, autoComplete      = Just 1000
    , historySize       = 1000 }
 
-- dynamicLog theme (suppress everything but layout)
myPP = defaultPP
    { ppLayout  = (\ x -> case x of
      "Hinted ResizableTall"        -> "[|]"
      "Mirror Hinted ResizableTall" -> "[-]"
      "Hinted Tabbed Simplest"      -> "[T]"
      "Full"                 -> "[ ]"
      _                      -> x )
    , ppCurrent         = const ""
    , ppVisible         = const ""
    , ppHidden          = const ""
    , ppHiddenNoWindows = const ""
    , ppUrgent          = const ""
    , ppTitle           = const ""
    , ppWsSep           = ""
    , ppSep             = "" }
 
-- mailPrompt
emailPrompt :: XPConfig -> [String] -> X( )
emailPrompt c addrs =
    inputPromptWithCompl c "@" (mkComplFunFromList addrs) ?+ \to ->
    inputPrompt c "s" ?+ \subj ->
    inputPrompt c ">" ?+ \body ->
    io $ runProcessWithInput "mutt" ["-F", "~/.gmailrc", "-s", subj, to] (body ++ "\n")
         >> return ()
 
-- layouts
myLayout = avoidStruts $ toggleLayouts (noBorders Full)
    (smartBorders (tiled ||| mosaic 2 [3,2] ||| Mirror tiled ||| layoutHints (tabbed shrinkText myTab)))
    where
        tiled   = layoutHints $ ResizableTall nmaster delta ratio []
        nmaster = 1
        delta   = 2/100
        ratio   = 1/2
 
-- special windows
myManageHook = composeAll
    [ className =? "MPlayer"        --> doFloat
    , className =? "Gimp"           --> doFloat
    --, className =? "Gimp"           --> doF (W.shift "7")
    --, className =? "Gimp"           --> (liftX (findWorkspace getSortByIndex Next EmptyWS 1) >>= doF . W.shift)
    --, className =? "Gimp"           --> (liftX (findWorkspace getSortByIndex Next (WSIs myGimpFindingFunction) 1) >>= doF . W.shift)
    , title     =? "glxgears"       --> doFloat
    , className =? "Gnome-panel"    --> doIgnore
    , className =? "XVkbd"          --> doIgnore
    , className =? "Cellwriter"     --> doIgnore
    , className =? "Gtkdialog"      --> doFloat
    , resource  =? "desktop_window" --> doIgnore
    , isFullscreen                  --> doFullFloat
    --                                      x y w h
    , scratchpadManageHook $ W.RationalRect 0 0 1 0.42
    , manageDocks ] <+> manageHook defaultConfig
 
-- let Gnome know about Xmonad actions
myLogHook = ewmhDesktopsLogHookCustom scratchpadFilterOutWorkspace >> updatePointer Nearest
 
-- main = xmonad $ defaultConfig
--        { terminal           = "urxvt"
--        , borderWidth        = 2
--        , normalBorderColor  = "black"
--        , focusedBorderColor = "orange"
--        , focusFollowsMouse  = True
--        , modMask            = mod4Mask
--        , keys               = myKeys
--        , mouseBindings      = myMouseBindings
--        , layoutHook         = myLayout
--        , handleEventHook    = ewmhDesktopsEventHook
--        , logHook            = myLogHook
--        , manageHook         = myManageHook
--        }
 
-- for dbus (gnome-session hang)
main = do
    env <- getEnvironment
    case lookup "DESKTOP_AUTOSTART_ID" env of
        Just id -> do
            forkIO $ (>> return ()) $ rawSystem "dbus-send" ["--session","--print-reply=string","--dest=org.gnome.SessionManager","/org/gnome/SessionManager","org.gnome.SessionManager.RegisterClient","string:xmonad","string:"++id]
            return ()
        Nothing -> return ()
    xmonad $ defaultConfig { terminal           = "urxvt"
                           , borderWidth        = 2
                           , normalBorderColor  = "black"
                           , focusedBorderColor = "orange"
                           , focusFollowsMouse  = True
                           , modMask            = mod4Mask
                           , keys               = myKeys
                           , mouseBindings      = myMouseBindings
                           , layoutHook         = myLayout
                           , handleEventHook    = ewmhDesktopsEventHook
                           , logHook            = myLogHook
                           , manageHook         = myManageHook
                           }