add new LayoutHelpers module.

This commit is contained in:
David Roundy 2007-06-22 14:29:50 +00:00
parent f94ab30506
commit d8589bbf61
2 changed files with 72 additions and 13 deletions

62
LayoutHelpers.hs Normal file
View File

@ -0,0 +1,62 @@
-----------------------------------------------------------------------------
-- |
-- Module : XMonadContrib.LayoutHelpers
-- Copyright : (c) David Roundy <droundy@darcs.net>
-- License : BSD
--
-- Maintainer : David Roundy <droundy@darcs.net>
-- Stability : unstable
-- Portability : portable
--
-- Make layouts respect size hints.
-----------------------------------------------------------------------------
module XMonadContrib.LayoutHelpers (
-- * usage
-- $usage
DoLayout, ModDo, ModMod, ModLay,
layoutModify,
l2lModDo,
idModMod,
) where
import Graphics.X11.Xlib ( Rectangle )
import XMonad
import StackSet ( Stack, integrate )
-- $usage
-- Use LayoutHelpers to help write easy Layouts.
--type DoLayout a = Rectangle -> Stack a -> X ([(a, Rectangle)], Maybe (Layout a))
type DoLayout a = Rectangle -> Stack a -> X [(a, Rectangle)]
type ModifyLayout a = SomeMessage -> X (Maybe (Layout a))
type ModDo a = Rectangle -> Stack a -> [(a, Rectangle)] -> X ([(a, Rectangle)], Maybe (ModLay a))
type ModMod a = SomeMessage -> X (Maybe (ModLay a))
type ModLay a = Layout a -> Layout a
layoutModify :: ModDo a -> ModMod a -> ModLay a
layoutModify fdo fmod l = Layout { doLayout = dl, modifyLayout = modl }
where dl r s = do --(ws, ml') <- doLayout l r s
ws <- doLayout l r s
(ws', mmod') <- fdo r s ws
--let ml'' = case mmod' of
-- Just mod' -> Just $ mod' $ maybe l id ml'
-- Nothing -> layoutModify fdo mod `fmap` ml'
--return (ws', ml'')
case mmod' of
Just _ -> fail "Sorry, can't yet safely modify layouts in doLayout."
Nothing -> return ws'
modl m = do ml' <- modifyLayout l m
mmod' <- fmod m
return $ case mmod' of
Just mod' -> Just $ mod' $ maybe l id ml'
Nothing -> layoutModify fdo fmod `fmap` ml'
l2lModDo :: (Rectangle -> [a] -> [(a,Rectangle)]) -> DoLayout a
--l2lModDo dl r s = return (dl r $ integrate s, Nothing)
l2lModDo dl r s = return (dl r $ integrate s)
idModMod :: ModMod a
idModMod _ = return Nothing

View File

@ -22,14 +22,10 @@ module XMonadContrib.Square (
-- $usage -- $usage
square ) where square ) where
import XMonad
import Graphics.X11.Xlib
import StackSet ( integrate )
-- $usage -- $usage
-- You can use this module with the following in your Config.hs file: -- You can use this module with the following in your Config.hs file:
-- --
-- > import XMonadContrib.Spiral -- > import XMonadContrib.Square
-- --
-- An example layout using square together with "XMonadContrib.Combo" -- An example layout using square together with "XMonadContrib.Combo"
-- to make the very last area square: -- to make the very last area square:
@ -39,16 +35,17 @@ import StackSet ( integrate )
-- > ,(combo [(twoPane 0.03 0.8,1),(square,1)] -- > ,(combo [(twoPane 0.03 0.8,1),(square,1)]
-- > (mirror $ twoPane 0.03 0.85),1)] (twoPane 0.03 0.5) ) -- > (mirror $ twoPane 0.03 0.85),1)] (twoPane 0.03 0.5) )
import XMonad
import Graphics.X11.Xlib
import StackSet ( integrate )
import XMonadContrib.LayoutHelpers ( l2lModDo )
square :: Layout a square :: Layout a
square = Layout { doLayout = \r s -> arrange r (integrate s), modifyLayout = message } square = Layout { doLayout = l2lModDo arrange, modifyLayout = const (return Nothing) }
where where arrange :: Rectangle -> [a] -> [(a, Rectangle)]
arrange rect ws@(_:_) = do arrange rect ws@(_:_) = map (\w->(w,rest)) (init ws) ++ [(last ws,sq)]
let (rest, sq) = splitSquare rect where (rest, sq) = splitSquare rect
return (map (\w->(w,rest)) (init ws) ++ [(last ws,sq)]) arrange _ [] = []
arrange _ [] = return []
message _ = return Nothing
splitSquare :: Rectangle -> (Rectangle, Rectangle) splitSquare :: Rectangle -> (Rectangle, Rectangle)
splitSquare (Rectangle x y w h) splitSquare (Rectangle x y w h)