From 957ec50d64d6ce1fbd19bbaa9eb3ae6c60c33d58 Mon Sep 17 00:00:00 2001 From: Ilya Portnov Date: Sat, 14 May 2011 21:21:28 +0600 Subject: [PATCH] Import Mouse.hs from [work] --- lib/Mouse.hs | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 45 insertions(+), 0 deletions(-) create mode 100644 lib/Mouse.hs 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 () -- 1.7.2.3