class XDo

Overview

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

Defined in:

x_do.cr
x_do/enums.cr
x_do/libxdo.cr
x_do/version.cr

Constant Summary

DEFAULT_DELAY = 12000
VERSION = "0.8.3"

Constructors

Class Method Summary

Instance Method Summary

Constructor Detail

def self.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 ...

[View source]

Class Method Detail

def self.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

[View source]
def self.lib_version #

Returns the version of libxdo being used as a String.


[View source]
def self.symbol_map #

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

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

[View source]

Instance Method Detail

def active_modifiers #

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


[View source]
def active_window(&) #

Returns the Window that is currently active.


[View source]
def active_window #

Returns the Window that is currently active.


[View source]
def clear_active_modifiers #

TODO implement


[View source]
def click(button : Button) #

Click the given mouse button on the active window (mouse-down + mouse-up)


[View source]
def click(button : Button, repeat, delay = DEFAULT_DELAY) #

Click the given mouse button repeat times, with delay between each click.


[View source]
def desktop #

Returns the current desktop's number.


[View source]
def desktop=(desktop) #

Sets the current desktop.


[View source]
def desktops #

Returns the number of desktops.


[View source]
def desktops=(ndesktops) #

Sets the number of desktops.


[View source]
def disable_feature(feature : XDoFeatures) #

Disable an xdo feature.


[View source]
def display : String? #

[View source]
def enable_feature(feature : XDoFeatures) #

Enable an xdo feature.


[View source]
def finalize #

Destroys the instance's internal state.


[View source]
def 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).


[View source]
def 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).


[View source]
def has_feature?(feature : XDoFeatures) #

Test whether a feature is enabled.


[View source]
def input_state : KeyMask #

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


[View source]
def keys(keys : String, delay = DEFAULT_DELAY) #

Send some keys (down + up) to the active window, with delay between them.

keys "Ctrl+s"

[View source]
def keys_down(keys : String, delay = DEFAULT_DELAY) #

Send some key press (down) events for the given keys, with delay between them. See #keys_up.

keys_down "Ctrl+o"

[View source]
def keys_raw(keys : Array(LibXDo::Charcodemap), *, pressed : Bool, modifier = 0, delay = DEFAULT_DELAY) #

Send some key events by specifying keysyms and modifiers directly, with delay between them. You most likely want to use #keys or #type instead, however this function skips the string parsing and should consequently run slightly faster.

key1 = XDo::LibXDo::Charcodemap.new
key1.code = 38
key1.modmask = 1
key2 = XDo::LibXDo::Charcodemap.new
key2.code = 56
keys = [key1, key2]
# Sends `AB`
keys_raw keys, pressed: true
keys_raw keys, pressed: false

[View source]
def keys_up(keys : String, delay = DEFAULT_DELAY) #

Send some key release (up) events for the given keys, with delay between them. See #keys_down.

keys_up "Ctrl+o"

[View source]
def mouse_down(button : Button) #

Send a mouse-down event for the given mouse button to the active window.


[View source]
def 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

[View source]
def mouse_up(button : Button) #

Send a mouse-up event for the given mouse button to the active window.


[View source]
def mouse_window(&) #

Returns the Window that the mouse is currently over.


[View source]
def mouse_window #

Returns the Window that the mouse is currently over.


[View source]
def move_mouse(x, y, screen) #

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


[View source]
def move_mouse(x, y) #

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


[View source]
def on_mouse_move(&) #

[View source]
def on_mouse_move_from(x, y, &) #

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


[View source]
def on_mouse_move_to(x, y, &) #

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


[View source]
def 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

[View source]
def search(&) #

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

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

[View source]
def select_window(&) #

Returns the Window selected interactively.


[View source]
def select_window #

Returns the Window selected interactively.


[View source]
def set_active_modifiers #

TODO implement


[View source]
def type(text : String, delay = DEFAULT_DELAY) #

Send some text to the active window, with delay between the keystrokes.

type "hello from Crystal!"

[View source]
def viewport #

Gets the desktop viewport as an x, y tuple.


[View source]
def viewport=(tup) #

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

XDo.act do
  viewport = {x, y}
end

[View source]
def viewport_dimensions(screen) #

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


[View source]
def wait_for_mouse_move_from(x, y) #

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


[View source]
def wait_for_mouse_move_to(x, y) #

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


[View source]