{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances, FlexibleContexts, PatternGuards #-}
module XMonad.Layout.Minimize (
Minimize,
minimize,
) where
import XMonad
import qualified XMonad.StackSet as W
import XMonad.Util.Minimize (Minimized(..))
import XMonad.Layout.LayoutModifier
import XMonad.Layout.BoringWindows as BW
import qualified XMonad.Util.ExtensibleState as XS
data Minimize a = Minimize deriving ( ReadPrec [Minimize a]
ReadPrec (Minimize a)
ReadS [Minimize a]
forall a. ReadPrec [Minimize a]
forall a. ReadPrec (Minimize a)
forall a. Int -> ReadS (Minimize a)
forall a. ReadS [Minimize a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Minimize a]
$creadListPrec :: forall a. ReadPrec [Minimize a]
readPrec :: ReadPrec (Minimize a)
$creadPrec :: forall a. ReadPrec (Minimize a)
readList :: ReadS [Minimize a]
$creadList :: forall a. ReadS [Minimize a]
readsPrec :: Int -> ReadS (Minimize a)
$creadsPrec :: forall a. Int -> ReadS (Minimize a)
Read, Int -> Minimize a -> ShowS
forall a. Int -> Minimize a -> ShowS
forall a. [Minimize a] -> ShowS
forall a. Minimize a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Minimize a] -> ShowS
$cshowList :: forall a. [Minimize a] -> ShowS
show :: Minimize a -> String
$cshow :: forall a. Minimize a -> String
showsPrec :: Int -> Minimize a -> ShowS
$cshowsPrec :: forall a. Int -> Minimize a -> ShowS
Show )
minimize :: l Window -> ModifiedLayout Minimize l Window
minimize :: forall (l :: * -> *). l Window -> ModifiedLayout Minimize l Window
minimize = forall (m :: * -> *) (l :: * -> *) a.
m a -> l a -> ModifiedLayout m l a
ModifiedLayout forall a. Minimize a
Minimize
instance LayoutModifier Minimize Window where
modifierDescription :: Minimize Window -> String
modifierDescription Minimize Window
_ = String
"Minimize"
modifyLayout :: forall (l :: * -> *).
LayoutClass l Window =>
Minimize Window
-> Workspace String (l Window) Window
-> Rectangle
-> X ([(Window, Rectangle)], Maybe (l Window))
modifyLayout Minimize Window
Minimize Workspace String (l Window) Window
wksp Rectangle
rect = do
[Window]
minimized <- forall a (m :: * -> *) b.
(ExtensionClass a, XLike m) =>
(a -> b) -> m b
XS.gets Minimized -> [Window]
minimizedStack
let stack :: Maybe (Stack Window)
stack = forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack Workspace String (l Window) Window
wksp
filtStack :: Maybe (Stack Window)
filtStack = Maybe (Stack Window)
stack forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= forall a. (a -> Bool) -> Stack a -> Maybe (Stack a)
W.filter (forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`notElem` [Window]
minimized)
forall (layout :: * -> *) a.
LayoutClass layout a =>
Workspace String (layout a) a
-> Rectangle -> X ([(a, Rectangle)], Maybe (layout a))
runLayout (Workspace String (l Window) Window
wksp {stack :: Maybe (Stack Window)
W.stack = Maybe (Stack Window)
filtStack}) Rectangle
rect
handleMess :: Minimize Window -> SomeMessage -> X (Maybe (Minimize Window))
handleMess Minimize Window
Minimize SomeMessage
m
| Just UpdateBoring
BW.UpdateBoring <- forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m = do
[Window]
minimized <- forall a (m :: * -> *) b.
(ExtensionClass a, XLike m) =>
(a -> b) -> m b
XS.gets Minimized -> [Window]
minimizedStack
Workspace String (Layout Window) Window
ws <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState -> WindowSet
windowset)
forall a b c. (a -> b -> c) -> b -> a -> c
flip forall a.
Message a =>
a -> Workspace String (Layout Window) Window -> X ()
sendMessageWithNoRefresh Workspace String (Layout Window) Window
ws forall a b. (a -> b) -> a -> b
$ String -> [Window] -> BoringMessage
BW.Replace String
"Minimize" [Window]
minimized
forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing
| Bool
otherwise = forall (m :: * -> *) a. Monad m => a -> m a
return forall a. Maybe a
Nothing