aboutsummaryrefslogtreecommitdiffstats
path: root/XMonad
diff options
context:
space:
mode:
authorquesel <quesel@informatik.uni-oldenburg.de>2010-05-18 08:05:57 +0200
committerquesel <quesel@informatik.uni-oldenburg.de>2010-05-18 08:05:57 +0200
commit45ab6c08dfd51841d4c5d9b8062d27c345416c5e (patch)
treef7a95c69b13e7281f79d26acec1b89c15552c2b5 /XMonad
parentf75fb2b65f735ecd26597fba210ea76a2b510bcb (diff)
downloadXMonadContrib-45ab6c08dfd51841d4c5d9b8062d27c345416c5e.tar.gz
XMonadContrib-45ab6c08dfd51841d4c5d9b8062d27c345416c5e.tar.xz
XMonadContrib-45ab6c08dfd51841d4c5d9b8062d27c345416c5e.zip
This patch adds support for multiple master windows to X.L.Master
Ignore-this: 5c62202575966ee65e9b41ef41c30f94 darcs-hash:20100518060557-2216c-1863401668febf2c430576802860d069d22aa8ae.gz
Diffstat (limited to 'XMonad')
-rw-r--r--XMonad/Layout/Master.hs63
1 files changed, 47 insertions, 16 deletions
diff --git a/XMonad/Layout/Master.hs b/XMonad/Layout/Master.hs
index 1d470c0..5747f93 100644
--- a/XMonad/Layout/Master.hs
+++ b/XMonad/Layout/Master.hs
@@ -17,7 +17,8 @@ module XMonad.Layout.Master (
-- * Usage
-- $usage
- mastered
+ mastered,
+ multimastered
) where
import XMonad
@@ -34,6 +35,10 @@ import XMonad.Layout.LayoutModifier
--
-- > mastered (1/100) (1/2) $ Grid
--
+-- Or if you want multiple (here two) master windows from the beginning:
+--
+-- > multimastered 2 (1/100) (1/2) $ Grid
+--
-- This will use the left half of your screen for a master window and let
-- Grid manage the right half.
--
@@ -45,42 +50,68 @@ import XMonad.Layout.LayoutModifier
-- | Data type for LayoutModifier which converts given layout to a mastered
-- layout
-data AddMaster a = AddMaster Rational Rational deriving (Show, Read)
+data AddMaster a = AddMaster Int Rational Rational deriving (Show, Read)
-- | Modifier which converts given layout to a mastered one
+multimastered :: (LayoutClass l a) =>
+ Int -- ^ @k@, number of master windows
+ -> Rational -- ^ @delta@, the ratio of the screen to resize by
+ -> Rational -- ^ @frac@, what portion of the screen to use for the master window
+ -> l a -- ^ the layout to be modified
+ -> ModifiedLayout AddMaster l a
+multimastered k delta frac = ModifiedLayout $ AddMaster k delta frac
+
mastered :: (LayoutClass l a) =>
Rational -- ^ @delta@, the ratio of the screen to resize by
-> Rational -- ^ @frac@, what portion of the screen to use for the master window
-> l a -- ^ the layout to be modified
-> ModifiedLayout AddMaster l a
-mastered delta frac = ModifiedLayout $ AddMaster delta frac
+mastered delta frac = multimastered 1 delta frac
instance LayoutModifier AddMaster Window where
- modifyLayout (AddMaster delta frac) = applyMaster delta frac
+ modifyLayout (AddMaster k delta frac) = applyMaster k delta frac
modifierDescription _ = "Mastered"
- pureMess (AddMaster delta frac) m
- | Just Shrink <- fromMessage m = Just $ AddMaster delta (frac-delta)
- | Just Expand <- fromMessage m = Just $ AddMaster delta (frac+delta)
+ pureMess (AddMaster k delta frac) m
+ | Just Shrink <- fromMessage m = Just $ AddMaster k delta (frac-delta)
+ | Just Expand <- fromMessage m = Just $ AddMaster k delta (frac+delta)
+ | Just (IncMasterN d) <- fromMessage m = Just $ AddMaster (max 1 (k+d)) delta frac
pureMess _ _ = Nothing
-- | Internal function for adding a master window and let the modified
-- layout handle the rest of the windows
applyMaster :: (LayoutClass l Window) =>
- Rational
+ Int
+ -> Rational
-> Rational
-> S.Workspace WorkspaceId (l Window) Window
-> Rectangle
-> X ([(Window, Rectangle)], Maybe (l Window))
-applyMaster _ frac wksp rect = do
+applyMaster k _ frac wksp rect = do
let st= S.stack wksp
let ws = S.integrate' $ st
- if length ws > 1 then do
- let m = head ws
- let (mr, sr) = splitHorizontallyBy frac rect
- let nst = st>>= S.filter (m/=)
- wrs <- runLayout (wksp {S.stack = nst}) sr
- return ((m, mr) : fst wrs, snd wrs)
-
+ let n = length ws
+ if n > 1 then do
+ if(n<=k) then
+ return ((divideCol rect ws), Nothing)
+ else do
+ let m = take k ws
+ let (mr, sr) = splitHorizontallyBy frac rect
+ let nst = st>>= S.filter (\w -> not (w `elem` m))
+ wrs <- runLayout (wksp {S.stack = nst}) sr
+ return ((divideCol mr m) ++ (fst wrs), snd wrs)
else runLayout wksp rect
+
+-- | Shift rectangle down
+shiftD :: Position -> Rectangle -> Rectangle
+shiftD s (Rectangle x y w h) = Rectangle x (y+s) w h
+
+-- | Divide rectangle between windows
+divideCol :: Rectangle -> [a] -> [(a, Rectangle)]
+divideCol (Rectangle x y w h) ws = zip ws rects
+ where n = length ws
+ oneH = fromIntegral h `div` n
+ oneRect = Rectangle x y w (fromIntegral oneH)
+ rects = take n $ iterate (shiftD (fromIntegral oneH)) oneRect
+