{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses #-}
module XMonad.Layout.Maximize (
maximize,
maximizeWithPadding,
maximizeRestore,
Maximize, MaximizeRestore,
) where
import XMonad
import qualified XMonad.StackSet as S
import XMonad.Layout.LayoutModifier
import XMonad.Prelude ( partition )
data Maximize a = Maximize Dimension (Maybe Window) deriving ( ReadPrec [Maximize a]
ReadPrec (Maximize a)
ReadS [Maximize a]
forall a. ReadPrec [Maximize a]
forall a. ReadPrec (Maximize a)
forall a. Int -> ReadS (Maximize a)
forall a. ReadS [Maximize a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Maximize a]
$creadListPrec :: forall a. ReadPrec [Maximize a]
readPrec :: ReadPrec (Maximize a)
$creadPrec :: forall a. ReadPrec (Maximize a)
readList :: ReadS [Maximize a]
$creadList :: forall a. ReadS [Maximize a]
readsPrec :: Int -> ReadS (Maximize a)
$creadsPrec :: forall a. Int -> ReadS (Maximize a)
Read, Int -> Maximize a -> ShowS
forall a. Int -> Maximize a -> ShowS
forall a. [Maximize a] -> ShowS
forall a. Maximize a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Maximize a] -> ShowS
$cshowList :: forall a. [Maximize a] -> ShowS
show :: Maximize a -> String
$cshow :: forall a. Maximize a -> String
showsPrec :: Int -> Maximize a -> ShowS
$cshowsPrec :: forall a. Int -> Maximize a -> ShowS
Show )
maximize :: LayoutClass l Window => l Window -> ModifiedLayout Maximize l Window
maximize :: forall (l :: * -> *).
LayoutClass l Window =>
l Window -> ModifiedLayout Maximize l Window
maximize = forall (m :: * -> *) (l :: * -> *) a.
m a -> l a -> ModifiedLayout m l a
ModifiedLayout forall a b. (a -> b) -> a -> b
$ forall a. Dimension -> Maybe Window -> Maximize a
Maximize Dimension
25 forall a. Maybe a
Nothing
maximizeWithPadding :: LayoutClass l Window => Dimension -> l Window -> ModifiedLayout Maximize l Window
maximizeWithPadding :: forall (l :: * -> *).
LayoutClass l Window =>
Dimension -> l Window -> ModifiedLayout Maximize l Window
maximizeWithPadding Dimension
padding = forall (m :: * -> *) (l :: * -> *) a.
m a -> l a -> ModifiedLayout m l a
ModifiedLayout forall a b. (a -> b) -> a -> b
$ forall a. Dimension -> Maybe Window -> Maximize a
Maximize Dimension
padding forall a. Maybe a
Nothing
newtype MaximizeRestore = MaximizeRestore Window deriving ( MaximizeRestore -> MaximizeRestore -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: MaximizeRestore -> MaximizeRestore -> Bool
$c/= :: MaximizeRestore -> MaximizeRestore -> Bool
== :: MaximizeRestore -> MaximizeRestore -> Bool
$c== :: MaximizeRestore -> MaximizeRestore -> Bool
Eq )
instance Message MaximizeRestore
maximizeRestore :: Window -> MaximizeRestore
maximizeRestore :: Window -> MaximizeRestore
maximizeRestore = Window -> MaximizeRestore
MaximizeRestore
instance LayoutModifier Maximize Window where
modifierDescription :: Maximize Window -> String
modifierDescription (Maximize Dimension
_ Maybe Window
_) = String
"Maximize"
pureModifier :: Maximize Window
-> Rectangle
-> Maybe (Stack Window)
-> [(Window, Rectangle)]
-> ([(Window, Rectangle)], Maybe (Maximize Window))
pureModifier (Maximize Dimension
padding (Just Window
target)) Rectangle
rect (Just (S.Stack Window
focused [Window]
_ [Window]
_)) [(Window, Rectangle)]
wrs =
if Window
focused forall a. Eq a => a -> a -> Bool
== Window
target
then ([(Window, Rectangle)]
maxed forall a. [a] -> [a] -> [a]
++ [(Window, Rectangle)]
rest, forall a. Maybe a
Nothing)
else ([(Window, Rectangle)]
rest forall a. [a] -> [a] -> [a]
++ [(Window, Rectangle)]
maxed, forall {a}. Maybe (Maximize a)
lay)
where
([(Window, Rectangle)]
toMax, [(Window, Rectangle)]
rest) = forall a. (a -> Bool) -> [a] -> ([a], [a])
partition (\(Window
w, Rectangle
_) -> Window
w forall a. Eq a => a -> a -> Bool
== Window
target) [(Window, Rectangle)]
wrs
maxed :: [(Window, Rectangle)]
maxed = forall a b. (a -> b) -> [a] -> [b]
map (\(Window
w, Rectangle
_) -> (Window
w, Rectangle
maxRect)) [(Window, Rectangle)]
toMax
maxRect :: Rectangle
maxRect = Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle (Rectangle -> Position
rect_x Rectangle
rect forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral Dimension
padding)
(Rectangle -> Position
rect_y Rectangle
rect forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fromIntegral Dimension
padding)
(Rectangle -> Dimension
rect_width Rectangle
rect forall a. Num a => a -> a -> a
- Dimension
padding forall a. Num a => a -> a -> a
* Dimension
2)
(Rectangle -> Dimension
rect_height Rectangle
rect forall a. Num a => a -> a -> a
- Dimension
padding forall a. Num a => a -> a -> a
* Dimension
2)
lay :: Maybe (Maximize a)
lay | forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Window, Rectangle)]
maxed = forall a. a -> Maybe a
Just (forall a. Dimension -> Maybe Window -> Maximize a
Maximize Dimension
padding forall a. Maybe a
Nothing)
| Bool
otherwise = forall a. Maybe a
Nothing
pureModifier Maximize Window
_ Rectangle
_ Maybe (Stack Window)
_ [(Window, Rectangle)]
wrs = ([(Window, Rectangle)]
wrs, forall a. Maybe a
Nothing)
pureMess :: Maximize Window -> SomeMessage -> Maybe (Maximize Window)
pureMess (Maximize Dimension
padding Maybe Window
mw) SomeMessage
m = case forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m of
Just (MaximizeRestore Window
w) -> case Maybe Window
mw of
Just Window
w' -> if Window
w forall a. Eq a => a -> a -> Bool
== Window
w'
then forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Dimension -> Maybe Window -> Maximize a
Maximize Dimension
padding forall a. Maybe a
Nothing
else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Dimension -> Maybe Window -> Maximize a
Maximize Dimension
padding forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just Window
w
Maybe Window
Nothing -> forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ forall a. Dimension -> Maybe Window -> Maximize a
Maximize Dimension
padding forall a b. (a -> b) -> a -> b
$ forall a. a -> Maybe a
Just Window
w
Maybe MaximizeRestore
_ -> forall a. Maybe a
Nothing