aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrobreim <robreim@bobturf.org>2008-03-01 14:44:01 +0100
committerrobreim <robreim@bobturf.org>2008-03-01 14:44:01 +0100
commitf9360be31df67e95e8d04acb71b01124028c42f5 (patch)
tree3c045a202bea35ad43cc3f59769c4f3ec6945a5b
parentb464dc0b07191b9b04692923d234e8fca79e6935 (diff)
downloadXMonadContrib-f9360be31df67e95e8d04acb71b01124028c42f5.tar.gz
XMonadContrib-f9360be31df67e95e8d04acb71b01124028c42f5.tar.xz
XMonadContrib-f9360be31df67e95e8d04acb71b01124028c42f5.zip
UpdatePointer XMonadContrib module
darcs-hash:20080301134401-d4c7e-6d984009ecc7fb9f3e3d96b829a928bbf56503af.gz
-rw-r--r--XMonad/Actions/UpdatePointer.hs54
-rw-r--r--xmonad-contrib.cabal1
2 files changed, 55 insertions, 0 deletions
diff --git a/XMonad/Actions/UpdatePointer.hs b/XMonad/Actions/UpdatePointer.hs
new file mode 100644
index 0000000..292bfdc
--- /dev/null
+++ b/XMonad/Actions/UpdatePointer.hs
@@ -0,0 +1,54 @@
+-----------------------------------------------------------------------------
+-- |
+-- Module : XMonadContrib.UpdatePointer
+-- Copyright : (c) Robert Marlow <robreim@bobturf.org>
+-- License : BSD3-style (see LICENSE)
+--
+-- Maintainer : Robert Marlow <robreim@bobturf.org>
+-- Stability : stable
+-- Portability : portable
+--
+-- Causes the pointer to follow whichever window focus changes to. Compliments
+-- the idea of switching focus as the mouse crosses window boundaries to
+-- keep the mouse near the currently focussed window
+--
+-----------------------------------------------------------------------------
+
+module XMonad.Actions.UpdatePointer
+ (
+ -- * Usage
+ -- $usage
+ updatePointer
+ )
+ where
+
+import XMonad
+import Control.Monad
+
+-- $usage
+-- You can use this module with the following in your @~\/.xmonad\/xmonad.hs@:
+--
+-- > import XMonad
+-- > import XMonad.Hooks.DynamicLog
+--
+-- Enable it by including it in your logHook definition. Eg:
+--
+-- > logHook = updatePointer (1%2) (1%2)
+--
+-- which will move the pointer to the middle of a newly focused window if the
+-- focus moves away from the pointer
+
+
+-- | Update the pointer's location to the currently focused window unless it's
+-- already there
+updatePointer :: Rational -> Rational -> X ()
+updatePointer h v = withFocused $ \w -> do
+ dpy <- asks display
+ root <- asks theRoot
+ wa <- io $ getWindowAttributes dpy w
+ (sameRoot,_,w',_,_,_,_,_) <- io $ queryPointer dpy root
+ unless (sameRoot && w == w') $
+ 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)
+
diff --git a/xmonad-contrib.cabal b/xmonad-contrib.cabal
index 657c5cb..336b4d3 100644
--- a/xmonad-contrib.cabal
+++ b/xmonad-contrib.cabal
@@ -82,6 +82,7 @@ library
XMonad.Actions.Submap
XMonad.Actions.SwapWorkspaces
XMonad.Actions.TagWindows
+ XMonad.Actions.UpdatePointer
XMonad.Actions.Warp
XMonad.Actions.WindowGo
XMonad.Actions.WindowBringer