class XDo::Window
Wraps an xdolib Window
pointer.
Attributes
The underlying X Window
handle.
The XDo
context that produced the window.
Public Class Methods
Creates a wrapper for an X Window
handle.
This constructor is called internally by XDo#find_windows and client code should not need to call it directly.
Args:
xdo:: the XDo wrapping the libxdo context used to get this Window _window:: the X Window handle to be wrapped
# File lib/x_do/window.rb, line 171 def initialize(xdo, _window) @xdo = xdo @_xdo_pointer = xdo._pointer @_window = _window end
Public Instance Methods
Brings a window forward and gives it focus.
# File lib/x_do/window.rb, line 7 def activate XDo::FFILib.xdo_activate_window @_xdo_pointer, @_window end
Clicks a mouse button.
# File lib/x_do/window.rb, line 119 def click_mouse(button) XDo::FFILib.xdo_click_window @_xdo_pointer, @_window, button end
Gives the input focus to a window
# File lib/x_do/window.rb, line 12 def focus XDo::FFILib.xdo_focus_window @_xdo_pointer, @_window end
- x, y
-
array containing the window's coordinates.
# File lib/x_do/window.rb, line 38 def location x_pointer = FFI::MemoryPointer.new :int, 1 y_pointer = FFI::MemoryPointer.new :int, 1 XDo::FFILib.xdo_get_window_location @_xdo_pointer, @_window, x_pointer, y_pointer, nil [x_pointer.read_int, y_pointer.read_int] end
# File lib/x_do/window.rb, line 55 def move(x, y) move_raw x, y glitched_location = self.location x_decoration = glitched_location.first - x y_decoration = glitched_location.last - y move_raw x - x_decoration, y - y_decoration end
Moves the mouse in window coordinates.
# File lib/x_do/window.rb, line 106 def move_mouse(window_x, window_y) old_location = @xdo.mouse.location move_mouse_async window_x, window_y @xdo.mouse.wait_for_move_from old_location[0], old_location[1] end
Moves the mouse in window coordinates.
# File lib/x_do/window.rb, line 113 def move_mouse_async(window_x, window_y) XDo::FFILib.xdo_move_mouse_relative_to_window @_xdo_pointer, @_window, window_x, window_y end
Moves this window to a new position.
The position is given directly to X, and does not account for window decorations.
# File lib/x_do/window.rb, line 67 def move_raw(x, y) old_location = self.location return_value = move_raw_async x, y 100.times do break unless self.location == old_location sleep 0.01 end return_value end
Asks X to move this window to a new position.
# File lib/x_do/window.rb, line 78 def move_raw_async(x, y) XDo::FFILib.xdo_move_window @_xdo_pointer, @_window, x, y end
The name of the window.
# File lib/x_do/window.rb, line 27 def name name_ppointer = FFI::MemoryPointer.new :pointer, 1 len_pointer = FFI::MemoryPointer.new :int, 1 name_type_pointer = FFI::MemoryPointer.new :int, 1 XDo::FFILib.xdo_get_window_name @_xdo_pointer, @_window, name_ppointer, len_pointer, name_type_pointer name_pointer = name_ppointer.read_pointer name_pointer.nil? ? nil : name_pointer.read_string(len_pointer.read_int) end
The PID of the process owning the window.
# File lib/x_do/window.rb, line 22 def pid XDo::FFILib.xdo_get_pid_window @_xdo_pointer, @_window end
Presses a keysequence in this window.
Examples: “alt+Return”, “Alt_L+Tab”, “l”, “semicolon”
# File lib/x_do/window.rb, line 150 def press_keysequence(keysequence, delay = 0.012) XDo::FFILib.xdo_send_keysequence_window_down @_xdo_pointer, @_window, keysequence, (delay * 1_000_000).to_i end
Presses a mouse button.
# File lib/x_do/window.rb, line 124 def press_mouse(button) XDo::FFILib.xdo_mouse_down @_xdo_pointer, @_window, button end
Moves the window at the top of the stack, making it visible.
# File lib/x_do/window.rb, line 17 def raise XDo::FFILib.xdo_raise_window @_xdo_pointer, @_window end
Releases a keysequence in this window.
Examples: “alt+Return”, “Alt_L+Tab”, “l”, “semicolon”
# File lib/x_do/window.rb, line 158 def release_keysequence(keysequence, delay = 0.012) XDo::FFILib.xdo_send_keysequence_window_up @_xdo_pointer, @_window, keysequence, (delay * 1_000_000).to_i end
Releases a mouse button.
# File lib/x_do/window.rb, line 129 def release_mouse(button) XDo::FFILib.xdo_mouse_up @_xdo_pointer, @_window, button end
Resizes this window.
Args:
width:: the new window's width height:: the new window's height use_hints:: if false, width and height are specified in pixels; otherwise, the unit is relative to window size hints
# File lib/x_do/window.rb, line 89 def resize(width, height, use_hints = false) old_size = self.size return_value = resize_async width, height, use_hints 100.times do break unless self.size == old_size sleep 0.01 end return_value end
Asks X to resize this window.
# File lib/x_do/window.rb, line 100 def resize_async(width, height, use_hints = false) flags = use_hints ? XDo::FFILib::Consts::SIZE_U : 0 XDo::FFILib.xdo_set_window_size @_xdo_pointer, @_window, width, height, flags end
- width, height
-
array containing the window's size.
# File lib/x_do/window.rb, line 47 def size width_pointer = FFI::MemoryPointer.new :int, 1 height_pointer = FFI::MemoryPointer.new :int, 1 XDo::FFILib.xdo_get_window_size @_xdo_pointer, @_window, width_pointer, height_pointer [width_pointer.read_int, height_pointer.read_int] end
Sends a keysequence to this window.
Examples: “alt+Return”, “Alt_L+Tab”, “l”, “semicolon”
# File lib/x_do/window.rb, line 142 def type_keysequence(keysequence, delay = 0.012) XDo::FFILib.xdo_send_keysequence_window @_xdo_pointer, @_window, keysequence, (delay * 1_000_000).to_i end
Types a string into this window.
# File lib/x_do/window.rb, line 134 def type_string(string, delay = 0.012) XDo::FFILib.xdo_enter_text_window @_xdo_pointer, @_window, string, (delay * 1_000_000).to_i end