From c7c457e933d08b0d72ca74ac3c169438f4c4de8d Mon Sep 17 00:00:00 2001 From: xmonad Date: Wed, 26 Mar 2008 08:57:59 +0100 Subject: UpdatePointer: Make pointer position configurable. darcs-hash:20080326075759-67423-391137fce18694e0151692653396c5578dbb2add.gz --- XMonad/Actions/UpdatePointer.hs | 37 ++++++++++++++++++++++++++++--------- 1 file changed, 28 insertions(+), 9 deletions(-) (limited to 'XMonad/Actions/UpdatePointer.hs') diff --git a/XMonad/Actions/UpdatePointer.hs b/XMonad/Actions/UpdatePointer.hs index 20f2f30..4a67112 100644 --- a/XMonad/Actions/UpdatePointer.hs +++ b/XMonad/Actions/UpdatePointer.hs @@ -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 = -- cgit v1.2.3