module XMonad.Actions.UpdateFocus (
focusOnMouseMove,
adjustEventInput,
focusUnderPointer,
) where
import XMonad
import XMonad.Prelude
import qualified XMonad.StackSet as W
focusOnMouseMove :: Event -> X All
focusOnMouseMove :: Event -> X All
focusOnMouseMove MotionEvent{ ev_x :: Event -> CInt
ev_x = CInt
x, ev_y :: Event -> CInt
ev_y = CInt
y, ev_window :: Event -> Window
ev_window = Window
root } = do
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (CInt
x forall a. Integral a => a -> a -> a
`mod` CInt
15 forall a. Eq a => a -> a -> Bool
== CInt
0 Bool -> Bool -> Bool
|| CInt
y forall a. Integral a => a -> a -> a
`mod` CInt
15 forall a. Eq a => a -> a -> Bool
== CInt
0) forall a b. (a -> b) -> a -> b
$ do
Display
dpy <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Display
display
Maybe Window
foc <- forall a. (WindowSet -> X a) -> X a
withWindowSet forall a b. (a -> b) -> a -> b
$ forall (m :: * -> *) a. Monad m => a -> m a
return 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
(Bool
_,Position
_,Position
_,Window
w) <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
io forall a b. (a -> b) -> a -> b
$ Display
-> Window
-> Window
-> Position
-> Position
-> IO (Bool, Position, Position, Window)
translateCoordinates Display
dpy Window
root Window
root (forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
x) (forall a b. (Integral a, Num b) => a -> b
fromIntegral CInt
y)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Maybe Window
foc forall a. Eq a => a -> a -> Bool
/= forall a. a -> Maybe a
Just Window
w) forall a b. (a -> b) -> a -> b
$ Window -> X ()
focus Window
w
forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> All
All Bool
True)
focusOnMouseMove Event
_ = forall (m :: * -> *) a. Monad m => a -> m a
return (Bool -> All
All Bool
True)
adjustEventInput :: X ()
adjustEventInput :: X ()
adjustEventInput = forall a. (Display -> X a) -> X a
withDisplay forall a b. (a -> b) -> a -> b
$ \Display
dpy -> do
Window
rootw <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Window
theRoot
forall (m :: * -> *) a. MonadIO m => IO a -> m a
io forall a b. (a -> b) -> a -> b
$ Display -> Window -> Window -> IO ()
selectInput Display
dpy Window
rootw forall a b. (a -> b) -> a -> b
$ Window
substructureRedirectMask forall a. Bits a => a -> a -> a
.|. Window
substructureNotifyMask
forall a. Bits a => a -> a -> a
.|. Window
enterWindowMask forall a. Bits a => a -> a -> a
.|. Window
leaveWindowMask forall a. Bits a => a -> a -> a
.|. Window
structureNotifyMask
forall a. Bits a => a -> a -> a
.|. Window
buttonPressMask forall a. Bits a => a -> a -> a
.|. Window
pointerMotionMask
focusUnderPointer :: X ()
focusUnderPointer :: X ()
focusUnderPointer = X Bool -> X () -> X ()
whenX (Bool -> Bool
not forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> (forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Bool
mouseFocused forall (m :: * -> *). Monad m => m Bool -> m Bool -> m Bool
<||> forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (forall a. Maybe a -> Bool
isJust forall b c a. (b -> c) -> (a -> b) -> a -> c
. XState -> Maybe (Position -> Position -> X (), X ())
dragging))) forall a b. (a -> b) -> a -> b
$ do
Display
dpy <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Display
display
Window
root <- forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
asks XConf -> Window
theRoot
(Bool
_, Window
_, Window
w', CInt
_, CInt
_, CInt
_, CInt
_, Modifier
_) <- forall (m :: * -> *) a. MonadIO m => IO a -> m a
io forall a b. (a -> b) -> a -> b
$ Display
-> Window
-> IO (Bool, Window, Window, CInt, CInt, CInt, CInt, Modifier)
queryPointer Display
dpy Window
root
Maybe Window
w <- forall s (m :: * -> *) a. MonadState s m => (s -> a) -> m a
gets (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)
forall (f :: * -> *). Applicative f => Bool -> f () -> f ()
when (Window
w' forall a. Eq a => a -> a -> Bool
/= Window
none Bool -> Bool -> Bool
&& forall a. a -> Maybe a
Just Window
w' forall a. Eq a => a -> a -> Bool
/= Maybe Window
w) (Window -> X ()
focus Window
w')