aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad
diff options
context:
space:
mode:
authorRoman Cheplyaka <roma@ro-che.info>2008-01-16 21:50:20 +0100
committerRoman Cheplyaka <roma@ro-che.info>2008-01-16 21:50:20 +0100
commit0b79840152525619eecf9bbafa66657031178991 (patch)
treefba2b8575f5c74a0791ffcdb33b3f6e703d58811 /XMonad
parent2e6892ee7845d244d8173ac43c673466e6d07ab4 (diff)
downloadXMonadContrib-0b79840152525619eecf9bbafa66657031178991.tar.gz
XMonadContrib-0b79840152525619eecf9bbafa66657031178991.tar.xz
XMonadContrib-0b79840152525619eecf9bbafa66657031178991.zip
add XMonad.Actions.CycleSelectedLayouts
darcs-hash:20080116205020-3ebed-4cbcc5e67871dddb863909b153205417ebe1ce94.gz
Diffstat (limited to 'XMonad')
-rw-r--r--XMonad/Actions/CycleSelectedLayouts.hs51
1 files changed, 51 insertions, 0 deletions
diff --git a/XMonad/Actions/CycleSelectedLayouts.hs b/XMonad/Actions/CycleSelectedLayouts.hs
new file mode 100644
index 0000000..63f07ca
--- /dev/null
+++ b/XMonad/Actions/CycleSelectedLayouts.hs
@@ -0,0 +1,51 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : XMonad.Actions.CycleSelectedLayouts
+-- Copyright : (c) Roman Cheplyaka
+-- License : BSD3-style (see LICENSE)
+--
+-- Maintainer : Roman Cheplyaka <roma@ro-che.info>
+-- Stability : unstable
+-- Portability : unportable
+--
+-- This module allows to cycle through the given subset of layouts.
+--
+-----------------------------------------------------------------------------
+
+module XMonad.Actions.CycleSelectedLayouts (
+ -- * Usage
+ -- $usage
+ cycleThroughLayouts) where
+
+import XMonad
+import Data.List (findIndex)
+import Data.Maybe (fromMaybe)
+import XMonad.Layout.LayoutCombinators (JumpToLayout(..))
+import qualified XMonad.StackSet as S
+
+-- $usage
+-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
+--
+-- > import XMonad hiding ((|||))
+-- > import XMonad.Layout.LayoutCombinators ((|||))
+-- > import XMonad.Actions.CycleSelectedLayouts
+--
+-- > , ((modMask x, xK_t ), cycleThroughLayouts ["Tall", "Mirror Tall"])
+--
+-- Make sure you are using NewSelect from XMonad.Layout.LayoutCombinators,
+-- rather than the Select defined in xmonad core.
+
+cycleToNext :: (Eq a) => [a] -> a -> Maybe a
+cycleToNext lst a = do
+ -- not beautiful but simple and readable
+ ind <- findIndex (a==) lst
+ return $ lst !! if ind == length lst - 1 then 0 else ind+1
+
+-- | If the current layout is in the list, cycle to the next layout. Otherwise,
+-- apply the first layout from list.
+cycleThroughLayouts :: [String] -> X ()
+cycleThroughLayouts lst = do
+ winset <- gets windowset
+ let ld = description . S.layout . S.workspace . S.current $ winset
+ let newld = fromMaybe (head lst) (cycleToNext lst ld)
+ sendMessage $ JumpToLayout newld