Skip to content

Instantly share code, notes, and snippets.

@naota
Created February 24, 2014 05:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save naota/9182316 to your computer and use it in GitHub Desktop.
Save naota/9182316 to your computer and use it in GitHub Desktop.
import Graphics.X11.Xlib.Display (defaultRootWindow)
import Graphics.X11.Xlib.Types (Display)
import Graphics.X11.Xlib.Extras
import Graphics.X11.Xlib.Event
import Graphics.X11.Types ( Window, ButtonMask, Button, enterNotify, buttonPress, noEventMask, button1
, buttonRelease)
import Foreign ( pokeByteOff )
import Foreign.C.Types ( CInt )
import System.Posix.Unistd (usleep)
setButtonEvent :: XEventPtr -> Window -> Window -> Window ->
ButtonMask -> Button ->
CInt -> CInt -> CInt -> CInt -> Bool ->
IO ()
setButtonEvent p win root subwin state button x y xroot yroot sameScreen = do
setKeyEvent p win root subwin 0 0 sameScreen
(`pokeByteOff` 64) p (x :: CInt)
(`pokeByteOff` 68) p (y :: CInt)
(`pokeByteOff` 72) p (xroot :: CInt)
(`pokeByteOff` 76) p (yroot :: CInt)
(`pokeByteOff` 80) p state
(`pokeByteOff` 84) p button
return ()
setEnterEvent :: XEventPtr -> Window -> Window -> Window ->
Bool -> IO ()
setEnterEvent p win root subwin = setButtonEvent p win root subwin 0 3 x y xroot yroot
where
(x, y) = (1, 1)
(xroot, yroot) = (x+1, y+20)
click :: Display -> Window -> (Int, Int) -> IO ()
click display window (x',y') = do
allocaXEvent $ \e -> do
setEventType e enterNotify
setEnterEvent e window root subwin True
sendEvent display window False noEventMask e
setEventType e buttonPress
setButtonEvent e window root subwin 0x10 button1 x y xroot yroot True
sendEvent display window False noEventMask e
usleep 100000
setEventType e buttonRelease
setButtonEvent e window root subwin 0x110 button1 x y xroot yroot True
sendEvent display window False noEventMask e
sync display False
where root = defaultRootWindow display
(xroot, yroot) = (x+1, y+20)
subwin = 0
(x,y) = (fromIntegral x', fromIntegral y')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment