LayoutModifier: reimplement ModifiedLayout using runLayout and more

- change modifyLayout type to get the Workspace
- updated ResizeScreen and ManageDocks accordingly.
This commit is contained in:
Andrea Rossato 2008-02-23 07:56:10 +00:00
parent 9ac91e3a15
commit 3ca4966b06
3 changed files with 16 additions and 20 deletions

View File

@ -122,9 +122,9 @@ data ToggleStruts = ToggleStruts deriving (Read,Show,Typeable)
instance Message ToggleStruts
instance LayoutModifier AvoidStruts a where
modifyLayout (AvoidStruts b) l r s = do
modifyLayout (AvoidStruts b) w r = do
nr <- if b then fmap ($ r) calcGap else return r
doLayout l nr s
runLayout w nr
handleMess (AvoidStruts b ) m
| Just ToggleStruts <- fromMessage m = return $ Just $ AvoidStruts (not b)

View File

@ -21,7 +21,7 @@ module XMonad.Layout.LayoutModifier (
) where
import XMonad
import XMonad.StackSet ( Stack )
import XMonad.StackSet ( Stack, Workspace (..) )
-- $usage
-- Use LayoutModifier to help write easy Layouts.
@ -33,9 +33,9 @@ import XMonad.StackSet ( Stack )
-- "XMonad.Layout.Magnifier", "XMonad.Layout.NoBorder",
class (Show (m a), Read (m a)) => LayoutModifier m a where
modifyLayout :: (LayoutClass l a) => m a -> l a -> Rectangle
-> Stack a -> X ([(a, Rectangle)], Maybe (l a))
modifyLayout _ l r s = doLayout l r s
modifyLayout :: (LayoutClass l a) => m a -> Workspace WorkspaceId (l a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (l a))
modifyLayout _ w r = runLayout w r
handleMess :: m a -> SomeMessage -> X (Maybe (m a))
handleMess m mess | Just Hide <- fromMessage mess = doUnhook
| Just ReleaseResources <- fromMessage mess = doUnhook
@ -67,20 +67,16 @@ class (Show (m a), Read (m a)) => LayoutModifier m a where
x <> y = x ++ " " ++ y
instance (LayoutModifier m a, LayoutClass l a) => LayoutClass (ModifiedLayout m l) a where
doLayout (ModifiedLayout m l) r s =
do (ws, ml') <- modifyLayout m l r s
(ws', mm') <- redoLayout m r s ws
runLayout (Workspace i (ModifiedLayout m l) ms) r =
do (ws, ml') <- modifyLayout m (Workspace i l ms) r
(ws', mm') <- case ms of
Just s -> redoLayout m r s ws
Nothing -> emptyLayoutMod m r ws
let ml'' = case mm' of
Just m' -> Just $ (ModifiedLayout m') $ maybe l id ml'
Nothing -> ModifiedLayout m `fmap` ml'
return (ws', ml'')
emptyLayout (ModifiedLayout m l) r =
do (ws, ml') <- emptyLayout l r
(ws',mm') <- emptyLayoutMod m r ws
let ml'' = case mm' of
Just m' -> Just $ (ModifiedLayout m') $ maybe l id ml'
Nothing -> ModifiedLayout m `fmap` ml'
Just m' -> Just $ (ModifiedLayout m') $ maybe l id ml'
Nothing -> ModifiedLayout m `fmap` ml'
return (ws', ml'')
handleMessage (ModifiedLayout m l) mess =
do mm' <- handleMessOrMaybeModifyIt m mess
ml' <- case mm' of

View File

@ -63,14 +63,14 @@ data ResizeScreen a = ResizeScreen ResizeMode Int
data ResizeMode = T | B | L | R deriving (Read, Show)
instance LayoutModifier ResizeScreen a where
modifyLayout m l rect@(Rectangle x y w h) s
modifyLayout m ws rect@(Rectangle x y w h)
| ResizeScreen L i <- m = resize $ Rectangle (x + fi i) y (w - fi i) h
| ResizeScreen R i <- m = resize $ Rectangle x y (w - fi i) h
| ResizeScreen T i <- m = resize $ Rectangle x (y + fi i) w (h - fi i)
| ResizeScreen B i <- m = resize $ Rectangle x y w (h - fi i)
| WithNewScreen r <- m = resize r
| otherwise = resize rect
where resize nr = doLayout l nr s
where resize nr = runLayout ws nr
pureMess (ResizeScreen d _) m
| Just (SetTheme t) <- fromMessage m = Just $ ResizeScreen d (fi $ decoHeight t)