diff options
author | xmonad <xmonad@selg.hethrael.org> | 2008-03-26 08:57:59 +0100 |
---|---|---|
committer | xmonad <xmonad@selg.hethrael.org> | 2008-03-26 08:57:59 +0100 |
commit | c7c457e933d08b0d72ca74ac3c169438f4c4de8d (patch) | |
tree | dd1981c62b36234b8dbf9a1fe25ff7845b862b77 /XMonad/Actions | |
parent | e80fdc8ebb807632f320a5917b295daadf0d06cb (diff) | |
download | XMonadContrib-c7c457e933d08b0d72ca74ac3c169438f4c4de8d.tar.gz XMonadContrib-c7c457e933d08b0d72ca74ac3c169438f4c4de8d.tar.xz XMonadContrib-c7c457e933d08b0d72ca74ac3c169438f4c4de8d.zip |
UpdatePointer: Make pointer position configurable.
darcs-hash:20080326075759-67423-391137fce18694e0151692653396c5578dbb2add.gz
Diffstat (limited to '')
-rw-r--r-- | XMonad/Actions/UpdatePointer.hs | 37 |
1 files changed, 28 insertions, 9 deletions
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 = |