{-# LANGUAGE DeriveDataTypeable, FlexibleContexts, FlexibleInstances, MultiParamTypeClasses, TypeSynonymInstances #-}
module XMonad.Layout.Maximize (
maximize,
maximizeWithPadding,
maximizeRestore,
Maximize, MaximizeRestore,
) where
import XMonad
import qualified XMonad.StackSet as S
import XMonad.Layout.LayoutModifier
import Data.List ( partition )
data Maximize a = Maximize Dimension (Maybe Window) deriving ( Read, Show )
maximize :: LayoutClass l Window => l Window -> ModifiedLayout Maximize l Window
maximize = ModifiedLayout $ Maximize 25 Nothing
maximizeWithPadding :: LayoutClass l Window => Dimension -> l Window -> ModifiedLayout Maximize l Window
maximizeWithPadding padding = ModifiedLayout $ Maximize padding Nothing
data MaximizeRestore = MaximizeRestore Window deriving ( Typeable, Eq )
instance Message MaximizeRestore
maximizeRestore :: Window -> MaximizeRestore
maximizeRestore = MaximizeRestore
instance LayoutModifier Maximize Window where
modifierDescription (Maximize _ _) = "Maximize"
pureModifier (Maximize padding (Just target)) rect (Just (S.Stack focused _ _)) wrs =
if focused == target
then (maxed ++ rest, Nothing)
else (rest ++ maxed, lay)
where
(toMax, rest) = partition (\(w, _) -> w == target) wrs
maxed = map (\(w, _) -> (w, maxRect)) toMax
maxRect = Rectangle (rect_x rect + fromIntegral padding)
(rect_y rect + fromIntegral padding)
(rect_width rect - padding * 2)
(rect_height rect - padding * 2)
lay | null maxed = Just (Maximize padding Nothing)
| otherwise = Nothing
pureModifier _ _ _ wrs = (wrs, Nothing)
pureMess (Maximize padding mw) m = case fromMessage m of
Just (MaximizeRestore w) -> case mw of
Just w' -> if (w == w')
then Just $ Maximize padding Nothing
else Just $ Maximize padding $ Just w
Nothing -> Just $ Maximize padding $ Just w
_ -> Nothing