Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Cannot retrieve contributors at this time

file 34 lines (29 sloc) 0.979 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
#include <X11/X.h>
#include <X11/extensions/XTest.h>
#include <ruby.h>

VALUE wrapFakeButtonEvent(VALUE rbSelf, VALUE rbButton, VALUE rbPress,
                          VALUE rbDelay)
{
  Display *display = XOpenDisplay(NULL);
  XTestFakeButtonEvent(display, NUM2INT(rbButton),
                       rbPress != Qfalse ? True : False, NUM2INT(rbDelay));
  XCloseDisplay(display);
  return rbSelf;
}

VALUE wrapFakeMotionEvent(VALUE rbSelf, VALUE rbX, VALUE rbY, VALUE rbDelay)
{
  Display *display = XOpenDisplay(NULL);
  XTestFakeMotionEvent(display, DefaultScreen(display),
                       NUM2INT(rbX), NUM2INT(rbY), NUM2INT(rbDelay));
  XCloseDisplay(display);
  return rbSelf;
}

extern "C" {

  void Init_x11test(void)
  {
    rb_define_method(rb_cObject, "fake_button_event",
                     RUBY_METHOD_FUNC(wrapFakeButtonEvent), 3);
    rb_define_method(rb_cObject, "fake_motion_event",
                     RUBY_METHOD_FUNC(wrapFakeMotionEvent), 3);
  }

}
Something went wrong with that request. Please try again.