{-# LANGUAGE MultiParamTypeClasses, TypeSynonymInstances, FlexibleContexts, PatternGuards #-}
----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Layout.Minimize
-- Description :  Minimize windows, temporarily removing them from the layout.
-- Copyright   :  (c) Jan Vornberger 2009, Alejandro Serrano 2010
-- License     :  BSD3-style (see LICENSE)
--
-- Maintainer  :  jan.vornberger@informatik.uni-oldenburg.de
-- Stability   :  unstable
-- Portability :  not portable
--
-- Makes it possible to minimize windows, temporarily removing them
-- from the layout until they are restored.
--
-----------------------------------------------------------------------------

module XMonad.Layout.Minimize (
        -- * Usage
        -- $usage
        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

-- $usage
-- You can use this module with the following in your @xmonad.hs@:
--
-- > import XMonad.Layout.Minimize
--
-- Then edit your @layoutHook@ by adding the Minimize layout modifier:
--
-- > myLayout = minimize (Tall 1 (3/100) (1/2)) ||| Full ||| etc..
-- > main = xmonad def { layoutHook = myLayout }
--
-- For more detailed instructions on editing the layoutHook see
-- <https://xmonad.org/TUTORIAL.html#customizing-xmonad the tutorial> and
-- "XMonad.Doc.Extending#Editing_the_layout_hook".
--
-- The module is designed to work together with "XMonad.Layout.BoringWindows" so
-- that minimized windows will be skipped over when switching the focused window with
-- the keyboard. Include 'BW.boringWindows' in your layout hook and see the
-- documentation of "XMonad.Layout.BoringWindows" on how to modify your keybindings.
--
-- See "XMonad.Actions.Minimize" for possible actions for minimizing/restoring windows
--
-- Also see "XMonad.Hooks.Minimize" if you want to be able to minimize
-- and restore windows from your taskbar.

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