UpdatePointer: Make pointer position configurable.

This commit is contained in:
xmonad 2008-03-26 07:57:59 +00:00
parent b85ce7522f
commit 1c6798a639

View File

@ -19,6 +19,7 @@ module XMonad.Actions.UpdatePointer
-- * Usage -- * Usage
-- $usage -- $usage
updatePointer updatePointer
, PointerPosition (..)
) )
where where
@ -33,24 +34,42 @@ import Control.Monad
-- --
-- Enable it by including it in your logHook definition. Eg: -- 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 -- window unless it's already there
updatePointer :: X () updatePointer :: PointerPosition -> X ()
updatePointer = withFocused $ \w -> do updatePointer p = withFocused $ \w -> do
dpy <- asks display dpy <- asks display
root <- asks theRoot root <- asks theRoot
wa <- io $ getWindowAttributes dpy w wa <- io $ getWindowAttributes dpy w
(_sameRoot,_,w',rootx,rooty,_,_,_) <- io $ queryPointer dpy root (_sameRoot,_,w',rootx,rooty,_,_,_) <- io $ queryPointer dpy root
-- Can sameRoot ever be false in this case? I'm going to assume not -- Can sameRoot ever be false in this case? I'm going to assume not
unless (w == w') $ do unless (w == w') $
let x = moveWithin rootx (wa_x wa) ((wa_x wa) + (wa_width wa)) case p of
let y = moveWithin rooty (wa_y wa) ((wa_y wa) + (wa_height wa)) Nearest -> do
io $ warpPointer dpy none root 0 0 0 0 (fromIntegral x) (fromIntegral y) 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 :: Integral a => a -> a -> a -> a
moveWithin current lower upper = moveWithin current lower upper =