]> ruderich.org/simon Gitweb - config/dotfiles.git/blobdiff - xmonad.hs
xmonad.hs: Fix nextLayoutIncluding changing layout on all workspaces.
[config/dotfiles.git] / xmonad.hs
index c71d10d2a9ec3e41b6728b013e87e7fa61f8d1fe..04257cb6dab0c809d9731b5de59f6daf77c19ad1 100644 (file)
--- a/xmonad.hs
+++ b/xmonad.hs
--- Xmonad configuration file.
+-- XMonad configuration file.
+--
+-- Should work fine with XMonad 0.7 and above.
 
 
-import XMonad
+-- "hiding" necessary for LayoutCombinators.
+import XMonad hiding ( (|||) )
+-- Necessary for reflectVert.
+import XMonad.Layout.Reflect
+-- Necessary for avoidMaster.
+import qualified XMonad.StackSet as W
+-- Necessary for toggleLayouts.
+import XMonad.Layout.ToggleLayouts
+-- Necessary for smartBorders.
+import XMonad.Layout.NoBorders
+-- Necessary for composeOne and -?>.
+import XMonad.Hooks.ManageHelpers
+-- Necessary for `additionalKeys`.
+import XMonad.Util.EZConfig
+-- Necessary for setWMName.
+import XMonad.Hooks.SetWMName
+-- Necessary for toggleWS.
+import XMonad.Actions.CycleWS
+-- Necessary for named.
+import XMonad.Layout.Named
+-- Necessary for JumpToLayout.
+import XMonad.Layout.LayoutCombinators
+
+
+-- Prevent new windows from spawning in the master pane. Taken from
+-- http://haskell.org/haskellwiki/Xmonad/Frequently_asked_questions on
+-- 2009-06-30. Thanks. Modified to not steal focus from the master pane when a
+-- new window is created, thanks to vav in #xmonad on Freenode (2010-04-15
+-- 21:59 CEST).
+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 r [] (t:rs)
+    otherwise           -> c
+
+-- Create my custom layout.
+--
+-- Only use horizontal (Mirror tiled) and fullscreen layouts, but allow
+-- switching to other layouts with bindings.
+--
+-- The master pane is at the top of the screen. To make sure new windows don't
+-- spawn in the master pane avoidMaster (see below) is used. Borders are only
+-- drawn when the screen has more then one window (smartBorders).
+--
+-- Thanks to jrick in #xmonad on Freenode (2009-06-29 22:19 CEST) for telling
+-- me how to remove the vertical tiled layout.
+--
+-- JumpToLayout (from LayoutCombinators) is used to jump to specific layouts,
+-- thanks to aavogt in #xmonad on Freenode (2011-06-12 22:13 CEST).
+--
+-- named is used to name layouts which allows switching to a specific layout
+-- (see below), thanks to vav in #xmonad on Freenode (2011-06-12 22:28 CEST).
+myLayoutHook = named "Default" (smartBorders $ Mirror tiled) ||| Full ||| named "Vertical" tiled
+    where
+    -- Default tiling algorithm partitions the screen into two panes.
+    tiled   = Tall nmaster delta ratio
+    -- The default number of windows in the master pane.
+    nmaster = 1
+    -- Percent of screen to increment by when resizing panes.
+    delta   = 3/100
+    -- Default proportion of screen occupied by master pane.
+    ratio   = 1/2
+
+-- Don't spawn new windows in the master pane (which is at the top of the
+-- screen). Thanks to dschoepe, aavogt and especially vav in #xmonad on
+-- Freenode (2009-06-30 02:10f CEST).
+--
+-- Also some applications are spawned on specific workspaces. Thanks to
+-- dschoepe and ivanm in #xmonad on Freenode (2009-07-12 14:50 CEST).
+myManageHook = composeOne
+    -- Browser on "2".
+    [ className =? "Iceweasel"          -?> doF (W.shift "2")
+    -- Miscellaneous on "3".
+    , className =? "Wireshark"          -?> doF (W.shift "3")
+    , title     =? "OpenOffice.org"     -?> doF (W.shift "3") -- splash screen
+    , className =? "OpenOffice.org 2.4" -?> doF (W.shift "3")
+    , className =? "Vncviewer"          -?> doF (W.shift "3")
+    -- Wine on "4".
+    , className =? "Wine"               -?> doF (W.shift "4")
+
+    -- Don't spawn new windows in the master pane.
+    , return True -?> doF avoidMaster
+    -- Prevent windows which get moved to other workspaces from removing the
+    -- focus of the currently selected window. Thanks to vav in #xmonad on
+    -- Freenode (2010-04-15 21:04 CEST).
+    , return True -?> doF W.focusDown
+    ]
+
+-- Switch to next layout, but skip all layouts not in layouts argument. This
+-- allows switching to some layouts with mappings but excluding them from
+-- meta-space (which gets mapped to this function). Thanks to aavogt in
+-- #xmonad on Freenode for this function (2011-06-13 12:45 CEST) and
+-- rootzlevel in #xmonad on Freenode for fixes (2011-06-13 15:20 CEST),
+-- modified to take list of layouts to switch to, not layouts to exclude.
+nextLayoutIncluding :: [String] -> X ()
+nextLayoutIncluding layouts = do
+    cws <- gets (W.workspace . W.current . windowset)
+    sendMessageWithNoRefresh NextLayout cws
+    nextLayoutIncluding' layouts
+
+nextLayoutIncluding' :: [String] -> X ()
+nextLayoutIncluding' layouts = do
+    cws <- gets (W.workspace . W.current . windowset)
+    if not $ (description $ W.layout cws) `elem` layouts
+        -- Skip over excluded layouts.
+        then do
+            sendMessageWithNoRefresh NextLayout cws
+            nextLayoutIncluding' layouts
+        -- Found allowed layout, show it.
+        else refresh
+
+myKeys = [
+        -- Switch to next layout, but only use the listed layouts.
+        ((mod4Mask, xK_space), nextLayoutIncluding ["Default", "Full"])
+        -- Switch to vertical tiled layout.
+      , ((mod4Mask, xK_v), sendMessage $ JumpToLayout "Vertical")
+
+        -- Switch to last active workspace, thanks to moljac024 in #xmonad on
+        -- Freenode (2010-12-18 14:45 CET).
+      , ((mod4Mask, xK_f), toggleWS)
+    ]
+    ++
+    -- When using multiple screens, switching to another workspace causes
+    -- Xmonad to pull the workspace to the current screen if it was also
+    -- displayed on another one. This is confusing for me so the following
+    -- code changes it to just switch to the screen where the workspace is
+    -- already displayed.
+    --
+    -- Thanks to the Xmonad FAQ, read on 2010-06-16 13:42 CEST
+    -- (http://www.haskell.org/haskellwiki/Xmonad/Frequently_asked_questions).
+    -- Thanks to MrElendig in #xmonad on Freenode (2010-06-17 17:16 CEST) to
+    -- use the default XMonad workspaces.
+    [((m .|. mod4Mask, k), windows $ f i)
+        | (i, k) <- zip (XMonad.workspaces defaultConfig) [xK_1 .. xK_9]
+        , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
 
 main = xmonad $ defaultConfig
-    -- Use Windows key as main key so it doesn't conflict with any other key
+    -- Use Windows key as main key as it doesn't conflict with any other key
     -- bindings.
     { modMask = mod4Mask
     -- Inactive borders are black - invisible on my black screen.
     , normalBorderColor = "#000000"
-    -- Active border is dark red.
-    , focusedBorderColor = "#990000" }
+    -- Active borders are dark red.
+    , focusedBorderColor = "#990000"
+    -- Use my layout and manage hooks (see above).
+    , layoutHook = myLayoutHook
+    , manageHook = myManageHook
+    -- Use unicode rxvt as my terminal.
+    , terminal = "urxvt"
+    -- Necessary for Java so it recognizes XMonad as tiling window manager.
+    , startupHook = setWMName "LG3D"
+    }
+    `additionalKeys` myKeys
+
+-- vim: nospell