mirror of
https://github.com/xmonad/xmonad-contrib.git
synced 2025-05-19 11:30:22 -07:00
UpdatePointer: Make pointer position configurable.
This commit is contained in:
parent
b85ce7522f
commit
1c6798a639
@ -19,6 +19,7 @@ module XMonad.Actions.UpdatePointer
|
||||
-- * Usage
|
||||
-- $usage
|
||||
updatePointer
|
||||
, PointerPosition (..)
|
||||
)
|
||||
where
|
||||
|
||||
@ -33,24 +34,42 @@ import Control.Monad
|
||||
--
|
||||
-- Enable it by including it in your logHook definition. Eg:
|
||||
--
|
||||
-- > logHook = updatePointer
|
||||
-- > logHook = updatePointer Nearest
|
||||
--
|
||||
-- which will move the pointer to the nearest point of a newly focused window
|
||||
-- which will move the pointer to the nearest point of a newly focused window, or
|
||||
--
|
||||
-- > logHook = updatePointer (Relative 0.5 0.5)
|
||||
--
|
||||
-- which will move the pointer to the center of a newly focused window.
|
||||
--
|
||||
-- To use this with an existing logHook, use >> :
|
||||
--
|
||||
-- > logHook = dynamicLog
|
||||
-- > >> updatePointer (RelativePosition 1 1)
|
||||
--
|
||||
-- which moves the pointer to the bottom-right corner of the focused window.
|
||||
|
||||
data PointerPosition = Nearest | Relative Rational Rational
|
||||
|
||||
-- | Update the pointer's location to the nearest point of the currently focused
|
||||
-- | Update the pointer's location to the currently focused
|
||||
-- window unless it's already there
|
||||
updatePointer :: X ()
|
||||
updatePointer = withFocused $ \w -> do
|
||||
updatePointer :: PointerPosition -> X ()
|
||||
updatePointer p = withFocused $ \w -> do
|
||||
dpy <- asks display
|
||||
root <- asks theRoot
|
||||
wa <- io $ getWindowAttributes dpy w
|
||||
(_sameRoot,_,w',rootx,rooty,_,_,_) <- io $ queryPointer dpy root
|
||||
-- Can sameRoot ever be false in this case? I'm going to assume not
|
||||
unless (w == w') $ do
|
||||
let x = moveWithin rootx (wa_x wa) ((wa_x wa) + (wa_width wa))
|
||||
let y = moveWithin rooty (wa_y wa) ((wa_y wa) + (wa_height wa))
|
||||
io $ warpPointer dpy none root 0 0 0 0 (fromIntegral x) (fromIntegral y)
|
||||
unless (w == w') $
|
||||
case p of
|
||||
Nearest -> do
|
||||
let x = moveWithin rootx (wa_x wa) ((wa_x wa) + (wa_width wa))
|
||||
let y = moveWithin rooty (wa_y wa) ((wa_y wa) + (wa_height wa))
|
||||
io $ warpPointer dpy none root 0 0 0 0 (fromIntegral x) (fromIntegral y)
|
||||
Relative h v ->
|
||||
io $ warpPointer dpy none w 0 0 0 0
|
||||
(fraction h (wa_width wa)) (fraction v (wa_height wa))
|
||||
where fraction x y = floor (x * fromIntegral y)
|
||||
|
||||
moveWithin :: Integral a => a -> a -> a -> a
|
||||
moveWithin current lower upper =
|
||||
|
Loading…
x
Reference in New Issue
Block a user