x_do_bindings 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ec538d7ebcacf6d9be941502f5a7d91f33e80b5a
4
+ data.tar.gz: 5b48ca12807f297cdd2dd7ff72511c5537b1cc2e
5
+ SHA512:
6
+ metadata.gz: 8f31007fe362ba2d047eebd4b7e7d0bc1b4ffd8302a1e1e9435b0b93c0aff8f628d0c868b34b3dd5beddc8fe89b0e52ab961c2811af74750e13ed2a93ae858ee
7
+ data.tar.gz: f94e70a5d3e624cfcb3cc07124c440ecfdddfaa8b67a4976158b541725bef5ee9e44df70623985d9ab0697dce8c2e98bcaaf94da0a19ee8083189dbccf6e3871
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.project ADDED
@@ -0,0 +1,17 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <projectDescription>
3
+ <name>x_do</name>
4
+ <comment></comment>
5
+ <projects>
6
+ </projects>
7
+ <buildSpec>
8
+ <buildCommand>
9
+ <name>com.aptana.ide.core.unifiedBuilder</name>
10
+ <arguments>
11
+ </arguments>
12
+ </buildCommand>
13
+ </buildSpec>
14
+ <natures>
15
+ <nature>com.aptana.ruby.core.rubynature</nature>
16
+ </natures>
17
+ </projectDescription>
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'ffi'
4
+
5
+ group :development do
6
+ gem 'rdoc'
7
+ gem 'rspec'
8
+ gem 'bundler'
9
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.2.5)
5
+ ffi (1.9.8)
6
+ rdoc (4.2.0)
7
+ rspec (3.2.0)
8
+ rspec-core (~> 3.2.0)
9
+ rspec-expectations (~> 3.2.0)
10
+ rspec-mocks (~> 3.2.0)
11
+ rspec-core (3.2.3)
12
+ rspec-support (~> 3.2.0)
13
+ rspec-expectations (3.2.1)
14
+ diff-lcs (>= 1.2.0, < 2.0)
15
+ rspec-support (~> 3.2.0)
16
+ rspec-mocks (3.2.1)
17
+ diff-lcs (>= 1.2.0, < 2.0)
18
+ rspec-support (~> 3.2.0)
19
+ rspec-support (3.2.2)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler
26
+ ffi
27
+ rdoc
28
+ rspec
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Victor Costan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,31 @@
1
+ = x_do
2
+
3
+ FFI ruby bindings for libxdo, which injects keystrokes and mouse events into X event queues.
4
+
5
+ == Installation
6
+
7
+ The gem requires libxdo on your machine to compile. On an Ubuntu system, you can get it by installing the libxdo-dev package.
8
+
9
+ == Documentation
10
+
11
+ Up-to-date RDocs are available at http://rdoc.info/github/pwnall/x_do/frames
12
+
13
+ == Testing
14
+
15
+ Tests require that xdotool is installed and on your path. On an Ubuntu system, you can get it by installing the xdotool package.
16
+
17
+ The terminal running the tests should remain focused while the suite runs, otherwise some tests will fail. The window should also not be maximized.
18
+
19
+ == Contributing to x_do
20
+
21
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
22
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
23
+ * Fork the project
24
+ * Start a feature/bugfix branch
25
+ * Commit and push until you are happy with your contribution
26
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
27
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
28
+
29
+ == Copyright
30
+
31
+ Copyright (c) 2011 Victor Costan. See LICENSE.txt for further details.
data/Rakefile ADDED
@@ -0,0 +1,37 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+ begin
4
+ Bundler.setup(:default, :development)
5
+ rescue Bundler::BundlerError => e
6
+ $stderr.puts e.message
7
+ $stderr.puts 'Run `bundle install` to install missing gems'
8
+ exit e.status_code
9
+ end
10
+ require 'rake'
11
+
12
+ require 'rspec/core'
13
+ require 'rspec/core/rake_task'
14
+ RSpec::Core::RakeTask.new(:spec) do |spec|
15
+ spec.pattern = FileList['spec/**/*_spec.rb']
16
+ end
17
+
18
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
19
+ spec.pattern = 'spec/**/*_spec.rb'
20
+ spec.rcov = true
21
+ end
22
+
23
+ task :default => :spec
24
+
25
+ require 'rdoc/task'
26
+ Rake::RDocTask.new do |rdoc|
27
+ version = File.exist?('VERSION') ? File.read('VERSION') : ''
28
+
29
+ rdoc.rdoc_dir = 'rdoc'
30
+ rdoc.title = "x_do #{version}"
31
+ rdoc.rdoc_files.include('README*')
32
+ rdoc.rdoc_files.include('lib/**/*.rb')
33
+ end
34
+
35
+ load 'tasks/ffi_codegen.rb'
36
+ task :package => :ffi_header
37
+ task :spec => :ffi_header
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
data/lib/x_do.rb ADDED
@@ -0,0 +1,13 @@
1
+ # :nodoc: documented in x_do/context.rb
2
+ class XDo
3
+ end # namespace XDo
4
+
5
+ require 'x_do/context.rb'
6
+ require 'x_do/mouse.rb'
7
+ require 'x_do/keyboard.rb'
8
+ require 'x_do/window.rb'
9
+
10
+ require 'x_do/ffi_lib.rb'
11
+ require 'x_do/ffi_autogen.rb'
12
+ require 'x_do/ffi_functions.rb'
13
+ require 'x_do/ffi_lib_ext.rb'
@@ -0,0 +1,102 @@
1
+ # Context for automation actions.
2
+ class XDo
3
+ # Creates a context for an X display.
4
+ #
5
+ # Args:
6
+ # display_name:: an X display name, such as ":0"; if not given, libxdo will
7
+ # choose a default display (usually the one pointed by the
8
+ # DISPLAY variable)
9
+ def initialize(display_name = nil)
10
+ @_pointer = XDo::FFILib.xdo_new display_name
11
+ @_context = XDo::FFILib::XDoContext.new @_pointer
12
+ @keyboard = XDo::Keyboard.new self
13
+ @mouse = XDo::Mouse.new self
14
+ end
15
+
16
+ # Releases resources associated with this context.
17
+ def close
18
+ return unless @_context
19
+ XDo::FFILib.xdo_free @_pointer
20
+ @_pointer = nil
21
+ @_context = nil
22
+ end
23
+
24
+ # :nodoc: automatically close contexts as they go out of scope.
25
+ def finalize
26
+ close
27
+ end
28
+
29
+ # The display name for the current context.
30
+ def display_name
31
+ @_context[:display_name]
32
+ end
33
+
34
+ # The underlying libxdo context structure.
35
+ attr_accessor :_context
36
+ # Pointer to the underlying _libxdo context structure.
37
+ attr_accessor :_pointer
38
+
39
+ # The keyboard state for this context.
40
+ attr_accessor :keyboard
41
+
42
+ # The mouse state for this context.
43
+ attr_accessor :mouse
44
+
45
+ # Returns X windows matching a query.
46
+ #
47
+ # Args:
48
+ # options:: hash that accepts the following keys:
49
+ # :title:: grep pattern that the window title has to match
50
+ # :name:: grep pattern that the window name has to match
51
+ # :class:: grep pattern that the window class has to match
52
+ # :class_name:: grep pattern that the window class (name?) has to match
53
+ # :pid:: only return windows whose process ID equals this
54
+ # :screen:: only return windows in this screen number
55
+ # :desktop:: only return windows with this desktop number
56
+ # :visible:: if true, only visible windows will be returned
57
+ #
58
+ # Returns an array of Window instances that match the query.
59
+ def find_windows(options = {})
60
+ query = XDo::FFILib::XDoSearch.from_options options
61
+ windows_pointer = FFI::MemoryPointer.new :pointer, 1
62
+ count_pointer = FFI::MemoryPointer.new :ulong, 1
63
+ XDo::FFILib.xdo_search_windows @_pointer, query, windows_pointer,
64
+ count_pointer
65
+ count = count_pointer.read_ulong
66
+ windows = windows_pointer.read_pointer.read_array_of_long(count)
67
+ windows.map { |window| XDo::Window.new self, window }
68
+ end
69
+
70
+ # Returns the currently active X window.
71
+ def active_window
72
+ window_pointer = FFI::MemoryPointer.new :ulong, 1
73
+ XDo::FFILib.xdo_get_active_window @_pointer, window_pointer
74
+ XDo::Window.new self, window_pointer.read_ulong
75
+ end
76
+
77
+ # Returns the X window that has the input focus.
78
+ def focused_window
79
+ window_pointer = FFI::MemoryPointer.new :ulong, 1
80
+ XDo::FFILib.xdo_get_focused_window @_pointer, window_pointer
81
+ XDo::Window.new self, window_pointer.read_ulong
82
+ end
83
+
84
+ # Returns the "real" X window that has the input focus.
85
+ #
86
+ # This calls xdo_get_focused_window_sane instead of xdo_get_focused_window and is
87
+ # recommended.
88
+ def real_focused_window
89
+ window_pointer = FFI::MemoryPointer.new :ulong, 1
90
+ XDo::FFILib.xdo_get_focused_window_sane @_pointer, window_pointer
91
+ XDo::Window.new self, window_pointer.read_ulong
92
+ end
93
+
94
+ # The version of the underlying library.
95
+ #
96
+ # This method is mostly useful as a health check on your installtion. A
97
+ # non-nil, non-empty result means the gem was built successfully against
98
+ # libxdo.
99
+ def self.lib_version
100
+ XDo::FFILib.xdo_version
101
+ end
102
+ end # class XDo
@@ -0,0 +1,50 @@
1
+ # Automatically generated by tasks/ffi_codegen.rb
2
+
3
+ # :nodoc: namespace
4
+ class XDo
5
+
6
+ # :nodoc: namespace
7
+ module FFILib
8
+ # Constant values extracted from headers.
9
+ module Consts
10
+ XDO_ERROR = 1
11
+ XDO_SUCCESS = 0
12
+ SEARCH_TITLE = 0x0001
13
+ SEARCH_CLASS = 0x0002
14
+ SEARCH_NAME = 0x0004
15
+ SEARCH_PID = 0x0008
16
+ SEARCH_ONLYVISIBLE = 0x0010
17
+ SEARCH_SCREEN = 0x0020
18
+ SEARCH_CLASSNAME = 0x0040
19
+ SEARCH_DESKTOP = 0x0080
20
+ SEARCH_ANY = nil
21
+ SEARCH_ALL = nil
22
+ SIZE_USEHINTS = 1
23
+ SIZE_USEHINTS_X = 2
24
+ SIZE_USEHINTS_Y = 4
25
+ SIZE_TO = 0
26
+ SIZE_FROM = 1
27
+ XDO_FIND_PARENTS = 0
28
+ XDO_FIND_CHILDREN = 1
29
+ XDO_FEATURE_XTEST = nil
30
+ end # module XDo::FFILib::Consts
31
+
32
+ # Status returned by libxdo functions.
33
+ Status = enum [
34
+ :error, Consts::XDO_ERROR,
35
+ :success, Consts::XDO_SUCCESS,
36
+ ]
37
+
38
+ # Search directions.
39
+ Direction = enum [
40
+ :parents, Consts::XDO_FIND_PARENTS,
41
+ :children, Consts::XDO_FIND_CHILDREN,
42
+ ]
43
+
44
+ # Optional features.
45
+ Feature = enum [
46
+ :xtest, Consts::XDO_FEATURE_XTEST,
47
+ ]
48
+
49
+ end # namespace XDo::FFILib
50
+ end # namespace XDo
@@ -0,0 +1,65 @@
1
+ require 'ffi'
2
+
3
+ # :nodoc: namespace
4
+ class XDo
5
+
6
+ # :nodoc: function attachments
7
+ module FFILib
8
+ attach_function :xdo_new, [:string], :pointer
9
+ attach_function :xdo_version, [], :string
10
+ attach_function :xdo_free, [:pointer], :void
11
+ attach_function :xdo_get_active_window, [:pointer, :pointer],
12
+ XDo::FFILib::Status
13
+ attach_function :xdo_get_focused_window, [:pointer, :pointer],
14
+ XDo::FFILib::Status
15
+ attach_function :xdo_get_focused_window_sane, [:pointer, :pointer],
16
+ XDo::FFILib::Status
17
+
18
+ attach_function :xdo_get_pid_window, [:pointer, :window], :int
19
+
20
+ attach_function :xdo_search_windows, [:pointer, :pointer, :pointer, :pointer],
21
+ XDo::FFILib::Status
22
+
23
+ attach_function :xdo_activate_window, [:pointer, :window], XDo::FFILib::Status
24
+ attach_function :xdo_focus_window, [:pointer, :window], XDo::FFILib::Status
25
+ attach_function :xdo_raise_window, [:pointer, :window], XDo::FFILib::Status
26
+
27
+ attach_function :xdo_get_window_name, [:pointer, :window, :pointer, :pointer,
28
+ :pointer], XDo::FFILib::Status
29
+ attach_function :xdo_get_window_location, [:pointer, :window, :pointer,
30
+ :pointer, :pointer],
31
+ XDo::FFILib::Status
32
+ attach_function :xdo_get_window_size, [:pointer, :window, :pointer, :pointer],
33
+ XDo::FFILib::Status
34
+ attach_function :xdo_move_window, [:pointer, :window, :int, :int],
35
+ XDo::FFILib::Status
36
+ attach_function :xdo_set_window_size, [:pointer, :window, :int, :int, :int],
37
+ XDo::FFILib::Status
38
+ attach_function :xdo_get_mouse_location, [:pointer, :pointer, :pointer, :pointer],
39
+ XDo::FFILib::Status
40
+ attach_function :xdo_move_mouse, [:pointer, :int, :int, :int],
41
+ XDo::FFILib::Status
42
+ attach_function :xdo_move_mouse_relative, [:pointer, :int, :int],
43
+ XDo::FFILib::Status
44
+ attach_function :xdo_wait_for_mouse_move_from, [:pointer, :int, :int],
45
+ XDo::FFILib::Status
46
+ attach_function :xdo_wait_for_mouse_move_to, [:pointer, :int, :int],
47
+ XDo::FFILib::Status
48
+
49
+ attach_function :xdo_move_mouse_relative_to_window, [:pointer, :window, :int,
50
+ :int], XDo::FFILib::Status
51
+ attach_function :xdo_mouse_down, [:pointer, :window, :int], XDo::FFILib::Status
52
+ attach_function :xdo_mouse_up, [:pointer, :window, :int], XDo::FFILib::Status
53
+ attach_function :xdo_click_window, [:pointer, :window, :int], XDo::FFILib::Status
54
+
55
+ attach_function :xdo_enter_text_window, [:pointer, :window, :string, :int],
56
+ XDo::FFILib::Status
57
+ attach_function :xdo_send_keysequence_window, [:pointer, :window, :string, :int],
58
+ XDo::FFILib::Status
59
+ attach_function :xdo_send_keysequence_window_down, [:pointer, :window, :string, :int],
60
+ XDo::FFILib::Status
61
+ attach_function :xdo_send_keysequence_window_up, [:pointer, :window, :string, :int],
62
+ XDo::FFILib::Status
63
+ end # module XDo::FFILib
64
+
65
+ end # namespace XDo
@@ -0,0 +1,50 @@
1
+ require 'ffi'
2
+
3
+ # :nodoc: namespace
4
+ class XDo
5
+
6
+ # FFI to the raw libxdo functions.
7
+ module FFILib
8
+ extend FFI::Library
9
+ ffi_lib 'libxdo.so'
10
+
11
+ # :nodoc: lifted from xdo.h
12
+ class XDoContext < FFI::Struct
13
+ layout :xdpy, :pointer,
14
+ :display_name, :string,
15
+ :charcodes, :pointer,
16
+ :charcodes_len, :int,
17
+ :modmap, :pointer,
18
+ :keymap, :pointer,
19
+ :keycode_high, :int,
20
+ :keycode_low, :int,
21
+ :keysyms_per_keycode, :int,
22
+ :close_display_when_freed, :int,
23
+ :quiet, :int,
24
+ :debug, :int,
25
+ :features_mask, :int
26
+ end # class XDo::FFILib::XDoContext
27
+
28
+ # :nodoc: lifted from xdo.h
29
+ class XDoSearch < FFI::Struct
30
+ layout :title, :pointer,
31
+ :winclass, :pointer,
32
+ :winclassname, :pointer,
33
+ :winname, :pointer,
34
+ :pid, :int,
35
+ :max_depth, :long,
36
+ :only_visible, :int,
37
+ :screen, :int,
38
+ :require, :int,
39
+ :searchmask, :int,
40
+ :desktop, :long,
41
+ :limit, :uint
42
+ end # class XDo::FFILib::XDoSearch
43
+
44
+ # :nodoc: Window from X11/X.h (Window -> XID -> unsigned long)
45
+ typedef :ulong, :window
46
+ # :nodoc: useconds_t from sys/types.h
47
+ typedef :ulong, :useconds_t
48
+ end # module XDo::FFILib
49
+
50
+ end # namespace XDo