christopheraue / ruby-xlib-objects

X11 bindings for ruby
MIT License
6 stars 2 forks source link

Pointer Functionality #2

Closed johnlane closed 7 years ago

johnlane commented 7 years ago

I was trying to query and reposition the pointer but I could not find any implementation in the xlib-objects gem. Did I miss it?

What I want to do, I achieved using xlib but I'd prefer to use the cleaner object layer if support exists:

class IntPtr < FFI::Struct
    layout  :value, :int
end
display = XlibObj::Display.new(':0')
root_window = Xlib.XRootWindow(display.to_native,0)
Xlib.XQueryPointer(display.to_native,
                   root_window,
                   IntPtr.new,
                   IntPtr.new,
                   mx = IntPtr.new,
                   my = IntPtr.new,
                   IntPtr.new,
                   IntPtr.new,
                   IntPtr.new)
Xlib.XWarpPointer(display.to_native,
                  Xlib::None,
                  root_window,
                  0, 0,
                  0, 0,
                  x, 10)
display.flush

Also, I want to submit a mouse click. I want to implement this Python code in Ruby:

from Xlib.ext.xtest import fake_input
fake_input(display,X.ButtonPress,1, X.CurrentTime, X.NONE, x, 10)

which uses the XTest extension. I don't think you have support for that but I thought I'd ask. I am working around the problem by using xdotool but I'd prefer to do it directly.

%x(xdotool click 1)

I've spent a few hours today (well, all day really!), first trying to write native Xlib code and then looking for libraries and trying to fix up a FFI binding to libxtst and libxdo. However, it's messy and I've fallen back to the above one-liner for the time being.

christopheraue commented 7 years ago

An interface for pointers does not exist. XTest is also not implemented.