Permalink
Browse files

- Add absolute mouse position support to xdo and vnc targets.

  • Loading branch information...
1 parent 9049b69 commit 362362730671f052738f4d7bc4372ae2075da4d9 @jordansissel committed Jan 2, 2011
Showing with 70 additions and 2 deletions.
  1. +2 −0 lib/fingerpoken/target.rb
  2. +16 −2 lib/fingerpoken/vnc.rb
  3. +44 −0 lib/fingerpoken/xdo.rb
  4. +8 −0 public/js/fingerpoken.js
View
2 lib/fingerpoken/target.rb
@@ -15,6 +15,8 @@ def register
response = case request["action"]
when "mousemove_relative"
mousemove_relative(request["rel_x"], request["rel_y"])
+ when "mousemove_absolute"
+ mousemove_absolute(request["percent_x"], request["percent_y"])
when "move_end"
move_end()
when "click"
View
18 lib/fingerpoken/vnc.rb
@@ -5,6 +5,8 @@
class FingerPoken::Target::VNC < FingerPoken::Target
attr_accessor :x
attr_accessor :y
+ attr_accessor :screen_x
+ attr_accessor :screen_y
attr_accessor :buttonmask
def initialize(config)
@@ -48,6 +50,16 @@ def mousemove_relative(x, y)
return nil
end
+ def mousemove_absolute(px, py)
+ # Edges may be hard to hit on some devices, so inflate things a bit.
+ xbuf = @screen_x * 0.1
+ ybuf = @screen_y * 0.1
+ @x = (((@screen_x + xbuf) * px) - (xbuf / 2)).to_i
+ @y = (((@screen_y + ybuf) * py) - (ybuf / 2)).to_i
+ update
+ return nil
+ end
+
def mousedown(button)
button = (1 << (button.to_i - 1))
return if @buttonmask & button != 0
@@ -72,10 +84,12 @@ def initialize(target)
end
def ready
- @target.register
+ @target.screen_x = @screen_width
+ @target.screen_y = @screen_height
+ @target.buttonmask = 0
@target.x = (@screen_width / 2).to_i
@target.y = (@screen_height / 2).to_i
- @target.buttonmask = 0
+ @target.register
end
end # class VNCClient
end
View
44 lib/fingerpoken/xdo.rb
@@ -17,20 +17,64 @@ module LibXdo
attach_function :xdo_mouseup, [:pointer, :long, :int], :int
attach_function :xdo_type, [:pointer, :long, :string, :long], :int
attach_function :xdo_keysequence, [:pointer, :long, :string, :long], :int
+ attach_function :xdo_get_window_size, [:pointer, :long, :pointer, :pointer], :int
+ attach_function :xdo_window_search, [:pointer, :pointer, :pointer, :pointer], :int
end
+ class XdoSearch < FFI::Struct
+ layout :title, :pointer,
+ :winclass, :pointer,
+ :winclassname, :pointer,
+ :winname, :pointer,
+ :pid, :int,
+ :max_depth, :long,
+ :only_visible, :int,
+ :screen, :int,
+ :require, :int,
+ :searchmask, :uint,
+ :desktop, :long
+ end # class XdoSearch
+
def initialize(config)
super(config)
@xdo = LibXdo::xdo_new(nil)
if @xdo.null?
raise "xdo_new failed"
end
+
+ search = XdoSearch.new
+ search[:searchmask] = 1 << 2 # SEARCH_NAME, from xdo.h
+ search[:max_depth] = 0
+ search[:winname] = FFI::MemoryPointer.new(:char, 3)
+ search[:winname].put_string(0, ".*")
+ ptr_nwindows = FFI::MemoryPointer.new(:ulong, 1)
+ ptr_winlist = FFI::MemoryPointer.new(:pointer, 1)
+ LibXdo::xdo_window_search(@xdo, search, ptr_winlist, ptr_nwindows)
+ nwindows = ptr_nwindows.read_long
+ @rootwin = ptr_winlist.read_pointer.read_array_of_long(nwindows)[0]
+
+ ptr_x = FFI::MemoryPointer.new(:int, 1)
+ ptr_y = FFI::MemoryPointer.new(:int, 1)
+
+ LibXdo::xdo_get_window_size(@xdo, @rootwin, ptr_x, ptr_y)
+ @screen_x = ptr_x.read_int
+ @screen_y = ptr_y.read_int
end
def mousemove_relative(x, y)
return LibXdo::xdo_mousemove_relative(@xdo, x, y)
end
+ def mousemove_absolute(px, py)
+ # Edges may be hard to hit on some devices, so inflate things a bit.
+ xbuf = @screen_x * 0.1
+ ybuf = @screen_y * 0.1
+ x = (((@screen_x + xbuf) * px) - (xbuf / 2)).to_i
+ y = (((@screen_y + ybuf) * py) - (ybuf / 2)).to_i
+
+ return LibXdo::xdo_mousemove(@xdo, x, y, 0)
+ end
+
def click(button)
return LibXdo::xdo_click(@xdo, 0, button.to_i)
end
View
8 public/js/fingerpoken.js
@@ -381,6 +381,14 @@
rel_x: delta_x,
rel_y: delta_y
}));
+ } else if (movement == "absolute") {
+ /* Send absolute in terms of percentages. */
+ var content = $(".content:visible");
+ state.websocket.send(JSON.stringify({
+ action: "mousemove_absolute",
+ percent_x: x / content.innerWidth(),
+ percent_y: y / content.innerHeight(),
+ }));
} else if (movement == "vector") {
if (!state.mouse.vectorTimer) {
state.mouse.vectorTimer = setInterval(function() {

0 comments on commit 3623627

Please sign in to comment.