{-# LANGUAGE FlexibleContexts, MultiParamTypeClasses, FlexibleInstances #-}
{-# OPTIONS_GHC -Wno-deprecations #-}
module XMonad.Layout.Fullscreen
(
fullscreenSupport
,fullscreenSupportBorder
,fullscreenFull
,fullscreenFocus
,fullscreenFullRect
,fullscreenFocusRect
,fullscreenFloat
,fullscreenFloatRect
,fullscreenEventHook
,fullscreenManageHook
,fullscreenManageHookWith
,FullscreenMessage(..)
,FullscreenFloat, FullscreenFocus, FullscreenFull
) where
import XMonad
import XMonad.Prelude
import XMonad.Layout.LayoutModifier
import XMonad.Layout.NoBorders (SmartBorder, smartBorders)
import XMonad.Hooks.EwmhDesktops (fullscreenStartup)
import XMonad.Hooks.ManageHelpers (isFullscreen)
import XMonad.Util.WindowProperties
import qualified XMonad.Util.Rectangle as R
import qualified XMonad.StackSet as W
import qualified Data.Map as M
import Control.Arrow (second)
fullscreenSupport :: LayoutClass l Window =>
XConfig l -> XConfig (ModifiedLayout FullscreenFull l)
fullscreenSupport :: forall (l :: * -> *).
LayoutClass l Word64 =>
XConfig l -> XConfig (ModifiedLayout FullscreenFull l)
fullscreenSupport XConfig l
c = XConfig l
c {
layoutHook = fullscreenFull $ layoutHook c,
handleEventHook = handleEventHook c <> fullscreenEventHook,
manageHook = manageHook c <> fullscreenManageHook,
startupHook = startupHook c <> fullscreenStartup
}
fullscreenSupportBorder :: LayoutClass l Window =>
XConfig l -> XConfig (ModifiedLayout FullscreenFull
(ModifiedLayout SmartBorder (ModifiedLayout FullscreenFull l)))
fullscreenSupportBorder :: forall (l :: * -> *).
LayoutClass l Word64 =>
XConfig l
-> XConfig
(ModifiedLayout
FullscreenFull
(ModifiedLayout SmartBorder (ModifiedLayout FullscreenFull l)))
fullscreenSupportBorder XConfig l
c =
XConfig
(ModifiedLayout SmartBorder (ModifiedLayout FullscreenFull l))
-> XConfig
(ModifiedLayout
FullscreenFull
(ModifiedLayout SmartBorder (ModifiedLayout FullscreenFull l)))
forall (l :: * -> *).
LayoutClass l Word64 =>
XConfig l -> XConfig (ModifiedLayout FullscreenFull l)
fullscreenSupport XConfig l
c { layoutHook = smartBorders
$ fullscreenFull
$ layoutHook c
}
data FullscreenMessage = AddFullscreen Window
| RemoveFullscreen Window
| FullscreenChanged
instance Message FullscreenMessage
data FullscreenFull a = FullscreenFull W.RationalRect [a]
deriving (ReadPrec [FullscreenFull a]
ReadPrec (FullscreenFull a)
Int -> ReadS (FullscreenFull a)
ReadS [FullscreenFull a]
(Int -> ReadS (FullscreenFull a))
-> ReadS [FullscreenFull a]
-> ReadPrec (FullscreenFull a)
-> ReadPrec [FullscreenFull a]
-> Read (FullscreenFull a)
forall a. Read a => ReadPrec [FullscreenFull a]
forall a. Read a => ReadPrec (FullscreenFull a)
forall a. Read a => Int -> ReadS (FullscreenFull a)
forall a. Read a => ReadS [FullscreenFull a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (FullscreenFull a)
readsPrec :: Int -> ReadS (FullscreenFull a)
$creadList :: forall a. Read a => ReadS [FullscreenFull a]
readList :: ReadS [FullscreenFull a]
$creadPrec :: forall a. Read a => ReadPrec (FullscreenFull a)
readPrec :: ReadPrec (FullscreenFull a)
$creadListPrec :: forall a. Read a => ReadPrec [FullscreenFull a]
readListPrec :: ReadPrec [FullscreenFull a]
Read, Int -> FullscreenFull a -> ShowS
[FullscreenFull a] -> ShowS
FullscreenFull a -> String
(Int -> FullscreenFull a -> ShowS)
-> (FullscreenFull a -> String)
-> ([FullscreenFull a] -> ShowS)
-> Show (FullscreenFull a)
forall a. Show a => Int -> FullscreenFull a -> ShowS
forall a. Show a => [FullscreenFull a] -> ShowS
forall a. Show a => FullscreenFull a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> FullscreenFull a -> ShowS
showsPrec :: Int -> FullscreenFull a -> ShowS
$cshow :: forall a. Show a => FullscreenFull a -> String
show :: FullscreenFull a -> String
$cshowList :: forall a. Show a => [FullscreenFull a] -> ShowS
showList :: [FullscreenFull a] -> ShowS
Show)
data FullscreenFocus a = FullscreenFocus W.RationalRect [a]
deriving (ReadPrec [FullscreenFocus a]
ReadPrec (FullscreenFocus a)
Int -> ReadS (FullscreenFocus a)
ReadS [FullscreenFocus a]
(Int -> ReadS (FullscreenFocus a))
-> ReadS [FullscreenFocus a]
-> ReadPrec (FullscreenFocus a)
-> ReadPrec [FullscreenFocus a]
-> Read (FullscreenFocus a)
forall a. Read a => ReadPrec [FullscreenFocus a]
forall a. Read a => ReadPrec (FullscreenFocus a)
forall a. Read a => Int -> ReadS (FullscreenFocus a)
forall a. Read a => ReadS [FullscreenFocus a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. Read a => Int -> ReadS (FullscreenFocus a)
readsPrec :: Int -> ReadS (FullscreenFocus a)
$creadList :: forall a. Read a => ReadS [FullscreenFocus a]
readList :: ReadS [FullscreenFocus a]
$creadPrec :: forall a. Read a => ReadPrec (FullscreenFocus a)
readPrec :: ReadPrec (FullscreenFocus a)
$creadListPrec :: forall a. Read a => ReadPrec [FullscreenFocus a]
readListPrec :: ReadPrec [FullscreenFocus a]
Read, Int -> FullscreenFocus a -> ShowS
[FullscreenFocus a] -> ShowS
FullscreenFocus a -> String
(Int -> FullscreenFocus a -> ShowS)
-> (FullscreenFocus a -> String)
-> ([FullscreenFocus a] -> ShowS)
-> Show (FullscreenFocus a)
forall a. Show a => Int -> FullscreenFocus a -> ShowS
forall a. Show a => [FullscreenFocus a] -> ShowS
forall a. Show a => FullscreenFocus a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> FullscreenFocus a -> ShowS
showsPrec :: Int -> FullscreenFocus a -> ShowS
$cshow :: forall a. Show a => FullscreenFocus a -> String
show :: FullscreenFocus a -> String
$cshowList :: forall a. Show a => [FullscreenFocus a] -> ShowS
showList :: [FullscreenFocus a] -> ShowS
Show)
data FullscreenFloat a = FullscreenFloat W.RationalRect (M.Map a (W.RationalRect, Bool))
deriving (ReadPrec [FullscreenFloat a]
ReadPrec (FullscreenFloat a)
Int -> ReadS (FullscreenFloat a)
ReadS [FullscreenFloat a]
(Int -> ReadS (FullscreenFloat a))
-> ReadS [FullscreenFloat a]
-> ReadPrec (FullscreenFloat a)
-> ReadPrec [FullscreenFloat a]
-> Read (FullscreenFloat a)
forall a. (Ord a, Read a) => ReadPrec [FullscreenFloat a]
forall a. (Ord a, Read a) => ReadPrec (FullscreenFloat a)
forall a. (Ord a, Read a) => Int -> ReadS (FullscreenFloat a)
forall a. (Ord a, Read a) => ReadS [FullscreenFloat a]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
$creadsPrec :: forall a. (Ord a, Read a) => Int -> ReadS (FullscreenFloat a)
readsPrec :: Int -> ReadS (FullscreenFloat a)
$creadList :: forall a. (Ord a, Read a) => ReadS [FullscreenFloat a]
readList :: ReadS [FullscreenFloat a]
$creadPrec :: forall a. (Ord a, Read a) => ReadPrec (FullscreenFloat a)
readPrec :: ReadPrec (FullscreenFloat a)
$creadListPrec :: forall a. (Ord a, Read a) => ReadPrec [FullscreenFloat a]
readListPrec :: ReadPrec [FullscreenFloat a]
Read, Int -> FullscreenFloat a -> ShowS
[FullscreenFloat a] -> ShowS
FullscreenFloat a -> String
(Int -> FullscreenFloat a -> ShowS)
-> (FullscreenFloat a -> String)
-> ([FullscreenFloat a] -> ShowS)
-> Show (FullscreenFloat a)
forall a. Show a => Int -> FullscreenFloat a -> ShowS
forall a. Show a => [FullscreenFloat a] -> ShowS
forall a. Show a => FullscreenFloat a -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: forall a. Show a => Int -> FullscreenFloat a -> ShowS
showsPrec :: Int -> FullscreenFloat a -> ShowS
$cshow :: forall a. Show a => FullscreenFloat a -> String
show :: FullscreenFloat a -> String
$cshowList :: forall a. Show a => [FullscreenFloat a] -> ShowS
showList :: [FullscreenFloat a] -> ShowS
Show)
instance LayoutModifier FullscreenFull Window where
pureMess :: FullscreenFull Word64
-> SomeMessage -> Maybe (FullscreenFull Word64)
pureMess ff :: FullscreenFull Word64
ff@(FullscreenFull RationalRect
frect [Word64]
fulls) SomeMessage
m = case SomeMessage -> Maybe FullscreenMessage
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m of
Just (AddFullscreen Word64
win) -> FullscreenFull Word64 -> Maybe (FullscreenFull Word64)
forall a. a -> Maybe a
Just (FullscreenFull Word64 -> Maybe (FullscreenFull Word64))
-> FullscreenFull Word64 -> Maybe (FullscreenFull Word64)
forall a b. (a -> b) -> a -> b
$ RationalRect -> [Word64] -> FullscreenFull Word64
forall a. RationalRect -> [a] -> FullscreenFull a
FullscreenFull RationalRect
frect ([Word64] -> FullscreenFull Word64)
-> [Word64] -> FullscreenFull Word64
forall a b. (a -> b) -> a -> b
$ [Word64] -> [Word64]
forall a. Eq a => [a] -> [a]
nub ([Word64] -> [Word64]) -> [Word64] -> [Word64]
forall a b. (a -> b) -> a -> b
$ Word64
winWord64 -> [Word64] -> [Word64]
forall a. a -> [a] -> [a]
:[Word64]
fulls
Just (RemoveFullscreen Word64
win) -> FullscreenFull Word64 -> Maybe (FullscreenFull Word64)
forall a. a -> Maybe a
Just (FullscreenFull Word64 -> Maybe (FullscreenFull Word64))
-> FullscreenFull Word64 -> Maybe (FullscreenFull Word64)
forall a b. (a -> b) -> a -> b
$ RationalRect -> [Word64] -> FullscreenFull Word64
forall a. RationalRect -> [a] -> FullscreenFull a
FullscreenFull RationalRect
frect ([Word64] -> FullscreenFull Word64)
-> [Word64] -> FullscreenFull Word64
forall a b. (a -> b) -> a -> b
$ Word64 -> [Word64] -> [Word64]
forall a. Eq a => a -> [a] -> [a]
delete Word64
win [Word64]
fulls
Just FullscreenMessage
FullscreenChanged -> FullscreenFull Word64 -> Maybe (FullscreenFull Word64)
forall a. a -> Maybe a
Just FullscreenFull Word64
ff
Maybe FullscreenMessage
_ -> Maybe (FullscreenFull Word64)
forall a. Maybe a
Nothing
pureModifier :: FullscreenFull Word64
-> Rectangle
-> Maybe (Stack Word64)
-> [(Word64, Rectangle)]
-> ([(Word64, Rectangle)], Maybe (FullscreenFull Word64))
pureModifier (FullscreenFull RationalRect
frect [Word64]
fulls) Rectangle
rect Maybe (Stack Word64)
_ [(Word64, Rectangle)]
list =
([(Word64, Rectangle)]
visfulls' [(Word64, Rectangle)]
-> [(Word64, Rectangle)] -> [(Word64, Rectangle)]
forall a. [a] -> [a] -> [a]
++ [(Word64, Rectangle)]
rest', Maybe (FullscreenFull Word64)
forall a. Maybe a
Nothing)
where ([(Word64, Rectangle)]
visfulls,[(Word64, Rectangle)]
rest) = ((Word64, Rectangle) -> Bool)
-> [(Word64, Rectangle)]
-> ([(Word64, Rectangle)], [(Word64, Rectangle)])
forall a. (a -> Bool) -> [a] -> ([a], [a])
partition ((Word64 -> [Word64] -> Bool) -> [Word64] -> Word64 -> Bool
forall a b c. (a -> b -> c) -> b -> a -> c
flip Word64 -> [Word64] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem [Word64]
fulls (Word64 -> Bool)
-> ((Word64, Rectangle) -> Word64) -> (Word64, Rectangle) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word64, Rectangle) -> Word64
forall a b. (a, b) -> a
fst) [(Word64, Rectangle)]
list
visfulls' :: [(Word64, Rectangle)]
visfulls' = ((Word64, Rectangle) -> (Word64, Rectangle))
-> [(Word64, Rectangle)] -> [(Word64, Rectangle)]
forall a b. (a -> b) -> [a] -> [b]
map ((Rectangle -> Rectangle)
-> (Word64, Rectangle) -> (Word64, Rectangle)
forall b c d. (b -> c) -> (d, b) -> (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ((Rectangle -> Rectangle)
-> (Word64, Rectangle) -> (Word64, Rectangle))
-> (Rectangle -> Rectangle)
-> (Word64, Rectangle)
-> (Word64, Rectangle)
forall a b. (a -> b) -> a -> b
$ Rectangle -> Rectangle -> Rectangle
forall a b. a -> b -> a
const Rectangle
rect') [(Word64, Rectangle)]
visfulls
rest' :: [(Word64, Rectangle)]
rest' = if [(Word64, Rectangle)] -> Bool
forall a. [a] -> Bool
forall (t :: * -> *) a. Foldable t => t a -> Bool
null [(Word64, Rectangle)]
visfulls'
then [(Word64, Rectangle)]
rest
else ((Word64, Rectangle) -> Bool)
-> [(Word64, Rectangle)] -> [(Word64, Rectangle)]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool)
-> ((Word64, Rectangle) -> Bool) -> (Word64, Rectangle) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Rectangle -> Rectangle -> Bool
R.supersetOf Rectangle
rect' (Rectangle -> Bool)
-> ((Word64, Rectangle) -> Rectangle)
-> (Word64, Rectangle)
-> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word64, Rectangle) -> Rectangle
forall a b. (a, b) -> b
snd) [(Word64, Rectangle)]
rest
rect' :: Rectangle
rect' = Rectangle -> RationalRect -> Rectangle
scaleRationalRect Rectangle
rect RationalRect
frect
instance LayoutModifier FullscreenFocus Window where
pureMess :: FullscreenFocus Word64
-> SomeMessage -> Maybe (FullscreenFocus Word64)
pureMess ff :: FullscreenFocus Word64
ff@(FullscreenFocus RationalRect
frect [Word64]
fulls) SomeMessage
m = case SomeMessage -> Maybe FullscreenMessage
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m of
Just (AddFullscreen Word64
win) -> FullscreenFocus Word64 -> Maybe (FullscreenFocus Word64)
forall a. a -> Maybe a
Just (FullscreenFocus Word64 -> Maybe (FullscreenFocus Word64))
-> FullscreenFocus Word64 -> Maybe (FullscreenFocus Word64)
forall a b. (a -> b) -> a -> b
$ RationalRect -> [Word64] -> FullscreenFocus Word64
forall a. RationalRect -> [a] -> FullscreenFocus a
FullscreenFocus RationalRect
frect ([Word64] -> FullscreenFocus Word64)
-> [Word64] -> FullscreenFocus Word64
forall a b. (a -> b) -> a -> b
$ [Word64] -> [Word64]
forall a. Eq a => [a] -> [a]
nub ([Word64] -> [Word64]) -> [Word64] -> [Word64]
forall a b. (a -> b) -> a -> b
$ Word64
winWord64 -> [Word64] -> [Word64]
forall a. a -> [a] -> [a]
:[Word64]
fulls
Just (RemoveFullscreen Word64
win) -> FullscreenFocus Word64 -> Maybe (FullscreenFocus Word64)
forall a. a -> Maybe a
Just (FullscreenFocus Word64 -> Maybe (FullscreenFocus Word64))
-> FullscreenFocus Word64 -> Maybe (FullscreenFocus Word64)
forall a b. (a -> b) -> a -> b
$ RationalRect -> [Word64] -> FullscreenFocus Word64
forall a. RationalRect -> [a] -> FullscreenFocus a
FullscreenFocus RationalRect
frect ([Word64] -> FullscreenFocus Word64)
-> [Word64] -> FullscreenFocus Word64
forall a b. (a -> b) -> a -> b
$ Word64 -> [Word64] -> [Word64]
forall a. Eq a => a -> [a] -> [a]
delete Word64
win [Word64]
fulls
Just FullscreenMessage
FullscreenChanged -> FullscreenFocus Word64 -> Maybe (FullscreenFocus Word64)
forall a. a -> Maybe a
Just FullscreenFocus Word64
ff
Maybe FullscreenMessage
_ -> Maybe (FullscreenFocus Word64)
forall a. Maybe a
Nothing
pureModifier :: FullscreenFocus Word64
-> Rectangle
-> Maybe (Stack Word64)
-> [(Word64, Rectangle)]
-> ([(Word64, Rectangle)], Maybe (FullscreenFocus Word64))
pureModifier (FullscreenFocus RationalRect
frect [Word64]
fulls) Rectangle
rect (Just W.Stack {focus :: forall a. Stack a -> a
W.focus = Word64
f}) [(Word64, Rectangle)]
list
| Word64
f Word64 -> [Word64] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [Word64]
fulls = ((Word64
f, Rectangle
rect') (Word64, Rectangle)
-> [(Word64, Rectangle)] -> [(Word64, Rectangle)]
forall a. a -> [a] -> [a]
: [(Word64, Rectangle)]
rest, Maybe (FullscreenFocus Word64)
forall a. Maybe a
Nothing)
| Bool
otherwise = ([(Word64, Rectangle)]
list, Maybe (FullscreenFocus Word64)
forall a. Maybe a
Nothing)
where rest :: [(Word64, Rectangle)]
rest = ((Word64, Rectangle) -> Bool)
-> [(Word64, Rectangle)] -> [(Word64, Rectangle)]
forall a. (a -> Bool) -> [a] -> [a]
filter (Bool -> Bool
not (Bool -> Bool)
-> ((Word64, Rectangle) -> Bool) -> (Word64, Rectangle) -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Word64 -> Bool)
-> (Rectangle -> Bool) -> (Word64, Rectangle) -> Bool
forall a b. (a -> Bool) -> (b -> Bool) -> (a, b) -> Bool
orP (Word64 -> Word64 -> Bool
forall a. Eq a => a -> a -> Bool
== Word64
f) (Rectangle -> Rectangle -> Bool
R.supersetOf Rectangle
rect')) [(Word64, Rectangle)]
list
rect' :: Rectangle
rect' = Rectangle -> RationalRect -> Rectangle
scaleRationalRect Rectangle
rect RationalRect
frect
pureModifier FullscreenFocus Word64
_ Rectangle
_ Maybe (Stack Word64)
Nothing [(Word64, Rectangle)]
list = ([(Word64, Rectangle)]
list, Maybe (FullscreenFocus Word64)
forall a. Maybe a
Nothing)
instance LayoutModifier FullscreenFloat Window where
handleMess :: FullscreenFloat Word64
-> SomeMessage -> X (Maybe (FullscreenFloat Word64))
handleMess (FullscreenFloat RationalRect
frect Map Word64 (RationalRect, Bool)
fulls) SomeMessage
m = case SomeMessage -> Maybe FullscreenMessage
forall m. Message m => SomeMessage -> Maybe m
fromMessage SomeMessage
m of
Just (AddFullscreen Word64
win) -> do
mrect <- Word64 -> Map Word64 RationalRect -> Maybe RationalRect
forall k a. Ord k => k -> Map k a -> Maybe a
M.lookup Word64
win (Map Word64 RationalRect -> Maybe RationalRect)
-> (WindowSet -> Map Word64 RationalRect)
-> WindowSet
-> Maybe RationalRect
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet -> Map Word64 RationalRect
forall i l a sid sd. StackSet i l a sid sd -> Map a RationalRect
W.floating (WindowSet -> Maybe RationalRect)
-> X WindowSet -> X (Maybe RationalRect)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (XState -> WindowSet) -> X WindowSet
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState -> WindowSet
windowset
return $ case mrect of
Just RationalRect
rect -> FullscreenFloat Word64 -> Maybe (FullscreenFloat Word64)
forall a. a -> Maybe a
Just (FullscreenFloat Word64 -> Maybe (FullscreenFloat Word64))
-> FullscreenFloat Word64 -> Maybe (FullscreenFloat Word64)
forall a b. (a -> b) -> a -> b
$ RationalRect
-> Map Word64 (RationalRect, Bool) -> FullscreenFloat Word64
forall a.
RationalRect -> Map a (RationalRect, Bool) -> FullscreenFloat a
FullscreenFloat RationalRect
frect (Map Word64 (RationalRect, Bool) -> FullscreenFloat Word64)
-> Map Word64 (RationalRect, Bool) -> FullscreenFloat Word64
forall a b. (a -> b) -> a -> b
$ Word64
-> (RationalRect, Bool)
-> Map Word64 (RationalRect, Bool)
-> Map Word64 (RationalRect, Bool)
forall k a. Ord k => k -> a -> Map k a -> Map k a
M.insert Word64
win (RationalRect
rect,Bool
True) Map Word64 (RationalRect, Bool)
fulls
Maybe RationalRect
Nothing -> Maybe (FullscreenFloat Word64)
forall a. Maybe a
Nothing
Just (RemoveFullscreen Word64
win) ->
Maybe (FullscreenFloat Word64)
-> X (Maybe (FullscreenFloat Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (Maybe (FullscreenFloat Word64)
-> X (Maybe (FullscreenFloat Word64)))
-> Maybe (FullscreenFloat Word64)
-> X (Maybe (FullscreenFloat Word64))
forall a b. (a -> b) -> a -> b
$ FullscreenFloat Word64 -> Maybe (FullscreenFloat Word64)
forall a. a -> Maybe a
Just (FullscreenFloat Word64 -> Maybe (FullscreenFloat Word64))
-> FullscreenFloat Word64 -> Maybe (FullscreenFloat Word64)
forall a b. (a -> b) -> a -> b
$ RationalRect
-> Map Word64 (RationalRect, Bool) -> FullscreenFloat Word64
forall a.
RationalRect -> Map a (RationalRect, Bool) -> FullscreenFloat a
FullscreenFloat RationalRect
frect (Map Word64 (RationalRect, Bool) -> FullscreenFloat Word64)
-> Map Word64 (RationalRect, Bool) -> FullscreenFloat Word64
forall a b. (a -> b) -> a -> b
$ ((RationalRect, Bool) -> (RationalRect, Bool))
-> Word64
-> Map Word64 (RationalRect, Bool)
-> Map Word64 (RationalRect, Bool)
forall k a. Ord k => (a -> a) -> k -> Map k a -> Map k a
M.adjust ((Bool -> Bool) -> (RationalRect, Bool) -> (RationalRect, Bool)
forall b c d. (b -> c) -> (d, b) -> (d, c)
forall (a :: * -> * -> *) b c d.
Arrow a =>
a b c -> a (d, b) (d, c)
second ((Bool -> Bool) -> (RationalRect, Bool) -> (RationalRect, Bool))
-> (Bool -> Bool) -> (RationalRect, Bool) -> (RationalRect, Bool)
forall a b. (a -> b) -> a -> b
$ Bool -> Bool -> Bool
forall a b. a -> b -> a
const Bool
False) Word64
win Map Word64 (RationalRect, Bool)
fulls
Just FullscreenMessage
FullscreenChanged -> do
st <- X XState
forall s (m :: * -> *). MonadState s m => m s
get
let ws = XState -> WindowSet
windowset XState
st
flt = WindowSet -> Map Word64 RationalRect
forall i l a sid sd. StackSet i l a sid sd -> Map a RationalRect
W.floating WindowSet
ws
flt' = ((RationalRect, Bool) -> RationalRect -> RationalRect)
-> Map Word64 (RationalRect, Bool)
-> Map Word64 RationalRect
-> Map Word64 RationalRect
forall k a b c.
Ord k =>
(a -> b -> c) -> Map k a -> Map k b -> Map k c
M.intersectionWith (RationalRect, Bool) -> RationalRect -> RationalRect
forall {p}. (RationalRect, Bool) -> p -> RationalRect
doFull Map Word64 (RationalRect, Bool)
fulls Map Word64 RationalRect
flt
put st {windowset = ws {W.floating = M.union flt' flt}}
return $ Just $ FullscreenFloat frect $ M.filter snd fulls
where doFull :: (RationalRect, Bool) -> p -> RationalRect
doFull (RationalRect
_, Bool
True) p
_ = RationalRect
frect
doFull (RationalRect
rect, Bool
False) p
_ = RationalRect
rect
Maybe FullscreenMessage
Nothing -> Maybe (FullscreenFloat Word64)
-> X (Maybe (FullscreenFloat Word64))
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return Maybe (FullscreenFloat Word64)
forall a. Maybe a
Nothing
fullscreenFull :: LayoutClass l a =>
l a -> ModifiedLayout FullscreenFull l a
fullscreenFull :: forall (l :: * -> *) a.
LayoutClass l a =>
l a -> ModifiedLayout FullscreenFull l a
fullscreenFull = RationalRect -> l a -> ModifiedLayout FullscreenFull l a
forall (l :: * -> *) a.
LayoutClass l a =>
RationalRect -> l a -> ModifiedLayout FullscreenFull l a
fullscreenFullRect (RationalRect -> l a -> ModifiedLayout FullscreenFull l a)
-> RationalRect -> l a -> ModifiedLayout FullscreenFull l a
forall a b. (a -> b) -> a -> b
$ Ratio Integer
-> Ratio Integer -> Ratio Integer -> Ratio Integer -> RationalRect
W.RationalRect Ratio Integer
0 Ratio Integer
0 Ratio Integer
1 Ratio Integer
1
fullscreenFullRect :: LayoutClass l a =>
W.RationalRect -> l a -> ModifiedLayout FullscreenFull l a
fullscreenFullRect :: forall (l :: * -> *) a.
LayoutClass l a =>
RationalRect -> l a -> ModifiedLayout FullscreenFull l a
fullscreenFullRect RationalRect
r = FullscreenFull a -> l a -> ModifiedLayout FullscreenFull l a
forall (m :: * -> *) (l :: * -> *) a.
m a -> l a -> ModifiedLayout m l a
ModifiedLayout (FullscreenFull a -> l a -> ModifiedLayout FullscreenFull l a)
-> FullscreenFull a -> l a -> ModifiedLayout FullscreenFull l a
forall a b. (a -> b) -> a -> b
$ RationalRect -> [a] -> FullscreenFull a
forall a. RationalRect -> [a] -> FullscreenFull a
FullscreenFull RationalRect
r []
fullscreenFocus :: LayoutClass l a =>
l a -> ModifiedLayout FullscreenFocus l a
fullscreenFocus :: forall (l :: * -> *) a.
LayoutClass l a =>
l a -> ModifiedLayout FullscreenFocus l a
fullscreenFocus = RationalRect -> l a -> ModifiedLayout FullscreenFocus l a
forall (l :: * -> *) a.
LayoutClass l a =>
RationalRect -> l a -> ModifiedLayout FullscreenFocus l a
fullscreenFocusRect (RationalRect -> l a -> ModifiedLayout FullscreenFocus l a)
-> RationalRect -> l a -> ModifiedLayout FullscreenFocus l a
forall a b. (a -> b) -> a -> b
$ Ratio Integer
-> Ratio Integer -> Ratio Integer -> Ratio Integer -> RationalRect
W.RationalRect Ratio Integer
0 Ratio Integer
0 Ratio Integer
1 Ratio Integer
1
fullscreenFocusRect :: LayoutClass l a =>
W.RationalRect -> l a -> ModifiedLayout FullscreenFocus l a
fullscreenFocusRect :: forall (l :: * -> *) a.
LayoutClass l a =>
RationalRect -> l a -> ModifiedLayout FullscreenFocus l a
fullscreenFocusRect RationalRect
r = FullscreenFocus a -> l a -> ModifiedLayout FullscreenFocus l a
forall (m :: * -> *) (l :: * -> *) a.
m a -> l a -> ModifiedLayout m l a
ModifiedLayout (FullscreenFocus a -> l a -> ModifiedLayout FullscreenFocus l a)
-> FullscreenFocus a -> l a -> ModifiedLayout FullscreenFocus l a
forall a b. (a -> b) -> a -> b
$ RationalRect -> [a] -> FullscreenFocus a
forall a. RationalRect -> [a] -> FullscreenFocus a
FullscreenFocus RationalRect
r []
fullscreenFloat :: LayoutClass l a =>
l a -> ModifiedLayout FullscreenFloat l a
fullscreenFloat :: forall (l :: * -> *) a.
LayoutClass l a =>
l a -> ModifiedLayout FullscreenFloat l a
fullscreenFloat = RationalRect -> l a -> ModifiedLayout FullscreenFloat l a
forall (l :: * -> *) a.
LayoutClass l a =>
RationalRect -> l a -> ModifiedLayout FullscreenFloat l a
fullscreenFloatRect (RationalRect -> l a -> ModifiedLayout FullscreenFloat l a)
-> RationalRect -> l a -> ModifiedLayout FullscreenFloat l a
forall a b. (a -> b) -> a -> b
$ Ratio Integer
-> Ratio Integer -> Ratio Integer -> Ratio Integer -> RationalRect
W.RationalRect Ratio Integer
0 Ratio Integer
0 Ratio Integer
1 Ratio Integer
1
fullscreenFloatRect :: LayoutClass l a =>
W.RationalRect -> l a -> ModifiedLayout FullscreenFloat l a
fullscreenFloatRect :: forall (l :: * -> *) a.
LayoutClass l a =>
RationalRect -> l a -> ModifiedLayout FullscreenFloat l a
fullscreenFloatRect RationalRect
r = FullscreenFloat a -> l a -> ModifiedLayout FullscreenFloat l a
forall (m :: * -> *) (l :: * -> *) a.
m a -> l a -> ModifiedLayout m l a
ModifiedLayout (FullscreenFloat a -> l a -> ModifiedLayout FullscreenFloat l a)
-> FullscreenFloat a -> l a -> ModifiedLayout FullscreenFloat l a
forall a b. (a -> b) -> a -> b
$ RationalRect -> Map a (RationalRect, Bool) -> FullscreenFloat a
forall a.
RationalRect -> Map a (RationalRect, Bool) -> FullscreenFloat a
FullscreenFloat RationalRect
r Map a (RationalRect, Bool)
forall k a. Map k a
M.empty
fullscreenEventHook :: Event -> X All
fullscreenEventHook :: Event -> X All
fullscreenEventHook (ClientMessageEvent EventType
_ CULong
_ Bool
_ Display
dpy Word64
win Word64
typ (CInt
action:[CInt]
dats)) = do
wmstate <- String -> X Word64
getAtom String
"_NET_WM_STATE"
fullsc <- getAtom "_NET_WM_STATE_FULLSCREEN"
wstate <- fromMaybe [] <$> getProp32 wmstate win
let isFull = Word64 -> CLong
forall a b. (Integral a, Num b) => a -> b
fi Word64
fullsc CLong -> [CLong] -> Bool
forall a. Eq a => a -> [a] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` [CLong]
wstate
remove = CInt
0
add = CInt
1
toggle = CInt
2
chWState [CLong] -> [CLong]
f = IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Display -> Word64 -> Word64 -> Word64 -> CInt -> [CLong] -> IO ()
changeProperty32 Display
dpy Word64
win Word64
wmstate Word64
aTOM CInt
propModeReplace ([CLong] -> [CLong]
f [CLong]
wstate)
when (typ == wmstate && fi fullsc `elem` dats) $ do
when (action == add || (action == toggle && not isFull)) $ do
chWState (fi fullsc:)
broadcastMessage $ AddFullscreen win
sendMessage FullscreenChanged
when (action == remove || (action == toggle && isFull)) $ do
chWState $ delete (fi fullsc)
broadcastMessage $ RemoveFullscreen win
sendMessage FullscreenChanged
return $ All True
fullscreenEventHook DestroyWindowEvent{ev_window :: Event -> Word64
ev_window = Word64
w} = do
FullscreenMessage -> X ()
forall a. Message a => a -> X ()
broadcastMessage (FullscreenMessage -> X ()) -> FullscreenMessage -> X ()
forall a b. (a -> b) -> a -> b
$ Word64 -> FullscreenMessage
RemoveFullscreen Word64
w
cw <- Screen String (Layout Word64) Word64 ScreenId ScreenDetail
-> Workspace String (Layout Word64) Word64
forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace (Screen String (Layout Word64) Word64 ScreenId ScreenDetail
-> Workspace String (Layout Word64) Word64)
-> (WindowSet
-> Screen String (Layout Word64) Word64 ScreenId ScreenDetail)
-> WindowSet
-> Workspace String (Layout Word64) Word64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. WindowSet
-> Screen String (Layout Word64) Word64 ScreenId ScreenDetail
forall i l a sid sd. StackSet i l a sid sd -> Screen i l a sid sd
W.current (WindowSet -> Workspace String (Layout Word64) Word64)
-> X WindowSet -> X (Workspace String (Layout Word64) Word64)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (XState -> WindowSet) -> X WindowSet
forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState -> WindowSet
windowset
sendMessageWithNoRefresh FullscreenChanged cw
return $ All True
fullscreenEventHook Event
_ = All -> X All
forall a. a -> X a
forall (m :: * -> *) a. Monad m => a -> m a
return (All -> X All) -> All -> X All
forall a b. (a -> b) -> a -> b
$ Bool -> All
All Bool
True
fullscreenManageHook :: ManageHook
fullscreenManageHook :: Query (Endo WindowSet)
fullscreenManageHook = Query Bool -> Query (Endo WindowSet)
fullscreenManageHook' Query Bool
isFullscreen
fullscreenManageHookWith :: Query Bool -> ManageHook
fullscreenManageHookWith :: Query Bool -> Query (Endo WindowSet)
fullscreenManageHookWith Query Bool
h = Query Bool -> Query (Endo WindowSet)
fullscreenManageHook' (Query Bool -> Query (Endo WindowSet))
-> Query Bool -> Query (Endo WindowSet)
forall a b. (a -> b) -> a -> b
$ Query Bool
isFullscreen Query Bool -> Query Bool -> Query Bool
forall (m :: * -> *). Monad m => m Bool -> m Bool -> m Bool
<||> Query Bool
h
fullscreenManageHook' :: Query Bool -> ManageHook
fullscreenManageHook' :: Query Bool -> Query (Endo WindowSet)
fullscreenManageHook' Query Bool
isFull = Query Bool
isFull Query Bool -> Query (Endo WindowSet) -> Query (Endo WindowSet)
forall (m :: * -> *) a. (Monad m, Monoid a) => m Bool -> m a -> m a
--> do
w <- Query Word64
forall r (m :: * -> *). MonadReader r m => m r
ask
liftX $ do
broadcastMessage $ AddFullscreen w
cw <- W.workspace . W.current <$> gets windowset
sendMessageWithNoRefresh FullscreenChanged cw
idHook
orP :: (a -> Bool) -> (b -> Bool) -> (a, b) -> Bool
orP :: forall a b. (a -> Bool) -> (b -> Bool) -> (a, b) -> Bool
orP a -> Bool
f b -> Bool
g (a
x, b
y) = a -> Bool
f a
x Bool -> Bool -> Bool
|| b -> Bool
g b
y