Import Mouse.hs from [work]
Import Mouse.hs from [work]
diff --git a/lib/Mouse.hs b/lib/Mouse.hs
new file mode 100644
index 0000000..05298f7
--- /dev/null
+++ b/lib/Mouse.hs
@@ -0,0 +1,45 @@
+{-# LANGUAGE ForeignFunctionInterface #-}
+module Mouse
+ (sendButtonPress,
+ movePointer)
+ where
+
+import Graphics.X11.Xlib
+import Graphics.X11.Xlib.Types
+import Graphics.X11.Xlib.Misc
+import Foreign
+import Foreign.C.Types
+
+import XMonad
+import XMonad.Util.XUtils (fi)
+import qualified XMonad.StackSet as W
+
+-- XTestFakeButtonEvent(display, button, is_press, delay)
+foreign import ccall unsafe "X11/extensions/XTest.h XTestFakeButtonEvent"
+ xFakeButtonEvent :: Display -> Button -> Bool -> Time -> IO Status
+
+foreign import ccall unsafe "X11/extensions/XTest.h XTestFakeMotionEvent"
+ xFakeMotionEvent :: Display -> CInt -> CInt -> CInt -> Time -> IO Status
+
+fakeMotion :: CInt -> CInt -> X ()
+fakeMotion x y = do
+ sid <- withWindowSet (return . W.screen . W.current)
+ withDisplay $ \dpy -> do
+ io $ xFakeMotionEvent dpy (fromIntegral sid) x y 0
+ return ()
+
+sendButtonPress :: Button -> X ()
+sendButtonPress button = do
+ root <- asks theRoot
+ withDisplay $ \dpy -> do
+ io $ xFakeButtonEvent dpy button True 0
+ io $ xFakeButtonEvent dpy button False 0
+ return ()
+
+movePointer :: Int -> Int -> X ()
+movePointer dx dy = do
+ root <- asks theRoot
+ withDisplay $ \dpy -> do
+ (_,_,_,x,y,_,_,_) <- io $ queryPointer dpy root
+ io $ warpPointer dpy root none 0 0 0 0 (fi $ x + fi dx) (fi $ y + fi dy)
+ return ()