module XMonad.Hooks.FadeInactive (
setOpacity,
isUnfocused,
isUnfocusedOnCurrentWS,
fadeIn,
fadeOut,
fadeIf,
fadeInactiveLogHook,
fadeInactiveCurrentWSLogHook,
fadeOutLogHook
) where
import XMonad
import XMonad.Prelude
import qualified XMonad.StackSet as W
rationalToOpacity :: Integral a => Rational -> a
rationalToOpacity :: forall a. Integral a => Rational -> a
rationalToOpacity Rational
perc
| Rational
perc forall a. Ord a => a -> a -> Bool
< Rational
0 Bool -> Bool -> Bool
|| Rational
perc forall a. Ord a => a -> a -> Bool
> Rational
1 = forall a b. (RealFrac a, Integral b) => a -> b
round Rational
perc
| Bool
otherwise = forall a b. (RealFrac a, Integral b) => a -> b
round forall a b. (a -> b) -> a -> b
$ Rational
perc forall a. Num a => a -> a -> a
* Rational
0xffffffff
setOpacity :: Window -> Rational -> X ()
setOpacity :: Window -> Rational -> X ()
setOpacity Window
w Rational
t = forall a. (Display -> X a) -> X a
withDisplay forall a b. (a -> b) -> a -> b
$ \Display
dpy -> do
Window
a <- String -> X Window
getAtom String
"_NET_WM_WINDOW_OPACITY"
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io forall a b. (a -> b) -> a -> b
$ Display -> Window -> Window -> Window -> CInt -> [CLong] -> IO ()
changeProperty32 Display
dpy Window
w Window
a Window
cARDINAL CInt
propModeReplace [forall a. Integral a => Rational -> a
rationalToOpacity Rational
t]
fadeOut :: Rational -> Window -> X ()
fadeOut :: Rational -> Window -> X ()
fadeOut = forall a b c. (a -> b -> c) -> b -> a -> c
flip Window -> Rational -> X ()
setOpacity
fadeIn :: Window -> X ()
fadeIn :: Window -> X ()
fadeIn = Rational -> Window -> X ()
fadeOut Rational
1
fadeIf :: Query Bool -> Rational -> Query Rational
fadeIf :: Query Bool -> Rational -> Query Rational
fadeIf Query Bool
qry Rational
amt = Query Bool
qry forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Bool
b -> forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ if Bool
b then Rational
amt else Rational
1
fadeInactiveLogHook :: Rational -> X ()
fadeInactiveLogHook :: Rational -> X ()
fadeInactiveLogHook = Query Rational -> X ()
fadeOutLogHook forall b c a. (b -> c) -> (a -> b) -> a -> c
. Query Bool -> Rational -> Query Rational
fadeIf Query Bool
isUnfocused
fadeInactiveCurrentWSLogHook :: Rational -> X ()
fadeInactiveCurrentWSLogHook :: Rational -> X ()
fadeInactiveCurrentWSLogHook = Query Rational -> X ()
fadeOutLogHook forall b c a. (b -> c) -> (a -> b) -> a -> c
. Query Bool -> Rational -> Query Rational
fadeIf Query Bool
isUnfocusedOnCurrentWS
isUnfocused :: Query Bool
isUnfocused :: Query Bool
isUnfocused = forall r (m :: * -> *). MonadReader r m => m r
ask forall (m :: * -> *) a b. Monad m => m a -> (a -> m b) -> m b
>>= \Window
w -> forall a. X a -> Query a
liftX forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets forall a b. (a -> b) -> a -> b
$ (forall a. a -> Maybe a
Just Window
w forall a. Eq a => a -> a -> Bool
/=) forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState -> WindowSet
windowset
isUnfocusedOnCurrentWS :: Query Bool
isUnfocusedOnCurrentWS :: Query Bool
isUnfocusedOnCurrentWS = do
Window
w <- forall r (m :: * -> *). MonadReader r m => m r
ask
WindowSet
ws <- forall a. X a -> Query a
liftX forall a b. (a -> b) -> a -> b
$ forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets XState -> WindowSet
windowset
let thisWS :: Bool
thisWS = Window
w forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
`elem` forall i l a s sd. StackSet i l a s sd -> [a]
W.index WindowSet
ws
unfocused :: Bool
unfocused = forall a. a -> Maybe a
Just Window
w forall a. Eq a => a -> a -> Bool
/= forall i l a s sd. StackSet i l a s sd -> Maybe a
W.peek WindowSet
ws
forall (m :: * -> *) a. Monad m => a -> m a
return forall a b. (a -> b) -> a -> b
$ Bool
thisWS Bool -> Bool -> Bool
&& Bool
unfocused
fadeOutLogHook :: Query Rational -> X ()
fadeOutLogHook :: Query Rational -> X ()
fadeOutLogHook Query Rational
qry = forall a. (WindowSet -> X a) -> X a
withWindowSet forall a b. (a -> b) -> a -> b
$ \WindowSet
s -> do
let visibleWins :: [Window]
visibleWins = (forall a. Maybe (Stack a) -> [a]
W.integrate' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack forall b c a. (b -> c) -> (a -> b) -> a -> c
. 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 a b. (a -> b) -> a -> b
$ WindowSet
s) forall a. [a] -> [a] -> [a]
++
forall (t :: * -> *) a b. Foldable t => (a -> [b]) -> t a -> [b]
concatMap (forall a. Maybe (Stack a) -> [a]
W.integrate' forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i l a. Workspace i l a -> Maybe (Stack a)
W.stack forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i l a sid sd. Screen i l a sid sd -> Workspace i l a
W.workspace) (forall i l a sid sd. StackSet i l a sid sd -> [Screen i l a sid sd]
W.visible WindowSet
s)
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
t a -> (a -> m b) -> m ()
forM_ [Window]
visibleWins forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a b c.
Applicative f =>
(a -> b -> c) -> f a -> f b -> f c
liftA2 forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
(=<<) Window -> Rational -> X ()
setOpacity (forall a. Query a -> Window -> X a
runQuery Query Rational
qry)