{-# LANGUAGE CPP #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PatternGuards #-}
{-# LANGUAGE TupleSections #-}
module XMonad.Layout.Decoration
(
decoration
, Theme (..), def
, Decoration
, DecorationMsg (..)
, DecorationStyle (..)
, DefaultDecoration (..)
, Shrinker (..), DefaultShrinker
, shrinkText, CustomShrink ( CustomShrink ), shrinkWhile
, isInStack, isVisible, isInvisible, isWithin, fi
, findWindowByDecoration
, module XMonad.Layout.LayoutModifier
, DecorationState, OrigWin
) where
import Foreign.C.Types(CInt)
import XMonad
import XMonad.Prelude
import qualified XMonad.StackSet as W
import XMonad.Hooks.UrgencyHook
import XMonad.Layout.LayoutModifier
import XMonad.Layout.WindowArranger (WindowArrangerMsg (..), diff, listFromList)
import XMonad.Util.NamedWindows (getName)
import XMonad.Util.Invisible
import XMonad.Util.XUtils
import XMonad.Util.Font
import XMonad.Util.Image
decoration :: (DecorationStyle ds a, Shrinker s) => s -> Theme -> ds a
-> l a -> ModifiedLayout (Decoration ds s) l a
decoration :: 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
t ds a
ds = Decoration ds s a -> l a -> ModifiedLayout (Decoration ds s) l a
forall (m :: * -> *) (l :: * -> *) a.
m a -> l a -> ModifiedLayout m l a
ModifiedLayout (Invisible Maybe DecorationState
-> s -> Theme -> ds a -> Decoration ds s a
forall (ds :: * -> *) s a.
Invisible Maybe DecorationState
-> s -> Theme -> ds a -> Decoration ds s a
Decoration (Maybe DecorationState -> Invisible Maybe DecorationState
forall (m :: * -> *) a. m a -> Invisible m a
I Maybe DecorationState
forall a. Maybe a
Nothing) s
s Theme
t ds a
ds)
data Theme =
Theme { Theme -> String
activeColor :: String
, Theme -> String
inactiveColor :: String
, Theme -> String
urgentColor :: String
, Theme -> String
activeBorderColor :: String
, Theme -> String
inactiveBorderColor :: String
, Theme -> String
urgentBorderColor :: String
, Theme -> Word32
activeBorderWidth :: Dimension
, Theme -> Word32
inactiveBorderWidth :: Dimension
, Theme -> Word32
urgentBorderWidth :: Dimension
, Theme -> String
activeTextColor :: String
, Theme -> String
inactiveTextColor :: String
, Theme -> String
urgentTextColor :: String
, Theme -> String
fontName :: String
, Theme -> Word32
decoWidth :: Dimension
, Theme -> Word32
decoHeight :: Dimension
, Theme -> [(String, Align)]
windowTitleAddons :: [(String, Align)]
, Theme -> [([[Bool]], Placement)]
windowTitleIcons :: [([[Bool]], Placement)]
} deriving (Int -> Theme -> ShowS
[Theme] -> ShowS
Theme -> String
(Int -> Theme -> ShowS)
-> (Theme -> String) -> ([Theme] -> ShowS) -> Show Theme
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Theme -> ShowS
showsPrec :: Int -> Theme -> ShowS
$cshow :: Theme -> String
show :: Theme -> String
$cshowList :: [Theme] -> ShowS
showList :: [Theme] -> ShowS
Show, ReadPrec [Theme]
ReadPrec Theme
Int -> ReadS Theme
ReadS [Theme]
(Int -> ReadS Theme)
-> ReadS [Theme]
-> ReadPrec Theme
-> ReadPrec [Theme]
-> Read Theme
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: Int -> ReadS Theme
readsPrec :: Int -> ReadS Theme
$creadList :: ReadS [Theme]
readList :: ReadS [Theme]
$creadPrec :: ReadPrec Theme
readPrec :: ReadPrec Theme
$creadListPrec :: ReadPrec [Theme]
readListPrec :: ReadPrec [Theme]
Read)
instance Default Theme where
def :: Theme
def =
Theme { activeColor :: String
activeColor = String
"#999999"
, inactiveColor :: String
inactiveColor = String
"#666666"
, urgentColor :: String
urgentColor = String
"#FFFF00"
, activeBorderColor :: String
activeBorderColor = String
"#FFFFFF"
, inactiveBorderColor :: String
inactiveBorderColor = String
"#BBBBBB"
, urgentBorderColor :: String
urgentBorderColor = String
"##00FF00"
, activeBorderWidth :: Word32
activeBorderWidth = Word32
1
, inactiveBorderWidth :: Word32
inactiveBorderWidth = Word32
1
, urgentBorderWidth :: Word32
urgentBorderWidth = Word32
1
, activeTextColor :: String
activeTextColor = String
"#FFFFFF"
, inactiveTextColor :: String
inactiveTextColor = String
"#BFBFBF"
, urgentTextColor :: String
urgentTextColor = String
"#FF0000"
#ifdef XFT
, fontName = "xft:monospace"
#else
, fontName :: String
fontName = String
"-misc-fixed-*-*-*-*-10-*-*-*-*-*-*-*"
#endif
, decoWidth :: Word32
decoWidth = Word32
200
, decoHeight :: Word32
decoHeight = Word32
20
, windowTitleAddons :: [(String, Align)]
windowTitleAddons = []
, windowTitleIcons :: [([[Bool]], Placement)]
windowTitleIcons = []
}
newtype DecorationMsg = SetTheme Theme
instance Message DecorationMsg
data DecorationState =
DS { DecorationState -> [(OrigWin, DecoWin)]
decos :: [(OrigWin,DecoWin)]
, DecorationState -> XMonadFont
font :: XMonadFont
}
type DecoWin = (Maybe Window, Maybe Rectangle)
type OrigWin = (Window,Rectangle)
data Decoration ds s a =
Decoration (Invisible Maybe DecorationState) s Theme (ds a)
deriving (Int -> Decoration ds s a -> ShowS
[Decoration ds s a] -> ShowS
Decoration ds s a -> String
(Int -> Decoration ds s a -> ShowS)
-> (Decoration ds s a -> String)
-> ([Decoration ds s a] -> ShowS)
-> Show (Decoration ds s a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (ds :: * -> *) s a.
(Show s, Show (ds a)) =>
Int -> Decoration ds s a -> ShowS
forall (ds :: * -> *) s a.
(Show s, Show (ds a)) =>
[Decoration ds s a] -> ShowS
forall (ds :: * -> *) s a.
(Show s, Show (ds a)) =>
Decoration ds s a -> String
$cshowsPrec :: forall (ds :: * -> *) s a.
(Show s, Show (ds a)) =>
Int -> Decoration ds s a -> ShowS
showsPrec :: Int -> Decoration ds s a -> ShowS
$cshow :: forall (ds :: * -> *) s a.
(Show s, Show (ds a)) =>
Decoration ds s a -> String
show :: Decoration ds s a -> String
$cshowList :: forall (ds :: * -> *) s a.
(Show s, Show (ds a)) =>
[Decoration ds s a] -> ShowS
showList :: [Decoration ds s a] -> ShowS
Show, ReadPrec [Decoration ds s a]
ReadPrec (Decoration ds s a)
Int -> ReadS (Decoration ds s a)
ReadS [Decoration ds s a]
(Int -> ReadS (Decoration ds s a))
-> ReadS [Decoration ds s a]
-> ReadPrec (Decoration ds s a)
-> ReadPrec [Decoration ds s a]
-> Read (Decoration ds s a)
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
forall (ds :: * -> *) s a.
(Read s, Read (ds a)) =>
ReadPrec [Decoration ds s a]
forall (ds :: * -> *) s a.
(Read s, Read (ds a)) =>
ReadPrec (Decoration ds s a)
forall (ds :: * -> *) s a.
(Read s, Read (ds a)) =>
Int -> ReadS (Decoration ds s a)
forall (ds :: * -> *) s a.
(Read s, Read (ds a)) =>
ReadS [Decoration ds s a]
$creadsPrec :: forall (ds :: * -> *) s a.
(Read s, Read (ds a)) =>
Int -> ReadS (Decoration ds s a)
readsPrec :: Int -> ReadS (Decoration ds s a)
$creadList :: forall (ds :: * -> *) s a.
(Read s, Read (ds a)) =>
ReadS [Decoration ds s a]
readList :: ReadS [Decoration ds s a]
$creadPrec :: forall (ds :: * -> *) s a.
(Read s, Read (ds a)) =>
ReadPrec (Decoration ds s a)
readPrec :: ReadPrec (Decoration ds s a)
$creadListPrec :: forall (ds :: * -> *) s a.
(Read s, Read (ds a)) =>
ReadPrec [Decoration ds s a]
readListPrec :: ReadPrec [Decoration ds s a]
Read)
class (Read (ds a), Show (ds a), Eq a) => DecorationStyle ds a where
describeDeco :: ds a -> String
describeDeco = ds a -> String
forall a. Show a => a -> String
show
shrink :: ds a -> Rectangle -> Rectangle -> Rectangle
shrink ds a
_ (Rectangle Int32
_ Int32
_ Word32
_ Word32
dh) (Rectangle Int32
x Int32
y Word32
w Word32
h) = Int32 -> Int32 -> Word32 -> Word32 -> Rectangle
Rectangle Int32
x (Int32
y Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fi Word32
dh) Word32
w (Word32
h Word32 -> Word32 -> Word32
forall a. Num a => a -> a -> a
- Word32
dh)
decorationEventHook :: ds a -> DecorationState -> Event -> X ()
decorationEventHook = ds a -> DecorationState -> Event -> X ()
forall (ds :: * -> *) a.
DecorationStyle ds a =>
ds a -> DecorationState -> Event -> X ()
handleMouseFocusDrag
decorationCatchClicksHook :: ds a
-> Window
-> Int
-> Int
-> X Bool
decorationCatchClicksHook ds a
_ Word64
_ Int
_ Int
_ = Bool -> X Bool
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Bool
False
decorationWhileDraggingHook :: ds a -> CInt -> CInt -> (Window, Rectangle) -> Position -> Position -> X ()
decorationWhileDraggingHook ds a
_ = CInt -> CInt -> OrigWin -> Int32 -> Int32 -> X ()
handleDraggingInProgress
decorationAfterDraggingHook :: ds a -> (Window, Rectangle) -> Window -> X ()
decorationAfterDraggingHook ds a
_ds (Word64
mainw, Rectangle
_r) Word64
_decoWin = Word64 -> X ()
focus Word64
mainw
pureDecoration :: ds a -> Dimension -> Dimension -> Rectangle
-> W.Stack a -> [(a,Rectangle)] -> (a,Rectangle) -> Maybe Rectangle
pureDecoration ds a
_ Word32
_ Word32
ht Rectangle
_ Stack a
s [(a, Rectangle)]
_ (a
w,Rectangle Int32
x Int32
y Word32
wh Word32
ht') = if Stack a -> a -> Bool
forall a. Eq a => Stack a -> a -> Bool
isInStack Stack a
s a
w Bool -> Bool -> Bool
&& (Word32
ht Word32 -> Word32 -> Bool
forall a. Ord a => a -> a -> Bool
< Word32
ht')
then Rectangle -> Maybe Rectangle
forall a. a -> Maybe a
Just (Rectangle -> Maybe Rectangle) -> Rectangle -> Maybe Rectangle
forall a b. (a -> b) -> a -> b
$ Int32 -> Int32 -> Word32 -> Word32 -> Rectangle
Rectangle Int32
x Int32
y Word32
wh Word32
ht
else Maybe Rectangle
forall a. Maybe a
Nothing
decorate :: ds a -> Dimension -> Dimension -> Rectangle
-> W.Stack a -> [(a,Rectangle)] -> (a,Rectangle) -> X (Maybe Rectangle)
decorate ds a
ds Word32
w Word32
h Rectangle
r Stack a
s [(a, Rectangle)]
wrs (a, Rectangle)
wr = Maybe Rectangle -> X (Maybe Rectangle)
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe Rectangle -> X (Maybe Rectangle))
-> Maybe Rectangle -> X (Maybe Rectangle)
forall a b. (a -> b) -> a -> b
$ ds a
-> Word32
-> Word32
-> Rectangle
-> Stack a
-> [(a, Rectangle)]
-> (a, Rectangle)
-> Maybe Rectangle
forall (ds :: * -> *) a.
DecorationStyle ds a =>
ds a
-> Word32
-> Word32
-> Rectangle
-> Stack a
-> [(a, Rectangle)]
-> (a, Rectangle)
-> Maybe Rectangle
pureDecoration ds a
ds Word32
w Word32
h Rectangle
r Stack a
s [(a, Rectangle)]
wrs (a, Rectangle)
wr
data DefaultDecoration a = DefaultDecoration deriving ( ReadPrec [DefaultDecoration a]
ReadPrec (DefaultDecoration a)
Int -> ReadS (DefaultDecoration a)
ReadS [DefaultDecoration a]
(Int -> ReadS (DefaultDecoration a))
-> ReadS [DefaultDecoration a]
-> ReadPrec (DefaultDecoration a)
-> ReadPrec [DefaultDecoration a]
-> Read (DefaultDecoration a)
forall a. ReadPrec [DefaultDecoration a]
forall a. ReadPrec (DefaultDecoration a)
forall a. Int -> ReadS (DefaultDecoration a)
forall a. ReadS [DefaultDecoration a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Int -> ReadS (DefaultDecoration a)
readsPrec :: Int -> ReadS (DefaultDecoration a)
$creadList :: forall a. ReadS [DefaultDecoration a]
readList :: ReadS [DefaultDecoration a]
$creadPrec :: forall a. ReadPrec (DefaultDecoration a)
readPrec :: ReadPrec (DefaultDecoration a)
$creadListPrec :: forall a. ReadPrec [DefaultDecoration a]
readListPrec :: ReadPrec [DefaultDecoration a]
Read, Int -> DefaultDecoration a -> ShowS
[DefaultDecoration a] -> ShowS
DefaultDecoration a -> String
(Int -> DefaultDecoration a -> ShowS)
-> (DefaultDecoration a -> String)
-> ([DefaultDecoration a] -> ShowS)
-> Show (DefaultDecoration a)
forall a. Int -> DefaultDecoration a -> ShowS
forall a. [DefaultDecoration a] -> ShowS
forall a. DefaultDecoration a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Int -> DefaultDecoration a -> ShowS
showsPrec :: Int -> DefaultDecoration a -> ShowS
$cshow :: forall a. DefaultDecoration a -> String
show :: DefaultDecoration a -> String
$cshowList :: forall a. [DefaultDecoration a] -> ShowS
showList :: [DefaultDecoration a] -> ShowS
Show )
instance Eq a => DecorationStyle DefaultDecoration a
instance (DecorationStyle ds Window, Shrinker s) => LayoutModifier (Decoration ds s) Window where
redoLayout :: Decoration ds s Word64
-> Rectangle
-> Maybe (Stack Word64)
-> [OrigWin]
-> X ([OrigWin], Maybe (Decoration ds s Word64))
redoLayout (Decoration (I (Just DecorationState
s)) s
sh Theme
t ds Word64
ds) Rectangle
_ Maybe (Stack Word64)
Nothing [OrigWin]
_ = do
DecorationState -> X ()
releaseResources DecorationState
s
([OrigWin], Maybe (Decoration ds s Word64))
-> X ([OrigWin], Maybe (Decoration ds s Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ([], Decoration ds s Word64 -> Maybe (Decoration ds s Word64)
forall a. a -> Maybe a
Just (Decoration ds s Word64 -> Maybe (Decoration ds s Word64))
-> Decoration ds s Word64 -> Maybe (Decoration ds s Word64)
forall a b. (a -> b) -> a -> b
$ Invisible Maybe DecorationState
-> s -> Theme -> ds Word64 -> Decoration ds s Word64
forall (ds :: * -> *) s a.
Invisible Maybe DecorationState
-> s -> Theme -> ds a -> Decoration ds s a
Decoration (Maybe DecorationState -> Invisible Maybe DecorationState
forall (m :: * -> *) a. m a -> Invisible m a
I Maybe DecorationState
forall a. Maybe a
Nothing) s
sh Theme
t ds Word64
ds)
redoLayout Decoration ds s Word64
_ Rectangle
_ Maybe (Stack Word64)
Nothing [OrigWin]
_ = ([OrigWin], Maybe (Decoration ds s Word64))
-> X ([OrigWin], Maybe (Decoration ds s Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ([], Maybe (Decoration ds s Word64)
forall a. Maybe a
Nothing)
redoLayout (Decoration Invisible Maybe DecorationState
st s
sh Theme
t ds Word64
ds) Rectangle
sc (Just Stack Word64
stack) [OrigWin]
wrs
| I Maybe DecorationState
Nothing <- Invisible Maybe DecorationState
st = Theme
-> ds Word64
-> Rectangle
-> Stack Word64
-> [OrigWin]
-> X DecorationState
forall (ds :: * -> *).
DecorationStyle ds Word64 =>
Theme
-> ds Word64
-> Rectangle
-> Stack Word64
-> [OrigWin]
-> X DecorationState
initState Theme
t ds Word64
ds Rectangle
sc Stack Word64
stack [OrigWin]
wrs X DecorationState
-> (DecorationState
-> X ([OrigWin], Maybe (Decoration ds s Word64)))
-> X ([OrigWin], Maybe (Decoration ds s Word64))
forall a b. X a -> (a -> X b) -> X b
forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= DecorationState -> X ([OrigWin], Maybe (Decoration ds s Word64))
processState
| I (Just DecorationState
s) <- Invisible Maybe DecorationState
st = do let dwrs :: [(OrigWin, DecoWin)]
dwrs = DecorationState -> [(OrigWin, DecoWin)]
decos DecorationState
s
([Word64]
d,[Word64]
a) = (([Word64], [Word64]) -> ([Word64], [Word64]))
-> [Word64] -> [Word64] -> ([Word64], [Word64])
forall a b c. ((a, b) -> c) -> a -> b -> c
curry ([Word64], [Word64]) -> ([Word64], [Word64])
forall a. Eq a => ([a], [a]) -> ([a], [a])
diff ([(OrigWin, DecoWin)] -> [Word64]
forall {b} {b} {b}. [((b, b), b)] -> [b]
get_ws [(OrigWin, DecoWin)]
dwrs) [Word64]
ws
toDel :: [(OrigWin, DecoWin)]
toDel = [Word64] -> [(OrigWin, DecoWin)] -> [(OrigWin, DecoWin)]
forall {t :: * -> *} {a} {b} {b}.
(Foldable t, Eq a) =>
t a -> [((a, b), b)] -> [((a, b), b)]
todel [Word64]
d [(OrigWin, DecoWin)]
dwrs
toAdd :: [OrigWin]
toAdd = [Word64] -> [OrigWin] -> [OrigWin]
forall {t :: * -> *} {a} {b}.
(Foldable t, Eq a) =>
t a -> [(a, b)] -> [(a, b)]
toadd [Word64]
a [OrigWin]
wrs
[DecoWin] -> X ()
deleteDecos (((OrigWin, DecoWin) -> DecoWin)
-> [(OrigWin, DecoWin)] -> [DecoWin]
forall a b. (a -> b) -> [a] -> [b]
map (OrigWin, DecoWin) -> DecoWin
forall a b. (a, b) -> b
snd [(OrigWin, DecoWin)]
toDel)
let ndwrs :: [(OrigWin, (Maybe a, Maybe a))]
ndwrs = (OrigWin -> (OrigWin, (Maybe a, Maybe a)))
-> [OrigWin] -> [(OrigWin, (Maybe a, Maybe a))]
forall a b. (a -> b) -> [a] -> [b]
map (, (Maybe a
forall a. Maybe a
Nothing,Maybe a
forall a. Maybe a
Nothing)) [OrigWin]
toAdd
ndecos <- [(OrigWin, DecoWin)] -> [OrigWin] -> X [(OrigWin, DecoWin)]
forall {b} {b}.
[((Word64, b), (Maybe Word64, b))]
-> [OrigWin] -> X [(OrigWin, DecoWin)]
resync ([(OrigWin, DecoWin)]
forall {a} {a}. [(OrigWin, (Maybe a, Maybe a))]
ndwrs [(OrigWin, DecoWin)]
-> [(OrigWin, DecoWin)] -> [(OrigWin, DecoWin)]
forall a. [a] -> [a] -> [a]
++ [Word64] -> [(OrigWin, DecoWin)] -> [(OrigWin, DecoWin)]
forall {b} {b}.
[Word64] -> [((Word64, b), b)] -> [((Word64, b), b)]
del_dwrs [Word64]
d [(OrigWin, DecoWin)]
dwrs) [OrigWin]
wrs
processState (s {decos = ndecos })
where
ws :: [Word64]
ws = (OrigWin -> Word64) -> [OrigWin] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map OrigWin -> Word64
forall a b. (a, b) -> a
fst [OrigWin]
wrs
get_w :: ((c, b), b) -> c
get_w = (c, b) -> c
forall a b. (a, b) -> a
fst ((c, b) -> c) -> (((c, b), b) -> (c, b)) -> ((c, b), b) -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((c, b), b) -> (c, b)
forall a b. (a, b) -> a
fst
get_ws :: [((b, b), b)] -> [b]
get_ws = (((b, b), b) -> b) -> [((b, b), b)] -> [b]
forall a b. (a -> b) -> [a] -> [b]
map ((b, b), b) -> b
forall {c} {b} {b}. ((c, b), b) -> c
get_w
del_dwrs :: [Word64] -> [((Word64, b), b)] -> [((Word64, b), b)]
del_dwrs = (((Word64, b), b) -> Word64)
-> (Word64 -> [Word64] -> Bool)
-> [Word64]
-> [((Word64, b), b)]
-> [((Word64, b), b)]
forall b c a. (b -> c) -> (c -> [a] -> Bool) -> [a] -> [b] -> [b]
listFromList ((Word64, b), b) -> Word64
forall {c} {b} {b}. ((c, b), b) -> c
get_w Word64 -> [Word64] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
notElem
find_dw :: Int -> [(a, (c, b))] -> c
find_dw Int
i = (c, b) -> c
forall a b. (a, b) -> a
fst ((c, b) -> c) -> ([(a, (c, b))] -> (c, b)) -> [(a, (c, b))] -> c
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, (c, b)) -> (c, b)
forall a b. (a, b) -> b
snd ((a, (c, b)) -> (c, b))
-> ([(a, (c, b))] -> (a, (c, b))) -> [(a, (c, b))] -> (c, b)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ([(a, (c, b))] -> Int -> (a, (c, b)))
-> Int -> [(a, (c, b))] -> (a, (c, b))
forall a b c. (a -> b -> c) -> b -> a -> c
flip [(a, (c, b))] -> Int -> (a, (c, b))
forall a. HasCallStack => [a] -> Int -> a
(!!) Int
i
todel :: t a -> [((a, b), b)] -> [((a, b), b)]
todel t a
d = (((a, b), b) -> Bool) -> [((a, b), b)] -> [((a, b), b)]
forall a. (a -> Bool) -> [a] -> [a]
filter ((a -> t a -> Bool) -> t a -> a -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> t a -> Bool
forall a. Eq a => a -> t a -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem t a
d (a -> Bool) -> (((a, b), b) -> a) -> ((a, b), b) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ((a, b), b) -> a
forall {c} {b} {b}. ((c, b), b) -> c
get_w)
toadd :: t a -> [(a, b)] -> [(a, b)]
toadd t a
a = ((a, b) -> Bool) -> [(a, b)] -> [(a, b)]
forall a. (a -> Bool) -> [a] -> [a]
filter ((a -> t a -> Bool) -> t a -> a -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> t a -> Bool
forall a. Eq a => a -> t a -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem t a
a (a -> Bool) -> ((a, b) -> a) -> (a, b) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a, b) -> a
forall a b. (a, b) -> a
fst )
check_dwr :: DecoWin -> X DecoWin
check_dwr DecoWin
dwr = case DecoWin
dwr of
(Maybe Word64
Nothing, Just Rectangle
dr) -> do dw <- Theme -> Rectangle -> X Word64
createDecoWindow Theme
t Rectangle
dr
return (Just dw, Just dr)
DecoWin
_ -> DecoWin -> X DecoWin
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return DecoWin
dwr
resync :: [((Word64, b), (Maybe Word64, b))]
-> [OrigWin] -> X [(OrigWin, DecoWin)]
resync [((Word64, b), (Maybe Word64, b))]
_ [] = [(OrigWin, DecoWin)] -> X [(OrigWin, DecoWin)]
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return []
resync [((Word64, b), (Maybe Word64, b))]
d ((Word64
w,Rectangle
r):[OrigWin]
xs) = case Word64
w Word64 -> [Word64] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
`elemIndex` [((Word64, b), (Maybe Word64, b))] -> [Word64]
forall {b} {b} {b}. [((b, b), b)] -> [b]
get_ws [((Word64, b), (Maybe Word64, b))]
d of
Just Int
i -> do dr <- ds Word64
-> Word32
-> Word32
-> Rectangle
-> Stack Word64
-> [OrigWin]
-> OrigWin
-> X (Maybe Rectangle)
forall (ds :: * -> *) a.
DecorationStyle ds a =>
ds a
-> Word32
-> Word32
-> Rectangle
-> Stack a
-> [(a, Rectangle)]
-> (a, Rectangle)
-> X (Maybe Rectangle)
decorate ds Word64
ds (Theme -> Word32
decoWidth Theme
t) (Theme -> Word32
decoHeight Theme
t) Rectangle
sc Stack Word64
stack [OrigWin]
wrs (Word64
w,Rectangle
r)
dwr <- check_dwr (find_dw i d, dr)
dwrs <- resync d xs
return $ ((w,r),dwr) : dwrs
Maybe Int
Nothing -> [((Word64, b), (Maybe Word64, b))]
-> [OrigWin] -> X [(OrigWin, DecoWin)]
resync [((Word64, b), (Maybe Word64, b))]
d [OrigWin]
xs
remove_stacked :: [b] -> [(a, b)] -> [(a, b)]
remove_stacked [b]
rs ((a
w,b
r):[(a, b)]
xs)
| b
r b -> [b] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [b]
rs = [b] -> [(a, b)] -> [(a, b)]
remove_stacked [b]
rs [(a, b)]
xs
| Bool
otherwise = (a
w,b
r) (a, b) -> [(a, b)] -> [(a, b)]
forall a. a -> [a] -> [a]
: [b] -> [(a, b)] -> [(a, b)]
remove_stacked (b
rb -> [b] -> [b]
forall a. a -> [a] -> [a]
:[b]
rs) [(a, b)]
xs
remove_stacked [b]
_ [] = []
insert_dwr :: ((a, Rectangle), (Maybe a, Maybe Rectangle))
-> [(a, Rectangle)] -> [(a, Rectangle)]
insert_dwr ((a
w,Rectangle
r),(Just a
dw,Just Rectangle
dr)) [(a, Rectangle)]
xs = (a
dw,Rectangle
dr)(a, Rectangle) -> [(a, Rectangle)] -> [(a, Rectangle)]
forall a. a -> [a] -> [a]
:(a
w, ds Word64 -> Rectangle -> Rectangle -> Rectangle
forall (ds :: * -> *) a.
DecorationStyle ds a =>
ds a -> Rectangle -> Rectangle -> Rectangle
shrink ds Word64
ds Rectangle
dr Rectangle
r)(a, Rectangle) -> [(a, Rectangle)] -> [(a, Rectangle)]
forall a. a -> [a] -> [a]
:[(a, Rectangle)]
xs
insert_dwr ((a, Rectangle)
x ,( Maybe a
_ , Maybe Rectangle
_ )) [(a, Rectangle)]
xs = (a, Rectangle)
x(a, Rectangle) -> [(a, Rectangle)] -> [(a, Rectangle)]
forall a. a -> [a] -> [a]
:[(a, Rectangle)]
xs
dwrs_to_wrs :: [((a, Rectangle), (Maybe a, Maybe Rectangle))] -> [(a, Rectangle)]
dwrs_to_wrs = [Rectangle] -> [(a, Rectangle)] -> [(a, Rectangle)]
forall {b} {a}. Eq b => [b] -> [(a, b)] -> [(a, b)]
remove_stacked [] ([(a, Rectangle)] -> [(a, Rectangle)])
-> ([((a, Rectangle), (Maybe a, Maybe Rectangle))]
-> [(a, Rectangle)])
-> [((a, Rectangle), (Maybe a, Maybe Rectangle))]
-> [(a, Rectangle)]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (((a, Rectangle), (Maybe a, Maybe Rectangle))
-> [(a, Rectangle)] -> [(a, Rectangle)])
-> [(a, Rectangle)]
-> [((a, Rectangle), (Maybe a, Maybe Rectangle))]
-> [(a, Rectangle)]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr ((a, Rectangle), (Maybe a, Maybe Rectangle))
-> [(a, Rectangle)] -> [(a, Rectangle)]
forall {a}.
((a, Rectangle), (Maybe a, Maybe Rectangle))
-> [(a, Rectangle)] -> [(a, Rectangle)]
insert_dwr []
processState :: DecorationState -> X ([OrigWin], Maybe (Decoration ds s Word64))
processState DecorationState
s = do let ndwrs :: [(OrigWin, DecoWin)]
ndwrs = DecorationState -> [(OrigWin, DecoWin)]
decos DecorationState
s
[DecoWin] -> X ()
showDecos (((OrigWin, DecoWin) -> DecoWin)
-> [(OrigWin, DecoWin)] -> [DecoWin]
forall a b. (a -> b) -> [a] -> [b]
map (OrigWin, DecoWin) -> DecoWin
forall a b. (a, b) -> b
snd [(OrigWin, DecoWin)]
ndwrs)
s -> Theme -> XMonadFont -> [(OrigWin, DecoWin)] -> X ()
forall s.
Shrinker s =>
s -> Theme -> XMonadFont -> [(OrigWin, DecoWin)] -> X ()
updateDecos s
sh Theme
t (DecorationState -> XMonadFont
font DecorationState
s) [(OrigWin, DecoWin)]
ndwrs
([OrigWin], Maybe (Decoration ds s Word64))
-> X ([OrigWin], Maybe (Decoration ds s Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ([(OrigWin, DecoWin)] -> [OrigWin]
forall {a}.
[((a, Rectangle), (Maybe a, Maybe Rectangle))] -> [(a, Rectangle)]
dwrs_to_wrs [(OrigWin, DecoWin)]
ndwrs, Decoration ds s Word64 -> Maybe (Decoration ds s Word64)
forall a. a -> Maybe a
Just (Invisible Maybe DecorationState
-> s -> Theme -> ds Word64 -> Decoration ds s Word64
forall (ds :: * -> *) s a.
Invisible Maybe DecorationState
-> s -> Theme -> ds a -> Decoration ds s a
Decoration (Maybe DecorationState -> Invisible Maybe DecorationState
forall (m :: * -> *) a. m a -> Invisible m a
I (DecorationState -> Maybe DecorationState
forall a. a -> Maybe a
Just (DecorationState
s {decos = ndwrs}))) s
sh Theme
t ds Word64
ds))
handleMess :: Decoration ds s Word64
-> SomeMessage -> X (Maybe (Decoration ds s Word64))
handleMess (Decoration (I (Just s :: DecorationState
s@DS{decos :: DecorationState -> [(OrigWin, DecoWin)]
decos = [(OrigWin, DecoWin)]
dwrs})) s
sh Theme
t ds Word64
ds) SomeMessage
m
| Just Event
e <- SomeMessage -> Maybe Event
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m = do ds Word64 -> DecorationState -> Event -> X ()
forall (ds :: * -> *) a.
DecorationStyle ds a =>
ds a -> DecorationState -> Event -> X ()
decorationEventHook ds Word64
ds DecorationState
s Event
e
s -> Theme -> DecorationState -> Event -> X ()
forall s.
Shrinker s =>
s -> Theme -> DecorationState -> Event -> X ()
handleEvent s
sh Theme
t DecorationState
s Event
e
Maybe (Decoration ds s Word64)
-> X (Maybe (Decoration ds s Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Decoration ds s Word64)
forall a. Maybe a
Nothing
| Just LayoutMessages
Hide <- SomeMessage -> Maybe LayoutMessages
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m = do [DecoWin] -> X ()
hideDecos (((OrigWin, DecoWin) -> DecoWin)
-> [(OrigWin, DecoWin)] -> [DecoWin]
forall a b. (a -> b) -> [a] -> [b]
map (OrigWin, DecoWin) -> DecoWin
forall a b. (a, b) -> b
snd [(OrigWin, DecoWin)]
dwrs)
Maybe (Decoration ds s Word64)
-> X (Maybe (Decoration ds s Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Decoration ds s Word64)
forall a. Maybe a
Nothing
| Just (SetTheme Theme
nt) <- SomeMessage -> Maybe DecorationMsg
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m = do DecorationState -> X ()
releaseResources DecorationState
s
Maybe (Decoration ds s Word64)
-> X (Maybe (Decoration ds s Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Decoration ds s Word64)
-> X (Maybe (Decoration ds s Word64)))
-> Maybe (Decoration ds s Word64)
-> X (Maybe (Decoration ds s Word64))
forall a b. (a -> b) -> a -> b
$ Decoration ds s Word64 -> Maybe (Decoration ds s Word64)
forall a. a -> Maybe a
Just (Decoration ds s Word64 -> Maybe (Decoration ds s Word64))
-> Decoration ds s Word64 -> Maybe (Decoration ds s Word64)
forall a b. (a -> b) -> a -> b
$ Invisible Maybe DecorationState
-> s -> Theme -> ds Word64 -> Decoration ds s Word64
forall (ds :: * -> *) s a.
Invisible Maybe DecorationState
-> s -> Theme -> ds a -> Decoration ds s a
Decoration (Maybe DecorationState -> Invisible Maybe DecorationState
forall (m :: * -> *) a. m a -> Invisible m a
I Maybe DecorationState
forall a. Maybe a
Nothing) s
sh Theme
nt ds Word64
ds
| Just LayoutMessages
ReleaseResources <- SomeMessage -> Maybe LayoutMessages
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m = do DecorationState -> X ()
releaseResources DecorationState
s
Maybe (Decoration ds s Word64)
-> X (Maybe (Decoration ds s Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (Decoration ds s Word64)
-> X (Maybe (Decoration ds s Word64)))
-> Maybe (Decoration ds s Word64)
-> X (Maybe (Decoration ds s Word64))
forall a b. (a -> b) -> a -> b
$ Decoration ds s Word64 -> Maybe (Decoration ds s Word64)
forall a. a -> Maybe a
Just (Decoration ds s Word64 -> Maybe (Decoration ds s Word64))
-> Decoration ds s Word64 -> Maybe (Decoration ds s Word64)
forall a b. (a -> b) -> a -> b
$ Invisible Maybe DecorationState
-> s -> Theme -> ds Word64 -> Decoration ds s Word64
forall (ds :: * -> *) s a.
Invisible Maybe DecorationState
-> s -> Theme -> ds a -> Decoration ds s a
Decoration (Maybe DecorationState -> Invisible Maybe DecorationState
forall (m :: * -> *) a. m a -> Invisible m a
I Maybe DecorationState
forall a. Maybe a
Nothing) s
sh Theme
t ds Word64
ds
handleMess Decoration ds s Word64
_ SomeMessage
_ = Maybe (Decoration ds s Word64)
-> X (Maybe (Decoration ds s Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (Decoration ds s Word64)
forall a. Maybe a
Nothing
modifierDescription :: Decoration ds s Word64 -> String
modifierDescription (Decoration Invisible Maybe DecorationState
_ s
_ Theme
_ ds Word64
ds) = ds Word64 -> String
forall (ds :: * -> *) a. DecorationStyle ds a => ds a -> String
describeDeco ds Word64
ds
handleEvent :: Shrinker s => s -> Theme -> DecorationState -> Event -> X ()
handleEvent :: forall s.
Shrinker s =>
s -> Theme -> DecorationState -> Event -> X ()
handleEvent s
sh Theme
t (DS [(OrigWin, DecoWin)]
dwrs XMonadFont
fs) Event
e
| PropertyEvent {ev_window :: Event -> Word64
ev_window = Word64
w} <- Event
e
, Just Int
i <- Word64
w Word64 -> [Word64] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
`elemIndex` ((OrigWin, DecoWin) -> Word64) -> [(OrigWin, DecoWin)] -> [Word64]
forall a b. (a -> b) -> [a] -> [b]
map (OrigWin -> Word64
forall a b. (a, b) -> a
fst (OrigWin -> Word64)
-> ((OrigWin, DecoWin) -> OrigWin) -> (OrigWin, DecoWin) -> Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OrigWin, DecoWin) -> OrigWin
forall a b. (a, b) -> a
fst) [(OrigWin, DecoWin)]
dwrs = s -> Theme -> XMonadFont -> (OrigWin, DecoWin) -> X ()
forall s.
Shrinker s =>
s -> Theme -> XMonadFont -> (OrigWin, DecoWin) -> X ()
updateDeco s
sh Theme
t XMonadFont
fs ([(OrigWin, DecoWin)]
dwrs [(OrigWin, DecoWin)] -> Int -> (OrigWin, DecoWin)
forall a. HasCallStack => [a] -> Int -> a
!! Int
i)
| ExposeEvent {ev_window :: Event -> Word64
ev_window = Word64
w} <- Event
e
, Just Int
i <- Word64
w Word64 -> [Word64] -> Maybe Int
forall a. Eq a => a -> [a] -> Maybe Int
`elemIndex` ((OrigWin, DecoWin) -> Maybe Word64)
-> [(OrigWin, DecoWin)] -> [Word64]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe (DecoWin -> Maybe Word64
forall a b. (a, b) -> a
fst (DecoWin -> Maybe Word64)
-> ((OrigWin, DecoWin) -> DecoWin)
-> (OrigWin, DecoWin)
-> Maybe Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (OrigWin, DecoWin) -> DecoWin
forall a b. (a, b) -> b
snd) [(OrigWin, DecoWin)]
dwrs = s -> Theme -> XMonadFont -> (OrigWin, DecoWin) -> X ()
forall s.
Shrinker s =>
s -> Theme -> XMonadFont -> (OrigWin, DecoWin) -> X ()
updateDeco s
sh Theme
t XMonadFont
fs ([(OrigWin, DecoWin)]
dwrs [(OrigWin, DecoWin)] -> Int -> (OrigWin, DecoWin)
forall a. HasCallStack => [a] -> Int -> a
!! Int
i)
handleEvent s
_ Theme
_ DecorationState
_ Event
_ = () -> X ()
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
handleMouseFocusDrag :: (DecorationStyle ds a) => ds a -> DecorationState -> Event -> X ()
handleMouseFocusDrag :: forall (ds :: * -> *) a.
DecorationStyle ds a =>
ds a -> DecorationState -> Event -> X ()
handleMouseFocusDrag ds a
ds (DS [(OrigWin, DecoWin)]
dwrs XMonadFont
_) ButtonEvent { ev_window :: Event -> Word64
ev_window = Word64
ew
, ev_event_type :: Event -> Word32
ev_event_type = Word32
et
, ev_x_root :: Event -> CInt
ev_x_root = CInt
ex
, ev_y_root :: Event -> CInt
ev_y_root = CInt
ey }
| Word32
et Word32 -> Word32 -> Bool
forall a. Eq a => a -> a -> Bool
== Word32
buttonPress
, Just ((Word64
mainw,Rectangle
r), (Word64
_, Maybe Rectangle
decoRectM)) <- Word64
-> [(OrigWin, DecoWin)]
-> Maybe (OrigWin, (Word64, Maybe Rectangle))
lookFor Word64
ew [(OrigWin, DecoWin)]
dwrs = do
let Rectangle Int32
dx Int32
_ Word32
dwh Word32
_ = Maybe Rectangle -> Rectangle
forall a. HasCallStack => Maybe a -> a
fromJust Maybe Rectangle
decoRectM
distFromLeft :: CInt
distFromLeft = CInt
ex CInt -> CInt -> CInt
forall a. Num a => a -> a -> a
- Int32 -> CInt
forall a b. (Integral a, Num b) => a -> b
fi Int32
dx
distFromRight :: CInt
distFromRight = Word32 -> CInt
forall a b. (Integral a, Num b) => a -> b
fi Word32
dwh CInt -> CInt -> CInt
forall a. Num a => a -> a -> a
- (CInt
ex CInt -> CInt -> CInt
forall a. Num a => a -> a -> a
- Int32 -> CInt
forall a b. (Integral a, Num b) => a -> b
fi Int32
dx)
dealtWith <- ds a -> Word64 -> Int -> Int -> X Bool
forall (ds :: * -> *) a.
DecorationStyle ds a =>
ds a -> Word64 -> Int -> Int -> X Bool
decorationCatchClicksHook ds a
ds Word64
mainw (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fi CInt
distFromLeft) (CInt -> Int
forall a b. (Integral a, Num b) => a -> b
fi CInt
distFromRight)
unless dealtWith $
mouseDrag (\Int32
x Int32
y -> Word64 -> X ()
focus Word64
mainw X () -> X () -> X ()
forall a b. X a -> X b -> X b
forall (m :: * -> *) a b. Monad m => m a -> m b -> m b
>> ds a -> CInt -> CInt -> OrigWin -> Int32 -> Int32 -> X ()
forall (ds :: * -> *) a.
DecorationStyle ds a =>
ds a -> CInt -> CInt -> OrigWin -> Int32 -> Int32 -> X ()
decorationWhileDraggingHook ds a
ds CInt
ex CInt
ey (Word64
mainw, Rectangle
r) Int32
x Int32
y)
(decorationAfterDraggingHook ds (mainw, r) ew)
handleMouseFocusDrag ds a
_ DecorationState
_ Event
_ = () -> X ()
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
handleDraggingInProgress :: CInt -> CInt -> (Window, Rectangle) -> Position -> Position -> X ()
handleDraggingInProgress :: CInt -> CInt -> OrigWin -> Int32 -> Int32 -> X ()
handleDraggingInProgress CInt
ex CInt
ey (Word64
_, Rectangle
r) Int32
x Int32
y = do
let rect :: Rectangle
rect = Int32 -> Int32 -> Word32 -> Word32 -> Rectangle
Rectangle (Int32
x Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
- (CInt -> Int32
forall a b. (Integral a, Num b) => a -> b
fi CInt
ex Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
- Rectangle -> Int32
rect_x Rectangle
r))
(Int32
y Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
- (CInt -> Int32
forall a b. (Integral a, Num b) => a -> b
fi CInt
ey Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
- Rectangle -> Int32
rect_y Rectangle
r))
(Rectangle -> Word32
rect_width Rectangle
r)
(Rectangle -> Word32
rect_height Rectangle
r)
WindowArrangerMsg -> X ()
forall a. Message a => a -> X ()
sendMessage (WindowArrangerMsg -> X ()) -> WindowArrangerMsg -> X ()
forall a b. (a -> b) -> a -> b
$ Rectangle -> WindowArrangerMsg
SetGeometry Rectangle
rect
lookFor :: Window -> [(OrigWin,DecoWin)] -> Maybe (OrigWin,(Window,Maybe Rectangle))
lookFor :: Word64
-> [(OrigWin, DecoWin)]
-> Maybe (OrigWin, (Word64, Maybe Rectangle))
lookFor Word64
w ((OrigWin
wr,(Just Word64
dw,Maybe Rectangle
dr)):[(OrigWin, DecoWin)]
dwrs) | Word64
w Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
dw = (OrigWin, (Word64, Maybe Rectangle))
-> Maybe (OrigWin, (Word64, Maybe Rectangle))
forall a. a -> Maybe a
Just (OrigWin
wr,(Word64
dw,Maybe Rectangle
dr))
| Bool
otherwise = Word64
-> [(OrigWin, DecoWin)]
-> Maybe (OrigWin, (Word64, Maybe Rectangle))
lookFor Word64
w [(OrigWin, DecoWin)]
dwrs
lookFor Word64
w ((OrigWin
_, (Maybe Word64
Nothing, Maybe Rectangle
_)):[(OrigWin, DecoWin)]
dwrs) = Word64
-> [(OrigWin, DecoWin)]
-> Maybe (OrigWin, (Word64, Maybe Rectangle))
lookFor Word64
w [(OrigWin, DecoWin)]
dwrs
lookFor Word64
_ [] = Maybe (OrigWin, (Word64, Maybe Rectangle))
forall a. Maybe a
Nothing
findWindowByDecoration :: Window -> DecorationState -> Maybe (OrigWin,(Window,Maybe Rectangle))
findWindowByDecoration :: Word64
-> DecorationState -> Maybe (OrigWin, (Word64, Maybe Rectangle))
findWindowByDecoration Word64
w DecorationState
ds = Word64
-> [(OrigWin, DecoWin)]
-> Maybe (OrigWin, (Word64, Maybe Rectangle))
lookFor Word64
w (DecorationState -> [(OrigWin, DecoWin)]
decos DecorationState
ds)
initState :: DecorationStyle ds Window => Theme -> ds Window -> Rectangle
-> W.Stack Window -> [(Window,Rectangle)] -> X DecorationState
initState :: forall (ds :: * -> *).
DecorationStyle ds Word64 =>
Theme
-> ds Word64
-> Rectangle
-> Stack Word64
-> [OrigWin]
-> X DecorationState
initState Theme
t ds Word64
ds Rectangle
sc Stack Word64
s [OrigWin]
wrs = do
fs <- String -> X XMonadFont
initXMF (Theme -> String
fontName Theme
t)
dwrs <- createDecos t ds sc s wrs wrs
return $ DS dwrs fs
releaseResources :: DecorationState -> X ()
releaseResources :: DecorationState -> X ()
releaseResources DecorationState
s = do
[DecoWin] -> X ()
deleteDecos (((OrigWin, DecoWin) -> DecoWin)
-> [(OrigWin, DecoWin)] -> [DecoWin]
forall a b. (a -> b) -> [a] -> [b]
map (OrigWin, DecoWin) -> DecoWin
forall a b. (a, b) -> b
snd ([(OrigWin, DecoWin)] -> [DecoWin])
-> [(OrigWin, DecoWin)] -> [DecoWin]
forall a b. (a -> b) -> a -> b
$ DecorationState -> [(OrigWin, DecoWin)]
decos DecorationState
s)
XMonadFont -> X ()
releaseXMF (DecorationState -> XMonadFont
font DecorationState
s)
createDecos :: DecorationStyle ds Window => Theme -> ds Window -> Rectangle -> W.Stack Window
-> [(Window,Rectangle)] -> [(Window,Rectangle)] -> X [(OrigWin,DecoWin)]
createDecos :: forall (ds :: * -> *).
DecorationStyle ds Word64 =>
Theme
-> ds Word64
-> Rectangle
-> Stack Word64
-> [OrigWin]
-> [OrigWin]
-> X [(OrigWin, DecoWin)]
createDecos Theme
t ds Word64
ds Rectangle
sc Stack Word64
s [OrigWin]
wrs ((Word64
w,Rectangle
r):[OrigWin]
xs) = do
deco <- ds Word64
-> Word32
-> Word32
-> Rectangle
-> Stack Word64
-> [OrigWin]
-> OrigWin
-> X (Maybe Rectangle)
forall (ds :: * -> *) a.
DecorationStyle ds a =>
ds a
-> Word32
-> Word32
-> Rectangle
-> Stack a
-> [(a, Rectangle)]
-> (a, Rectangle)
-> X (Maybe Rectangle)
decorate ds Word64
ds (Theme -> Word32
decoWidth Theme
t) (Theme -> Word32
decoHeight Theme
t) Rectangle
sc Stack Word64
s [OrigWin]
wrs (Word64
w,Rectangle
r)
case deco of
Just Rectangle
dr -> do dw <- Theme -> Rectangle -> X Word64
createDecoWindow Theme
t Rectangle
dr
dwrs <- createDecos t ds sc s wrs xs
return $ ((w,r), (Just dw, Just dr)) : dwrs
Maybe Rectangle
Nothing -> do dwrs <- Theme
-> ds Word64
-> Rectangle
-> Stack Word64
-> [OrigWin]
-> [OrigWin]
-> X [(OrigWin, DecoWin)]
forall (ds :: * -> *).
DecorationStyle ds Word64 =>
Theme
-> ds Word64
-> Rectangle
-> Stack Word64
-> [OrigWin]
-> [OrigWin]
-> X [(OrigWin, DecoWin)]
createDecos Theme
t ds Word64
ds Rectangle
sc Stack Word64
s [OrigWin]
wrs [OrigWin]
xs
return $ ((w,r), (Nothing, Nothing)) : dwrs
createDecos Theme
_ ds Word64
_ Rectangle
_ Stack Word64
_ [OrigWin]
_ [] = [(OrigWin, DecoWin)] -> X [(OrigWin, DecoWin)]
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return []
createDecoWindow :: Theme -> Rectangle -> X Window
createDecoWindow :: Theme -> Rectangle -> X Word64
createDecoWindow Theme
t Rectangle
r = do
let mask :: Maybe Word64
mask = Word64 -> Maybe Word64
forall a. a -> Maybe a
Just (Word64
exposureMask Word64 -> Word64 -> Word64
forall a. Bits a => a -> a -> a
.|. Word64
buttonPressMask)
w <- Rectangle -> Maybe Word64 -> String -> Bool -> X Word64
createNewWindow Rectangle
r Maybe Word64
mask (Theme -> String
inactiveColor Theme
t) Bool
True
d <- asks display
io $ setClassHint d w (ClassHint "xmonad-decoration" "xmonad")
pure w
showDecos :: [DecoWin] -> X ()
showDecos :: [DecoWin] -> X ()
showDecos = [Word64] -> X ()
showWindows ([Word64] -> X ()) -> ([DecoWin] -> [Word64]) -> [DecoWin] -> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DecoWin -> Maybe Word64) -> [DecoWin] -> [Word64]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe DecoWin -> Maybe Word64
forall a b. (a, b) -> a
fst ([DecoWin] -> [Word64])
-> ([DecoWin] -> [DecoWin]) -> [DecoWin] -> [Word64]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DecoWin -> Bool) -> [DecoWin] -> [DecoWin]
forall a. (a -> Bool) -> [a] -> [a]
filter (Maybe Rectangle -> Bool
forall a. Maybe a -> Bool
isJust (Maybe Rectangle -> Bool)
-> (DecoWin -> Maybe Rectangle) -> DecoWin -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DecoWin -> Maybe Rectangle
forall a b. (a, b) -> b
snd)
hideDecos :: [DecoWin] -> X ()
hideDecos :: [DecoWin] -> X ()
hideDecos = [Word64] -> X ()
hideWindows ([Word64] -> X ()) -> ([DecoWin] -> [Word64]) -> [DecoWin] -> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DecoWin -> Maybe Word64) -> [DecoWin] -> [Word64]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe DecoWin -> Maybe Word64
forall a b. (a, b) -> a
fst
deleteDecos :: [DecoWin] -> X ()
deleteDecos :: [DecoWin] -> X ()
deleteDecos = [Word64] -> X ()
deleteWindows ([Word64] -> X ()) -> ([DecoWin] -> [Word64]) -> [DecoWin] -> X ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (DecoWin -> Maybe Word64) -> [DecoWin] -> [Word64]
forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe DecoWin -> Maybe Word64
forall a b. (a, b) -> a
fst
updateDecos :: Shrinker s => s -> Theme -> XMonadFont -> [(OrigWin,DecoWin)] -> X ()
updateDecos :: forall s.
Shrinker s =>
s -> Theme -> XMonadFont -> [(OrigWin, DecoWin)] -> X ()
updateDecos s
s Theme
t XMonadFont
f = ((OrigWin, DecoWin) -> X ()) -> [(OrigWin, DecoWin)] -> X ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (((OrigWin, DecoWin) -> X ()) -> [(OrigWin, DecoWin)] -> X ())
-> ((OrigWin, DecoWin) -> X ()) -> [(OrigWin, DecoWin)] -> X ()
forall a b. (a -> b) -> a -> b
$ s -> Theme -> XMonadFont -> (OrigWin, DecoWin) -> X ()
forall s.
Shrinker s =>
s -> Theme -> XMonadFont -> (OrigWin, DecoWin) -> X ()
updateDeco s
s Theme
t XMonadFont
f
updateDeco :: Shrinker s => s -> Theme -> XMonadFont -> (OrigWin,DecoWin) -> X ()
updateDeco :: forall s.
Shrinker s =>
s -> Theme -> XMonadFont -> (OrigWin, DecoWin) -> X ()
updateDeco s
sh Theme
t XMonadFont
fs ((Word64
w,Rectangle
_),(Just Word64
dw,Just (Rectangle Int32
_ Int32
_ Word32
wh Word32
ht))) = do
nw <- (NamedWindow -> String) -> X NamedWindow -> X String
forall a b. (a -> b) -> X a -> X b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (Int -> ShowS
forall a. Int -> [a] -> [a]
take Int
2048 ShowS -> (NamedWindow -> String) -> NamedWindow -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Char -> Bool) -> ShowS
forall a. (a -> Bool) -> [a] -> [a]
takeWhile (Char -> Char -> Bool
forall a. Eq a => a -> a -> Bool
/= Char
'\n') ShowS -> (NamedWindow -> String) -> NamedWindow -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NamedWindow -> String
forall a. Show a => a -> String
show) (Word64 -> X NamedWindow
getName Word64
w)
ur <- readUrgents
dpy <- asks display
let focusColor Word64
win b
ic b
ac b
uc = b -> (Word64 -> b) -> Maybe Word64 -> b
forall b a. b -> (a -> b) -> Maybe a -> b
maybe b
ic (\Word64
focusw -> case () of
()
_ | Word64
focusw Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
win -> b
ac
| Word64
win Word64 -> [Word64] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Word64]
ur -> b
uc
| Bool
otherwise -> b
ic) (Maybe Word64 -> b)
-> (StackSet String (Layout Word64) Word64 ScreenId ScreenDetail
-> Maybe Word64)
-> StackSet String (Layout Word64) Word64 ScreenId ScreenDetail
-> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. StackSet String (Layout Word64) Word64 ScreenId ScreenDetail
-> Maybe Word64
forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek
(StackSet String (Layout Word64) Word64 ScreenId ScreenDetail -> b)
-> f (StackSet String (Layout Word64) Word64 ScreenId ScreenDetail)
-> f b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (XState
-> StackSet String (Layout Word64) Word64 ScreenId ScreenDetail)
-> f (StackSet String (Layout Word64) Word64 ScreenId ScreenDetail)
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState
-> StackSet String (Layout Word64) Word64 ScreenId ScreenDetail
windowset
(bc,borderc,borderw,tc) <-
focusColor w (inactiveColor t, inactiveBorderColor t, inactiveBorderWidth t, inactiveTextColor t)
(activeColor t, activeBorderColor t, activeBorderWidth t, activeTextColor t)
(urgentColor t, urgentBorderColor t, urgentBorderWidth t, urgentTextColor t)
let s = s -> String -> [String]
forall s. Shrinker s => s -> String -> [String]
shrinkIt s
sh
name <- shrinkWhile s (\String
n -> do size <- IO Int -> X Int
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO Int -> X Int) -> IO Int -> X Int
forall a b. (a -> b) -> a -> b
$ Display -> XMonadFont -> String -> IO Int
forall (m :: * -> *).
MonadIO m =>
Display -> XMonadFont -> String -> m Int
textWidthXMF Display
dpy XMonadFont
fs String
n
return $ size > fromIntegral wh - fromIntegral (ht `div` 2)) nw
let als = Align
AlignCenter Align -> [Align] -> [Align]
forall a. a -> [a] -> [a]
: ((String, Align) -> Align) -> [(String, Align)] -> [Align]
forall a b. (a -> b) -> [a] -> [b]
map (String, Align) -> Align
forall a b. (a, b) -> b
snd (Theme -> [(String, Align)]
windowTitleAddons Theme
t)
strs = String
name String -> [String] -> [String]
forall a. a -> [a] -> [a]
: ((String, Align) -> String) -> [(String, Align)] -> [String]
forall a b. (a -> b) -> [a] -> [b]
map (String, Align) -> String
forall a b. (a, b) -> a
fst (Theme -> [(String, Align)]
windowTitleAddons Theme
t)
i_als = (([[Bool]], Placement) -> Placement)
-> [([[Bool]], Placement)] -> [Placement]
forall a b. (a -> b) -> [a] -> [b]
map ([[Bool]], Placement) -> Placement
forall a b. (a, b) -> b
snd (Theme -> [([[Bool]], Placement)]
windowTitleIcons Theme
t)
icons = (([[Bool]], Placement) -> [[Bool]])
-> [([[Bool]], Placement)] -> [[[Bool]]]
forall a b. (a -> b) -> [a] -> [b]
map ([[Bool]], Placement) -> [[Bool]]
forall a b. (a, b) -> a
fst (Theme -> [([[Bool]], Placement)]
windowTitleIcons Theme
t)
paintTextAndIcons dw fs wh ht borderw bc borderc tc bc als strs i_als icons
updateDeco s
_ Theme
_ XMonadFont
_ (OrigWin
_,(Just Word64
w,Maybe Rectangle
Nothing)) = Word64 -> X ()
hideWindow Word64
w
updateDeco s
_ Theme
_ XMonadFont
_ (OrigWin, DecoWin)
_ = () -> X ()
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return ()
isInStack :: Eq a => W.Stack a -> a -> Bool
isInStack :: forall a. Eq a => Stack a -> a -> Bool
isInStack Stack a
s = (a -> [a] -> Bool) -> [a] -> a -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip a -> [a] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem (Stack a -> [a]
forall a. Stack a -> [a]
W.integrate Stack a
s)
isVisible :: Rectangle -> [Rectangle] -> Bool
isVisible :: Rectangle -> [Rectangle] -> Bool
isVisible Rectangle
r = [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> ([Rectangle] -> [Bool]) -> [Rectangle] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Rectangle -> [Bool] -> [Bool]) -> [Bool] -> [Rectangle] -> [Bool]
forall a b. (a -> b -> b) -> b -> [a] -> b
forall (t :: * -> *) a b.
Foldable t =>
(a -> b -> b) -> b -> t a -> b
foldr Rectangle -> [Bool] -> [Bool]
f []
where f :: Rectangle -> [Bool] -> [Bool]
f Rectangle
x [Bool]
xs = if Rectangle
r Rectangle -> Rectangle -> Bool
`isWithin` Rectangle
x then Bool
False Bool -> [Bool] -> [Bool]
forall a. a -> [a] -> [a]
: [Bool]
xs else Bool
True Bool -> [Bool] -> [Bool]
forall a. a -> [a] -> [a]
: [Bool]
xs
isInvisible :: Rectangle -> [Rectangle] -> Bool
isInvisible :: Rectangle -> [Rectangle] -> Bool
isInvisible Rectangle
r = Bool -> Bool
not (Bool -> Bool) -> ([Rectangle] -> Bool) -> [Rectangle] -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rectangle -> [Rectangle] -> Bool
isVisible Rectangle
r
isWithin :: Rectangle -> Rectangle -> Bool
isWithin :: Rectangle -> Rectangle -> Bool
isWithin (Rectangle Int32
x Int32
y Word32
w Word32
h) (Rectangle Int32
rx Int32
ry Word32
rw Word32
rh)
| Int32
x Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
>= Int32
rx, Int32
x Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int32
rx Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fi Word32
rw
, Int32
y Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
>= Int32
ry, Int32
y Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int32
ry Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fi Word32
rh
, Int32
x Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fi Word32
w Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int32
rx Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fi Word32
rw
, Int32
y Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fi Word32
h Int32 -> Int32 -> Bool
forall a. Ord a => a -> a -> Bool
<= Int32
ry Int32 -> Int32 -> Int32
forall a. Num a => a -> a -> a
+ Word32 -> Int32
forall a b. (Integral a, Num b) => a -> b
fi Word32
rh = Bool
True
| Bool
otherwise = Bool
False
shrinkWhile :: (String -> [String]) -> (String -> X Bool) -> String -> X String
shrinkWhile :: (String -> [String]) -> (String -> X Bool) -> String -> X String
shrinkWhile String -> [String]
sh String -> X Bool
p String
x = [String] -> X String
sw ([String] -> X String) -> [String] -> X String
forall a b. (a -> b) -> a -> b
$ String -> [String]
sh String
x
where sw :: [String] -> X String
sw [String
n] = String -> X String
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return String
n
sw [] = String -> X String
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return String
""
sw (String
n:[String]
ns) = do
cond <- String -> X Bool
p String
n
if cond
then sw ns
else return n
data CustomShrink = CustomShrink
instance Show CustomShrink where show :: CustomShrink -> String
show CustomShrink
_ = String
""
instance Read CustomShrink where readsPrec :: Int -> ReadS CustomShrink
readsPrec Int
_ String
s = [(CustomShrink
CustomShrink,String
s)]
class (Read s, Show s) => Shrinker s where
shrinkIt :: s -> String -> [String]
data DefaultShrinker = DefaultShrinker
instance Show DefaultShrinker where show :: DefaultShrinker -> String
show DefaultShrinker
_ = String
""
instance Read DefaultShrinker where readsPrec :: Int -> ReadS DefaultShrinker
readsPrec Int
_ String
s = [(DefaultShrinker
DefaultShrinker,String
s)]
instance Shrinker DefaultShrinker where
shrinkIt :: DefaultShrinker -> String -> [String]
shrinkIt DefaultShrinker
_ String
"" = [String
""]
shrinkIt DefaultShrinker
s String
cs = String
cs String -> [String] -> [String]
forall a. a -> [a] -> [a]
: DefaultShrinker -> String -> [String]
forall s. Shrinker s => s -> String -> [String]
shrinkIt DefaultShrinker
s (ShowS
forall a. HasCallStack => [a] -> [a]
init String
cs)
shrinkText :: DefaultShrinker
shrinkText :: DefaultShrinker
shrinkText = DefaultShrinker
DefaultShrinker