aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad/Layout/LimitWindows.hs
diff options
context:
space:
mode:
authorAdam Vogt <vogt.adam@gmail.com>2009-06-19 07:27:31 +0200
committerAdam Vogt <vogt.adam@gmail.com>2009-06-19 07:27:31 +0200
commita0c7989fdfcbe3a1238e48fa4d3a10fa05fc8098 (patch)
treeb8e2f0d1c838bd32f74f4c225fe00e493f59d58b /XMonad/Layout/LimitWindows.hs
parentb578d52a5dcfa89ab65c027478dbb553df4c34e5 (diff)
downloadXMonadContrib-a0c7989fdfcbe3a1238e48fa4d3a10fa05fc8098.tar.gz
XMonadContrib-a0c7989fdfcbe3a1238e48fa4d3a10fa05fc8098.tar.xz
XMonadContrib-a0c7989fdfcbe3a1238e48fa4d3a10fa05fc8098.zip
Add L.LimitWindows layout modifier
Ignore-this: e91c07885f0ab662f70e0ebd82fb7a5d darcs-hash:20090619052731-1499c-b68f6df5d8d5c750be9cc68c67a9b7e50c51e7dc.gz
Diffstat (limited to 'XMonad/Layout/LimitWindows.hs')
-rw-r--r--XMonad/Layout/LimitWindows.hs55
1 files changed, 55 insertions, 0 deletions
diff --git a/XMonad/Layout/LimitWindows.hs b/XMonad/Layout/LimitWindows.hs
new file mode 100644
index 0000000..9feb462
--- /dev/null
+++ b/XMonad/Layout/LimitWindows.hs
@@ -0,0 +1,55 @@
+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
+-----------------------------------------------------------------------------
+-- |
+-- Module : XMonad.Layout.LimitWindows
+-- Copyright : (c) 2009 Adam Vogt
+-- License : BSD-style (see xmonad/LICENSE)
+--
+-- Maintainer : vogt.adam@gmail.com
+-- Stability : unstable
+-- Portability : unportable
+--
+-- A layout modifier that limits the number of windows that can be shown.
+--
+-----------------------------------------------------------------------------
+
+module XMonad.Layout.LimitWindows (limitWindows,limitSlice) where
+
+import XMonad.Layout.LayoutModifier
+import XMonad
+import qualified XMonad.StackSet as W
+
+-- | Only display the first @n@ windows.
+limitWindows :: Int -> l a -> ModifiedLayout LimitWindows l a
+limitWindows n = ModifiedLayout (LimitWindows FirstN n)
+
+-- | Only display @n@ windows around the focused window. This makes sense with
+-- layouts that arrange windows linearily, like 'XMonad.Layout.Layout.Accordion'.
+limitSlice :: Int -> l a -> ModifiedLayout LimitWindows l a
+limitSlice n = ModifiedLayout (LimitWindows Slice n)
+
+data LimitWindows a = LimitWindows SliceStyle Int deriving (Read,Show)
+
+data SliceStyle = FirstN | Slice deriving (Read,Show)
+
+-- do the runLayout call in an environment with only the windows chosen by f ... ?
+instance LayoutModifier LimitWindows a where
+ modifyLayout (LimitWindows style n) ws r =
+ runLayout ws { W.stack = f n `fmap` W.stack ws } r
+ where f = case style of
+ FirstN -> firstN
+ Slice -> slice
+
+firstN :: Int -> W.Stack a -> W.Stack a
+firstN n st = W.Stack f (reverse u) d
+ where (u,f:d) = splitAt (min (n-1) $ length $ W.up st)
+ $ take n $ W.integrate st
+
+slice :: Int -> W.Stack t -> W.Stack t
+slice n (W.Stack f u d) =
+ W.Stack f (take (nu + unusedD) u)
+ (take (nd + unusedU) d)
+ where unusedD = max 0 $ nd - length d
+ unusedU = max 0 $ nu - length u
+ nd = div (n - 1) 2
+ nu = uncurry (+) $ divMod (n - 1) 2