{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
-----------------------------------------------------------------------------
-- |
-- Module      :  XMonad.Layout.SimpleDecoration
-- Description :  Add simple decorations to the windows of a given layout.
-- Copyright   :  (c) 2007 Andrea Rossato
-- License     :  BSD-style (see xmonad/LICENSE)
--
-- Maintainer  :  andrea.rossato@unibz.it
-- Stability   :  unstable
-- Portability :  unportable
--
-- A layout modifier for adding simple decorations to the windows of a
-- given layout. The decorations are in the form of ion-like tabs
-- for window titles.
--
-----------------------------------------------------------------------------

module XMonad.Layout.SimpleDecoration
    ( -- * Usage:
      -- $usage
      simpleDeco
    , Theme (..)
    , def
    , SimpleDecoration (..)
    , shrinkText, CustomShrink(CustomShrink)
    , Shrinker(..)
    ) where

import XMonad
import XMonad.Layout.Decoration

-- $usage
-- You can use this module with the following in your
-- @xmonad.hs@:
--
-- > import XMonad.Layout.SimpleDecoration
--
-- Then edit your @layoutHook@ by adding the SimpleDecoration decoration to
-- your layout:
--
-- > myL = simpleDeco shrinkText def (layoutHook def)
-- > main = xmonad def { layoutHook = myL }
--
-- 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".
--
-- You can also edit the default configuration options.
--
-- > mySDConfig = def { inactiveBorderColor = "red"
-- >                  , inactiveTextColor   = "red"}
--
-- and
--
-- > myL = simpleDeco shrinkText mySDConfig (layoutHook def)

-- | Add simple decorations to windows of a layout.
simpleDeco :: (Eq a, Shrinker s) => s -> Theme
           -> l a -> ModifiedLayout (Decoration SimpleDecoration s) l a
simpleDeco :: forall a s (l :: * -> *).
(Eq a, Shrinker s) =>
s
-> Theme
-> l a
-> ModifiedLayout (Decoration SimpleDecoration s) l a
simpleDeco s
s Theme
c = forall (ds :: * -> *) a s (l :: * -> *).
(DecorationStyle ds a, Shrinker s) =>
s -> Theme -> ds a -> l a -> ModifiedLayout (Decoration ds s) l a
decoration s
s Theme
c forall a b. (a -> b) -> a -> b
$ forall a. Bool -> SimpleDecoration a
Simple Bool
True

newtype SimpleDecoration a = Simple Bool deriving (Int -> SimpleDecoration a -> ShowS
forall a. Int -> SimpleDecoration a -> ShowS
forall a. [SimpleDecoration a] -> ShowS
forall a. SimpleDecoration a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [SimpleDecoration a] -> ShowS
$cshowList :: forall a. [SimpleDecoration a] -> ShowS
show :: SimpleDecoration a -> String
$cshow :: forall a. SimpleDecoration a -> String
showsPrec :: Int -> SimpleDecoration a -> ShowS
$cshowsPrec :: forall a. Int -> SimpleDecoration a -> ShowS
Show, ReadPrec [SimpleDecoration a]
ReadPrec (SimpleDecoration a)
ReadS [SimpleDecoration a]
forall a. ReadPrec [SimpleDecoration a]
forall a. ReadPrec (SimpleDecoration a)
forall a. Int -> ReadS (SimpleDecoration a)
forall a. ReadS [SimpleDecoration a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [SimpleDecoration a]
$creadListPrec :: forall a. ReadPrec [SimpleDecoration a]
readPrec :: ReadPrec (SimpleDecoration a)
$creadPrec :: forall a. ReadPrec (SimpleDecoration a)
readList :: ReadS [SimpleDecoration a]
$creadList :: forall a. ReadS [SimpleDecoration a]
readsPrec :: Int -> ReadS (SimpleDecoration a)
$creadsPrec :: forall a. Int -> ReadS (SimpleDecoration a)
Read)

instance Eq a => DecorationStyle SimpleDecoration a where
    describeDeco :: SimpleDecoration a -> String
describeDeco SimpleDecoration a
_ = String
"Simple"
    shrink :: SimpleDecoration a -> Rectangle -> Rectangle -> Rectangle
shrink (Simple Bool
b) (Rectangle Position
_ Position
_ Dimension
_ Dimension
dh) r :: Rectangle
r@(Rectangle Position
x Position
y Dimension
w Dimension
h) =
        if Bool
b then Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x (Position
y forall a. Num a => a -> a -> a
+ forall a b. (Integral a, Num b) => a -> b
fi Dimension
dh) Dimension
w (Dimension
h forall a. Num a => a -> a -> a
- Dimension
dh) else Rectangle
r
    pureDecoration :: SimpleDecoration a
-> Dimension
-> Dimension
-> Rectangle
-> Stack a
-> [(a, Rectangle)]
-> (a, Rectangle)
-> Maybe Rectangle
pureDecoration (Simple Bool
b) Dimension
wh Dimension
ht Rectangle
_ Stack a
s [(a, Rectangle)]
_ (a
w,Rectangle Position
x Position
y Dimension
wid Dimension
_) =
        if forall a. Eq a => Stack a -> a -> Bool
isInStack Stack a
s a
w
        then if Bool
b
             then forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x  Position
y          Dimension
nwh Dimension
ht
             else forall a. a -> Maybe a
Just forall a b. (a -> b) -> a -> b
$ Position -> Position -> Dimension -> Dimension -> Rectangle
Rectangle Position
x (Position
y forall a. Num a => a -> a -> a
- forall a b. (Integral a, Num b) => a -> b
fi Dimension
ht) Dimension
nwh Dimension
ht
        else forall a. Maybe a
Nothing
            where nwh :: Dimension
nwh = forall a. Ord a => a -> a -> a
min Dimension
wid Dimension
wh