fingerpoken 0.2.20101217123250 → 0.2.20101227000817
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/bin/fingerpoken.rb +16 -9
- data/lib/fingerpoken/target.rb +5 -2
- data/lib/fingerpoken/tivo.rb +9 -1
- data/lib/fingerpoken/vnc.rb +17 -6
- data/lib/fingerpoken/xdo.rb +5 -7
- metadata +4 -4
data/bin/fingerpoken.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
+
$:.unshift "#{File.dirname(__FILE__)}/../lib"
|
3
4
|
require "rubygems"
|
4
5
|
require "em-websocket"
|
5
6
|
require "json"
|
@@ -36,19 +37,25 @@ def main(args)
|
|
36
37
|
case target.scheme
|
37
38
|
when "xdo"
|
38
39
|
require "fingerpoken/#{target.scheme}"
|
39
|
-
targets << [:Xdo, {}]
|
40
|
+
targets << [:Xdo, { }]
|
40
41
|
when "vnc"
|
41
42
|
require "fingerpoken/#{target.scheme}"
|
42
|
-
targets << [:VNC, {
|
43
|
+
targets << [:VNC, {
|
44
|
+
:host => target.host, :user => target.user,
|
45
|
+
:password => target.password, :recenter => (target.query == "recenter")
|
46
|
+
}]
|
43
47
|
when "tivo"
|
44
48
|
require "fingerpoken/#{target.scheme}"
|
45
|
-
targets << [:Tivo, { :host =>
|
49
|
+
targets << [:Tivo, { :host => target.host }]
|
46
50
|
end
|
47
51
|
end
|
48
52
|
end
|
49
53
|
opts.parse(args)
|
50
54
|
|
51
|
-
|
55
|
+
if targets.size == 0
|
56
|
+
$stderr.puts "No targets given. You should specify one with -t."
|
57
|
+
return 1
|
58
|
+
end
|
52
59
|
|
53
60
|
EventMachine::run do
|
54
61
|
$:.unshift(File.dirname(__FILE__) + "/lib")
|
@@ -56,13 +63,13 @@ def main(args)
|
|
56
63
|
|
57
64
|
targets.each do |klass, args|
|
58
65
|
args.merge!({ :channel => channel })
|
59
|
-
|
60
|
-
|
66
|
+
target = FingerPoken::Target.const_get(klass).new(args)
|
67
|
+
target.register
|
68
|
+
end # targets.each
|
61
69
|
|
62
70
|
EventMachine::WebSocket.start(:host => "0.0.0.0", :port => 5001) do |ws|
|
63
71
|
ws.onmessage do |message|
|
64
72
|
request = JSON.parse(message)
|
65
|
-
puts "Request: #{request.inspect}"
|
66
73
|
channel.push(
|
67
74
|
:request => request,
|
68
75
|
:callback => proc { |message| ws.send(JSON.dump(message)) }
|
@@ -72,8 +79,8 @@ def main(args)
|
|
72
79
|
|
73
80
|
Rack::Handler::Thin.run(
|
74
81
|
Rack::CommonLogger.new( \
|
75
|
-
|
76
|
-
|
82
|
+
Rack::ShowExceptions.new( \
|
83
|
+
FingerPoken.new)), :Port => 5000)
|
77
84
|
end # EventMachine::run
|
78
85
|
end
|
79
86
|
|
data/lib/fingerpoken/target.rb
CHANGED
@@ -4,12 +4,14 @@ class FingerPoken::Target
|
|
4
4
|
def initialize(config)
|
5
5
|
@channel = config[:channel]
|
6
6
|
@logger = Logger.new(STDERR)
|
7
|
+
@logger.level = ($DEBUG ? Logger::DEBUG: Logger::WARN)
|
7
8
|
end
|
8
9
|
|
9
10
|
def register
|
10
11
|
@channel.subscribe do |obj|
|
11
12
|
request = obj[:request]
|
12
13
|
callback = obj[:callback]
|
14
|
+
@logger.debug(request)
|
13
15
|
response = case request["action"]
|
14
16
|
when "mousemove_relative"
|
15
17
|
mousemove_relative(request["rel_x"], request["rel_y"])
|
@@ -29,8 +31,9 @@ class FingerPoken::Target
|
|
29
31
|
p ["Unsupported action", request]
|
30
32
|
end
|
31
33
|
|
32
|
-
|
33
|
-
|
34
|
+
if response.is_a?(Hash)
|
35
|
+
callback.call(response)
|
36
|
+
end
|
34
37
|
end
|
35
38
|
end
|
36
39
|
|
data/lib/fingerpoken/tivo.rb
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
3
|
# TODO(sissel): Refactor the protocol into an EM::Tivo module.
|
4
|
+
# Commands
|
5
|
+
#
|
6
|
+
# IRCODE ...
|
7
|
+
# INFO
|
8
|
+
# WINDOW - aspect ratio
|
4
9
|
|
5
10
|
require "rubygems"
|
6
11
|
require "fingerpoken/target"
|
@@ -11,7 +16,8 @@ class FingerPoken::Target::Tivo < FingerPoken::Target
|
|
11
16
|
super(config)
|
12
17
|
# TODO(sissel): Make this a config
|
13
18
|
@host = config[:host]
|
14
|
-
@
|
19
|
+
@port = (config[:port] or 31339)
|
20
|
+
@tivo = EventMachine::connect(@host, @port, TivoClient, self)
|
15
21
|
|
16
22
|
@state = OpenStruct.new # TODO(sissel): Make this not an open struct...
|
17
23
|
|
@@ -52,6 +58,7 @@ class FingerPoken::Target::Tivo < FingerPoken::Target
|
|
52
58
|
|
53
59
|
def move_end
|
54
60
|
@tivo.send_data("IRCODE PLAY\r\n")
|
61
|
+
@state.speed = 0
|
55
62
|
return { "action" => "status", "status" => "\\u25b6" }
|
56
63
|
end
|
57
64
|
|
@@ -82,6 +89,7 @@ class FingerPoken::Target::Tivo < FingerPoken::Target
|
|
82
89
|
when "Return"
|
83
90
|
@tivo.send_data("IRCODE SELECT\r\n")
|
84
91
|
end
|
92
|
+
return nil
|
85
93
|
end
|
86
94
|
|
87
95
|
class TivoClient < EventMachine::Connection
|
data/lib/fingerpoken/vnc.rb
CHANGED
@@ -9,10 +9,19 @@ class FingerPoken::Target::VNC < FingerPoken::Target
|
|
9
9
|
|
10
10
|
def initialize(config)
|
11
11
|
super(config)
|
12
|
-
# TODO(sissel):
|
13
|
-
@
|
14
|
-
@
|
15
|
-
@
|
12
|
+
# TODO(sissel): eventmachine-vnc needs to suppore more auth mechanisms
|
13
|
+
@user = config[:user]
|
14
|
+
@password = (config[:password] or config[:user])
|
15
|
+
@host = config[:host]
|
16
|
+
@port = (config[:port] or 5900)
|
17
|
+
@recenter = config[:recenter]
|
18
|
+
|
19
|
+
# For eventmachine-vnc
|
20
|
+
ENV["VNCPASS"] = @password
|
21
|
+
|
22
|
+
if @host == nil
|
23
|
+
raise "#{self.class.name}: No host given to connect to"
|
24
|
+
end
|
16
25
|
|
17
26
|
@vnc = EventMachine::connect(@host, @port, VNCClient, self)
|
18
27
|
@x = 0
|
@@ -21,13 +30,12 @@ class FingerPoken::Target::VNC < FingerPoken::Target
|
|
21
30
|
end
|
22
31
|
|
23
32
|
def update
|
24
|
-
p [@x, @y, @buttonmask]
|
25
33
|
@vnc.pointerevent(@x, @y, @buttonmask)
|
26
34
|
|
27
35
|
# TODO(sissel): Hack to make it work in TF2.
|
28
36
|
# Mouse movement is always "from center"
|
29
37
|
# So after each move, center the cursor.
|
30
|
-
if
|
38
|
+
if @recenter
|
31
39
|
@x = (@vnc.screen_width / 2).to_i
|
32
40
|
@y = (@vnc.screen_height / 2).to_i
|
33
41
|
end
|
@@ -37,6 +45,7 @@ class FingerPoken::Target::VNC < FingerPoken::Target
|
|
37
45
|
@x += x
|
38
46
|
@y += y
|
39
47
|
update
|
48
|
+
return nil
|
40
49
|
end
|
41
50
|
|
42
51
|
def mousedown(button)
|
@@ -44,6 +53,7 @@ class FingerPoken::Target::VNC < FingerPoken::Target
|
|
44
53
|
return if @buttonmask & button != 0
|
45
54
|
@buttonmask |= button
|
46
55
|
update
|
56
|
+
return nil
|
47
57
|
end
|
48
58
|
|
49
59
|
def mouseup(button)
|
@@ -51,6 +61,7 @@ class FingerPoken::Target::VNC < FingerPoken::Target
|
|
51
61
|
return if @buttonmask & button == 0
|
52
62
|
@buttonmask &= (~button)
|
53
63
|
update
|
64
|
+
return nil
|
54
65
|
end
|
55
66
|
|
56
67
|
class VNCClient < EventMachine::Connection
|
data/lib/fingerpoken/xdo.rb
CHANGED
@@ -25,32 +25,29 @@ class FingerPoken::Target::Xdo < FingerPoken::Target
|
|
25
25
|
if @xdo.null?
|
26
26
|
raise "xdo_new failed"
|
27
27
|
end
|
28
|
-
register
|
29
28
|
end
|
30
29
|
|
31
30
|
def mousemove_relative(x, y)
|
32
|
-
@logger.info("move #{x},#{y}")
|
33
31
|
return LibXdo::xdo_mousemove_relative(@xdo, x, y)
|
34
32
|
end
|
35
33
|
|
36
34
|
def click(button)
|
37
|
-
LibXdo::xdo_click(@xdo, 0, button.to_i)
|
35
|
+
return LibXdo::xdo_click(@xdo, 0, button.to_i)
|
38
36
|
end
|
39
37
|
|
40
38
|
def mousedown(button)
|
41
|
-
LibXdo::xdo_mousedown(@xdo, 0, button.to_i)
|
39
|
+
return LibXdo::xdo_mousedown(@xdo, 0, button.to_i)
|
42
40
|
end
|
43
41
|
|
44
42
|
def mouseup(button)
|
45
|
-
LibXdo::xdo_mouseup(@xdo, 0, button.to_i)
|
43
|
+
return LibXdo::xdo_mouseup(@xdo, 0, button.to_i)
|
46
44
|
end
|
47
45
|
|
48
46
|
def type(string)
|
49
|
-
LibXdo::xdo_type(@xdo, 0, string, 12000)
|
47
|
+
return LibXdo::xdo_type(@xdo, 0, string, 12000)
|
50
48
|
end
|
51
49
|
|
52
50
|
def keypress(key)
|
53
|
-
p "Pressing: #{key}"
|
54
51
|
if key.is_a?(String)
|
55
52
|
if key.length == 1
|
56
53
|
# Assume letter
|
@@ -74,5 +71,6 @@ class FingerPoken::Target::Xdo < FingerPoken::Target
|
|
74
71
|
end # case key
|
75
72
|
end # if 32.upto(127).include?(key)
|
76
73
|
end # if key.is_a?String
|
74
|
+
return nil
|
77
75
|
end # def keypress
|
78
76
|
end # class FingerPoken::Target::Xdo
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fingerpoken
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 40202454001653
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 20101227000817
|
10
|
+
version: 0.2.20101227000817
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jordan Sissel
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-12-
|
18
|
+
date: 2010-12-27 00:00:00 -08:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|