Class: XDo
- Inherits:
-
Object
- Object
- XDo
- Defined in:
- lib/x_do.rb,
lib/x_do/mouse.rb,
lib/x_do/window.rb,
lib/x_do/context.rb,
lib/x_do/ffi_lib.rb,
lib/x_do/keyboard.rb,
lib/x_do/ffi_autogen.rb,
lib/x_do/ffi_lib_ext.rb,
lib/x_do/ffi_functions.rb
Overview
:nodoc: namespace
Defined Under Namespace
Modules: FFILib Classes: Keyboard, Mouse, Window
Instance Attribute Summary collapse
-
#_context ⇒ Object
The underlying libxdo context structure.
-
#_pointer ⇒ Object
Pointer to the underlying _libxdo context structure.
-
#keyboard ⇒ Object
The keyboard state for this context.
-
#mouse ⇒ Object
The mouse state for this context.
Class Method Summary collapse
-
.lib_version ⇒ Object
The version of the underlying library.
Instance Method Summary collapse
-
#active_window ⇒ Object
Returns the currently active X window.
-
#close ⇒ Object
Releases resources associated with this context.
-
#display_name ⇒ Object
The display name for the current context.
-
#finalize ⇒ Object
:nodoc: automatically close contexts as they go out of scope.
-
#find_windows(options = {}) ⇒ Object
Returns X windows matching a query.
-
#focused_window ⇒ Object
Returns the X window that has the input focus.
-
#initialize(display_name = nil) ⇒ XDo
constructor
Creates a context for an X display.
-
#real_focused_window ⇒ Object
Returns the “real” X window that has the input focus.
Constructor Details
#initialize(display_name = nil) ⇒ XDo
Creates a context for an X display.
Args:
display_name:: an X display name, such as ":0"; if not given, libxdo will
choose a default display (usually the one pointed by the
DISPLAY variable)
9 10 11 12 13 14 |
# File 'lib/x_do/context.rb', line 9 def initialize(display_name = nil) @_pointer = XDo::FFILib.xdo_new display_name @_context = XDo::FFILib::XDoContext.new @_pointer @keyboard = XDo::Keyboard.new self @mouse = XDo::Mouse.new self end |
Instance Attribute Details
#_context ⇒ Object
The underlying libxdo context structure.
35 36 37 |
# File 'lib/x_do/context.rb', line 35 def _context @_context end |
#_pointer ⇒ Object
Pointer to the underlying _libxdo context structure.
37 38 39 |
# File 'lib/x_do/context.rb', line 37 def _pointer @_pointer end |
#keyboard ⇒ Object
The keyboard state for this context.
40 41 42 |
# File 'lib/x_do/context.rb', line 40 def keyboard @keyboard end |
#mouse ⇒ Object
The mouse state for this context.
43 44 45 |
# File 'lib/x_do/context.rb', line 43 def mouse @mouse end |
Class Method Details
.lib_version ⇒ Object
The version of the underlying library.
This method is mostly useful as a health check on your installtion. A non-nil, non-empty result means the gem was built successfully against libxdo.
99 100 101 |
# File 'lib/x_do/context.rb', line 99 def self.lib_version XDo::FFILib.xdo_version end |
Instance Method Details
#active_window ⇒ Object
Returns the currently active X window.
71 72 73 74 75 |
# File 'lib/x_do/context.rb', line 71 def active_window window_pointer = FFI::MemoryPointer.new :ulong, 1 XDo::FFILib.xdo_window_get_active @_pointer, window_pointer XDo::Window.new self, window_pointer.read_ulong end |
#close ⇒ Object
Releases resources associated with this context.
17 18 19 20 21 22 |
# File 'lib/x_do/context.rb', line 17 def close return unless @_context XDo::FFILib.xdo_free @_pointer @_pointer = nil @_context = nil end |
#display_name ⇒ Object
The display name for the current context.
30 31 32 |
# File 'lib/x_do/context.rb', line 30 def display_name @_context[:display_name] end |
#finalize ⇒ Object
:nodoc: automatically close contexts as they go out of scope.
25 26 27 |
# File 'lib/x_do/context.rb', line 25 def finalize close end |
#find_windows(options = {}) ⇒ Object
Returns X windows matching a query.
Args:
options:: hash that accepts the following keys:
:title:: grep pattern that the window title has to match
:name:: grep pattern that the window name has to match
:class:: grep pattern that the window class has to match
:class_name:: grep pattern that the window class (name?) has to match
:pid:: only return windows whose process ID equals this
:screen:: only return windows in this screen number
:desktop:: only return windows with this desktop number
:visible:: if true, only visible windows will be returned
Returns an array of Window instances that match the query.
59 60 61 62 63 64 65 66 67 68 |
# File 'lib/x_do/context.rb', line 59 def find_windows( = {}) query = XDo::FFILib::XDoSearch. windows_pointer = FFI::MemoryPointer.new :pointer, 1 count_pointer = FFI::MemoryPointer.new :ulong, 1 XDo::FFILib.xdo_window_search @_pointer, query, windows_pointer, count_pointer count = count_pointer.read_ulong windows = windows_pointer.read_pointer.read_array_of_long(count) windows.map { |window| XDo::Window.new self, window } end |
#focused_window ⇒ Object
Returns the X window that has the input focus.
78 79 80 81 82 |
# File 'lib/x_do/context.rb', line 78 def focused_window window_pointer = FFI::MemoryPointer.new :ulong, 1 XDo::FFILib.xdo_window_get_focus @_pointer, window_pointer XDo::Window.new self, window_pointer.read_ulong end |
#real_focused_window ⇒ Object
Returns the “real” X window that has the input focus.
This calls xdo_window_sane_get_focus instead of xdo_window_get_focus and is recommended.
88 89 90 91 92 |
# File 'lib/x_do/context.rb', line 88 def real_focused_window window_pointer = FFI::MemoryPointer.new :ulong, 1 XDo::FFILib.xdo_window_sane_get_focus @_pointer, window_pointer XDo::Window.new self, window_pointer.read_ulong end |