class

XDo

Inherits Reference / Object

XDo is a Crystal interface for libxdo, the C library that backs xdotool.

It exposes most of the functionality of xdotool, allowing users to write Crystal programs that manage windows in an X11 instance.

The easiest way to use XDo is via XDo.act:

XDo.act do
  active_window do |win|
    win.type "hello from Crystal!"
  end
end

Constants

DEFAULT_DELAY = 12000
VERSION = "0.8.3"

Constructors

new(display = ENV["DISPLAY"]?)

Creates a new XDo instance with the given X11 display.

# create an instance on the default display or `DISPLAY` env variable
xdo = XDo.new

# ...or with a different X display
xdo2 = XDo.new(":2")

# ... do some work ...
Source

Class methods

act

Yields a block with an XDo instance, providing a DSL for interaction.

XDo.act do
  select_window do |win|
    win.unmap!
    sleep 1
    win.map!
    win.type "hello"
  end

  desktop = 3
end
Source
lib_version

Returns the version of libxdo being used as a String.

Source
symbol_map

Returns a Hash(String, String) indicating the current symbol map.

XDo.symbol_map # => {"alt" => "Alt_L", "ctrl" => "Control_L"}
Source

Instance methods

active_modifiers

Returns a list of XDo::LibXDo::Charcodemaps indicating all active modifier keys.

Source
active_window

Returns the Window that is currently active.

Source
active_window

Returns the Window that is currently active.

Source
clear_active_modifiers

TODO: implement

Source
desktop

Returns the current desktop's number.

Source
desktop=(desktop)

Sets the current desktop.

Source
desktops

Returns the number of desktops.

Source
desktops=(ndesktops)

Sets the number of desktops.

Source
disable_feature(feature : XDoFeatures)

Disable an xdo feature.

Source
display
Source
enable_feature(feature : XDoFeatures)

Enable an xdo feature.

Source
finalize

Destroys the instance's internal state.

Source
focused_window(*, sane = true)

Returns the Window that currently has focus.

When sane is set to true, returns the first ancestor-or-self window with the WM_CLASS property. When set to false, returns the actual focused window (which may not be the application's top-level window).

Source
focused_window(*, sane = true, &)

Returns the Window that currently has focus.

When sane is set to true, returns the first ancestor-or-self window with the WM_CLASS property. When set to false, returns the actual focused window (which may not be the application's top-level window).

Source
has_feature?(feature : XDoFeatures)

Test whether a feature is enabled.

Source
input_state

Returns the input state, which is the OR of any active modifiers in the KeyMask.

Source
mouse_location

Returns the mouse's current position as a tuple of x and y coordinates, the screen it's on, and the Window it's over.

x, y, screen, win = xdo.mouse_location
Source
mouse_window

Returns the Window that the mouse is currently over.

Source
mouse_window

Returns the Window that the mouse is currently over.

Source
move_mouse(x, y, screen)

Moves the mouse to coordinates x, y on the given screen.

Source
move_mouse(x, y)

Moves the mouse to coordinates x, y relative to its current position.

Source
on_mouse_move
Source
on_mouse_move_from(x, y, &)

Wait for the mouse to move from the coordinates x, y.

Source
on_mouse_move_to(x, y, &)

Wait for the mouse to move to the coordinates x, y.

Source
search(query)

Takes a Search and runs it, returning a list of Windows matching the search.

XDo.act do
  query = XDo::Search.build { window_name "Firefox" }
  winds = search(query)
  puts winds
end
Source
search

Like #search(query), but yields a block to build the query directly.

XDo.act do
  winds = search { window_name "Firefox" }
  puts winds
end
Source
select_window

Returns the Window selected interactively.

Source
select_window

Returns the Window selected interactively.

Source
set_active_modifiers

TODO: implement

Source
viewport

Gets the desktop viewport as an x, y tuple.

Source
viewport=(tup)

Sets the desktop viewport (only relevant if _NET_DESKTOP_VIEWPORT is supported).

XDo.act do
  viewport = {x, y}
end
Source
viewport_dimensions(screen)

Gets the dimensions of the given screen's viewport as a width, height tuple.

Source
wait_for_mouse_move_from(x, y)

Wait for the mouse to move from the coordinates x, y.

Source
wait_for_mouse_move_to(x, y)

Wait for the mouse to move to the coordinates x, y.

Source

Nested types