Personal tools

Xmonad/Config archive/Gwern's xmonad.hs

From HaskellWiki

< Xmonad | Config archive(Difference between revisions)
Jump to: navigation, search
m (Xmonad/Config archive/Gwern's Config.hs moved to Xmonad/Config archive/Gwern's xmonad.hs)
(update)
Line 1: Line 1:
 
<haskell>
 
<haskell>
 
import Data.Bits (Bits((.|.)))
 
import Data.Bits (Bits((.|.)))
import Data.Map as M (fromList, union, Map())
+
import Data.Map as M (fromList, Map())
 
import XMonad
 
import XMonad
 
import XMonad.Actions.GridSelect (defaultGSConfig, goToSelected)
 
import XMonad.Actions.GridSelect (defaultGSConfig, goToSelected)
 
import XMonad.Actions.Search (google, isohunt, wayback, wikipedia, selectSearch, promptSearch)
 
import XMonad.Actions.Search (google, isohunt, wayback, wikipedia, selectSearch, promptSearch)
 
import XMonad.Actions.WindowGo (raiseMaybe, raiseBrowser, raiseEditor, runOrRaise)
 
import XMonad.Actions.WindowGo (raiseMaybe, raiseBrowser, raiseEditor, runOrRaise)
import XMonad.Config (defaultConfig)
 
 
import XMonad.Config.Gnome (gnomeConfig)
 
import XMonad.Config.Gnome (gnomeConfig)
 
import XMonad.Hooks.EwmhDesktops (ewmhDesktopsLogHook)
 
import XMonad.Hooks.EwmhDesktops (ewmhDesktopsLogHook)
import XMonad.Hooks.FadeInactive (fadeInactiveLogHook)
 
 
import XMonad.Hooks.ManageDocks (avoidStruts, manageDocks)
 
import XMonad.Hooks.ManageDocks (avoidStruts, manageDocks)
 
import XMonad.Hooks.UrgencyHook (withUrgencyHook, FocusHook(..))
 
import XMonad.Hooks.UrgencyHook (withUrgencyHook, FocusHook(..))
import XMonad.Layout (Full(..), Mirror(..), Tall(..), (|||))
 
import XMonad.Layout.Monitor (addMonitor, Property(ClassName))
 
 
import XMonad.Layout.NoBorders (smartBorders)
 
import XMonad.Layout.NoBorders (smartBorders)
import XMonad.Main (xmonad)
 
import XMonad.Operations (kill, windows, withFocused)
 
 
import XMonad.Prompt (greenXPConfig)
 
import XMonad.Prompt (greenXPConfig)
 
import XMonad.Prompt.Shell (shellPrompt, prompt, safePrompt)
 
import XMonad.Prompt.Shell (shellPrompt, prompt, safePrompt)
import XMonad.StackSet as W (focusUp, focusDown, shift, sink)
+
import XMonad.StackSet as W (focusUp, focusDown, sink)
import XMonad.Util.Run (unsafeSpawn, runInTerm)
+
import XMonad.Util.Run (unsafeSpawn, runInTerm, safeSpawnProg)
 
import XMonad.Util.XSelection (safePromptSelection)
 
import XMonad.Util.XSelection (safePromptSelection)
  +
import XMonad.Hooks.SetWMName (setWMName)
   
 
main :: IO ()
 
main :: IO ()
main = spawn "xcompmgr" >> xmonad myConfig
+
main = spawn "emacs --daemon" >> xmonad myConfig
 
where myConfig = withUrgencyHook FocusHook $ gnomeConfig { focusedBorderColor = "red"
 
where myConfig = withUrgencyHook FocusHook $ gnomeConfig { focusedBorderColor = "red"
, keys = \c -> myKeys c `M.union` keys defaultConfig c
+
, keys = \c -> myKeys c <+> keys defaultConfig c
, layoutHook = hideGnome $ avoidStruts $ smartBorders $ (Full ||| Mirror tiled ||| tiled )
+
, layoutHook = avoidStruts $ smartBorders (Full ||| Mirror tiled ||| tiled)
, logHook = ewmhDesktopsLogHook >> fadeInactiveLogHook 0xdddddddd
+
, logHook = ewmhDesktopsLogHook >> setWMName "LG3D"
 
, manageHook = myManageHook
 
, manageHook = myManageHook
 
, modMask = mod4Mask
 
, modMask = mod4Mask
 
, normalBorderColor = "grey"
 
, normalBorderColor = "grey"
, terminal = "gnome-terminal"
+
, terminal = "urxvt"
, XMonad.workspaces = ["web", "irc", "code", "5"] }
+
, XMonad.workspaces = ["web", "irc", "code", "4"] }
where tiled :: Tall a
+
where tiled = Tall 1 0.03 0.5
tiled = Tall 1 0.03 0.5
 
hideGnome = addMonitor (ClassName "gnome-panel") (Rectangle 0 0 0 0)
 
   
 
{- Important things to note: We specifically don't use 'managehook
 
{- Important things to note: We specifically don't use 'managehook
Line 41: Line 36:
 
gnome-panel; Firefox/Emacs/Irssi go to their designated workspaces. -}
 
gnome-panel; Firefox/Emacs/Irssi go to their designated workspaces. -}
 
myManageHook :: ManageHook
 
myManageHook :: ManageHook
myManageHook = composeAll [ moveToC "Emacs" "code",
+
myManageHook = composeAll [moveToC "Emacs" "code",
moveToC "Firefox" "web",
+
moveToC "gimp" "irc",
moveToT "irssi" "irc",
+
moveToC "Navigator" "web",
className =? "defcon.bin.x86" --> unfloat,
+
moveToC "Mnemosyne" "code",
className =? "Darwinia" --> unfloat,
+
moveToT "irssi" "irc",
className =? "gnome-panel" --> doIgnore ]
+
className =? "defcon.bin.x86" --> unfloat,
<+> manageDocks
+
className =? "Darwinia" --> unfloat,
where moveToC c w = className =? c --> doF (W.shift w)
+
className =? "gnome-panel" --> doIgnore,
moveToT t w = title =? t --> doF (W.shift w)
+
className =? "Mnemosyne" --> unfloat,
unfloat = ask >>= doF . W.sink
+
title =? "Brain Workshop 4.5" --> unfloat]
  +
<+> manageDocks
  +
where moveToC c w = className =? c --> doShift w
  +
moveToT t w = title =? t --> doShift w
  +
unfloat = ask >>= doF . W.sink
   
 
myKeys :: XConfig t -> M.Map (KeyMask, KeySym) (X ())
 
myKeys :: XConfig t -> M.Map (KeyMask, KeySym) (X ())
myKeys conf@(XConfig {modMask = m}) = M.fromList [ -- rebind standard keys
+
myKeys (XConfig {modMask = m, terminal = term}) = M.fromList [ -- rebind standard keys
 
((m .|. shiftMask,xK_p), shellPrompt greenXPConfig)
 
((m .|. shiftMask,xK_p), shellPrompt greenXPConfig)
 
, ((m, xK_k), kill)
 
, ((m, xK_k), kill)
Line 62: Line 57:
 
, ((m, xK_s), goToSelected defaultGSConfig)
 
, ((m, xK_s), goToSelected defaultGSConfig)
 
, ((m, xK_a), runOrRaise "amarok" (className =? "amarokapp"))
 
, ((m, xK_a), runOrRaise "amarok" (className =? "amarokapp"))
  +
, ((m .|. shiftMask,xK_a), safeSpawnProg "/home/gwern/bin/bin/amphetype")
 
, ((m, xK_b), safePrompt "firefox" greenXPConfig)
 
, ((m, xK_b), safePrompt "firefox" greenXPConfig)
 
, ((m .|. shiftMask,xK_b), safePromptSelection "firefox")
 
, ((m .|. shiftMask,xK_b), safePromptSelection "firefox")
, ((m, xK_c), unsafeSpawn term)
+
, ((m, xK_c), safeSpawnProg term)
 
, ((m .|. shiftMask,xK_c), prompt (term ++ " -e") greenXPConfig)
 
, ((m .|. shiftMask,xK_c), prompt (term ++ " -e") greenXPConfig)
, ((m .|. shiftMask,xK_d), raiseMaybe (runInTerm "--title=elinks" "elinks") (title =? "elinks"))
+
, ((m .|. shiftMask,xK_d), raiseMaybe (runInTerm "-title elinks" "elinks") (title =? "elinks"))
 
, ((m, xK_e), raiseEditor)
 
, ((m, xK_e), raiseEditor)
, ((m .|. shiftMask,xK_e), prompt "emacsclient -a emacs" greenXPConfig)
+
, ((m .|. shiftMask,xK_e), prompt "emacsclient -c -a emacs" greenXPConfig)
 
, ((m, xK_g), promptSearch greenXPConfig google)
 
, ((m, xK_g), promptSearch greenXPConfig google)
 
, ((m .|. shiftMask,xK_g), selectSearch google)
 
, ((m .|. shiftMask,xK_g), selectSearch google)
Line 77: Line 73:
 
, ((m, xK_y), promptSearch greenXPConfig wayback)
 
, ((m, xK_y), promptSearch greenXPConfig wayback)
 
, ((m .|. shiftMask,xK_y), selectSearch wayback)
 
, ((m .|. shiftMask,xK_y), selectSearch wayback)
  +
, ((m, xK_w), safeSpawnProg "/home/gwern/bin/bin/brainworkshop")
 
, ((m, xK_Print), unsafeSpawn "import -quality 90 -window root png:$HOME/xwd-$(date +%s)$$.png")
 
, ((m, xK_Print), unsafeSpawn "import -quality 90 -window root png:$HOME/xwd-$(date +%s)$$.png")
, ((m, xK_i), raiseMaybe (runInTerm "--title=irssi" "\"sh -c 'screen -r irssi'\"") (title =? "irssi"))
+
, ((m, xK_i), raiseMaybe (runInTerm "-title irssi" "sh -c 'screen -r irssi'") (title =? "irssi"))
-- We ask for zsh specifically so ~/.zshenv gets picked up and my
+
, ((m, xK_m), runOrRaise "mnemosyne" (className =? "Mnemosyne"))
-- expanded $PATH gets used; otherwise Mutt can't find needed scripts.
+
, ((m, xK_r), raiseMaybe (runInTerm "-title rtorrent" "sh -c 'screen -r rtorrent'") (title =? "rtorrent"))
, ((m, xK_m), raiseMaybe (runInTerm "--title=mutt" "\"zsh -c 'mutt'\"") (title =? "mutt"))
 
, ((m .|. shiftMask,xK_m), runOrRaise "mnemosyne" (className =? "Mnemosyne"))
 
, ((m, xK_r), raiseMaybe (runInTerm "--title='rtorrent'" "\"sh -c 'screen -r rtorrent'\"") (title =? "rtorrent"))
 
 
, ((m, xK_d), raiseBrowser) ]
 
, ((m, xK_d), raiseBrowser) ]
where term :: String
 
term = XMonad.terminal conf
 
 
</haskell>
 
</haskell>

Revision as of 21:55, 8 January 2010

import Data.Bits (Bits((.|.)))
import Data.Map as M (fromList, Map())
import XMonad
import XMonad.Actions.GridSelect (defaultGSConfig, goToSelected)
import XMonad.Actions.Search (google, isohunt, wayback, wikipedia, selectSearch, promptSearch)
import XMonad.Actions.WindowGo (raiseMaybe, raiseBrowser, raiseEditor, runOrRaise)
import XMonad.Config.Gnome (gnomeConfig)
import XMonad.Hooks.EwmhDesktops (ewmhDesktopsLogHook)
import XMonad.Hooks.ManageDocks (avoidStruts, manageDocks)
import XMonad.Hooks.UrgencyHook (withUrgencyHook, FocusHook(..))
import XMonad.Layout.NoBorders (smartBorders)
import XMonad.Prompt (greenXPConfig)
import XMonad.Prompt.Shell (shellPrompt, prompt, safePrompt)
import XMonad.StackSet as W (focusUp, focusDown, sink)
import XMonad.Util.Run (unsafeSpawn, runInTerm, safeSpawnProg)
import XMonad.Util.XSelection (safePromptSelection)
import XMonad.Hooks.SetWMName (setWMName)
 
main :: IO ()
main = spawn "emacs --daemon" >> xmonad myConfig
 where myConfig = withUrgencyHook FocusHook $ gnomeConfig { focusedBorderColor = "red"
                         , keys = \c -> myKeys c <+> keys defaultConfig c
                         , layoutHook =  avoidStruts $ smartBorders (Full ||| Mirror tiled ||| tiled)
                         , logHook    = ewmhDesktopsLogHook >> setWMName "LG3D"
                         , manageHook = myManageHook
                         , modMask = mod4Mask
                         , normalBorderColor  = "grey"
                         , terminal = "urxvt"
                         , XMonad.workspaces = ["web", "irc", "code", "4"] }
           where tiled = Tall 1 0.03 0.5
 
{- Important things to note: We specifically don't use 'managehook
   defaultConfig, since I don't like floating mplayer and I don't use the other
   specified applications. Otherwise, we have manageDocks there to allow use of
   gnome-panel; Firefox/Emacs/Irssi go to their designated workspaces. -}
myManageHook :: ManageHook
myManageHook = composeAll [moveToC "Emacs"     "code",
                           moveToC "gimp"      "irc",
                           moveToC "Navigator" "web",
                           moveToC "Mnemosyne" "code",
                           moveToT "irssi"     "irc",
                           className =? "defcon.bin.x86" --> unfloat,
                           className =? "Darwinia" --> unfloat,
                           className =? "gnome-panel" --> doIgnore,
                           className =? "Mnemosyne" --> unfloat,
                           title     =? "Brain Workshop 4.5" --> unfloat]
                           <+> manageDocks
          where moveToC c w = className =? c --> doShift w
                moveToT t w = title     =? t --> doShift w
                unfloat = ask >>= doF . W.sink
 
myKeys :: XConfig t -> M.Map (KeyMask, KeySym) (X ())
myKeys (XConfig {modMask = m, terminal = term}) = M.fromList [ -- rebind standard keys
            ((m .|. shiftMask,xK_p), shellPrompt greenXPConfig)
          , ((m,              xK_k), kill)
          , ((m,              xK_n), windows W.focusDown)
          , ((m,              xK_p), windows W.focusUp)
          , ((m,              xK_z), withFocused $ windows . W.sink) -- unfloat
          -- Custom bindings and commands
          , ((m,              xK_s), goToSelected defaultGSConfig)
          , ((m,              xK_a), runOrRaise "amarok" (className =? "amarokapp"))
          , ((m .|. shiftMask,xK_a), safeSpawnProg "/home/gwern/bin/bin/amphetype")
          , ((m,              xK_b), safePrompt "firefox" greenXPConfig)
          , ((m .|. shiftMask,xK_b), safePromptSelection "firefox")
          , ((m,              xK_c), safeSpawnProg term)
          , ((m .|. shiftMask,xK_c), prompt (term ++ " -e") greenXPConfig)
          , ((m .|. shiftMask,xK_d), raiseMaybe (runInTerm "-title elinks" "elinks") (title =? "elinks"))
          , ((m,              xK_e), raiseEditor)
          , ((m .|. shiftMask,xK_e), prompt "emacsclient -c -a emacs" greenXPConfig)
          , ((m,              xK_g), promptSearch greenXPConfig google)
          , ((m .|. shiftMask,xK_g), selectSearch google)
          , ((m,              xK_t), promptSearch greenXPConfig wikipedia)
          , ((m .|. shiftMask,xK_t), selectSearch wikipedia)
          , ((m,              xK_u), promptSearch greenXPConfig isohunt)
          , ((m .|. shiftMask,xK_u), selectSearch isohunt)
          , ((m,              xK_y), promptSearch greenXPConfig wayback)
          , ((m .|. shiftMask,xK_y), selectSearch wayback)
          , ((m,              xK_w), safeSpawnProg "/home/gwern/bin/bin/brainworkshop")
          , ((m,          xK_Print), unsafeSpawn "import -quality 90 -window root png:$HOME/xwd-$(date +%s)$$.png")
          , ((m,              xK_i), raiseMaybe (runInTerm "-title irssi" "sh -c 'screen -r irssi'") (title =? "irssi"))
          , ((m,              xK_m), runOrRaise "mnemosyne" (className =? "Mnemosyne"))
          , ((m,              xK_r), raiseMaybe (runInTerm "-title rtorrent" "sh -c 'screen -r rtorrent'") (title =? "rtorrent"))
          , ((m,              xK_d), raiseBrowser) ]