class XDo::Window

Overview

Represents an XDo view of an X11 window.

win.move_mouse 0, 0
puts "typing inside #{win["WM_NAME"]}"
win.type "hello!"

Defined in:

x_do/window.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(xdo_p : Pointer(XDo::LibXDo::XDo), window : UInt64) #

[View source]

Instance Method Detail

def ==(other) #

Returns true if other has the same X11 window ID (WID).


[View source]
def [](property : String) #

Get the value associated with the property property.

NOTE Always returns a string, regardless of the underlying X11 atom. As a result, this method can return "garbage" strings for some property names.


[View source]
def []=(property : String, value : String) #

Set the window's property property to value.

# change the window's title-bar name
win["WM_NAME"] = "my custom window name"

[View source]
def activate! #

Activates the window. Requires _NET_ACTIVE_WINDOW from EWMH.

See #focus! for WMs without _NET_ACTIVE_WINDOW.

# switch to the window's desktop and raise it
win.activate!

[View source]
def child #

Attempt to find the window's child.


[View source]
def class=(klass : String) #

Set the window's class (WM_CLASS class name) to klass.

win.class = "my-custom-class"

[View source]
def class_name=(name : String) #

Set the window's class name (WM_CLASS instance name) to name.

win.class_name = "my-custom-instance"

[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 click(button : Button) #

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


[View source]
def close! #

Closes a window without trying to kill its client.

To kill the client while closing a window, see #kill!.


[View source]
def desktop #

Get the window's desktop number.

desktop = win.desktop

[View source]
def focus! #

Focuses the window.

See #activate! for WMs with _NET_ACTIVE_WINDOW.


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

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

win.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.

win.keys_down "Ctrl+o"

[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.

win.keys_up "Ctrl+o"

[View source]
def kill! #

Kills a window and the client owning it.

To close a window without killing its client, see #close!.


[View source]
def location #

Get the window's location, consisting of a tuple of width, height, and Screen object

x, y, screen = win.location

[View source]
def map! #

Maps the window, making it visible if previously unmapped. See #unmap!.


[View source]
def minimize! #

Minimizes the window.


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

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


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

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


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

Attempt to move the window to x, y on the screen.

# try to put the window in the upper left corner
win.move 0, 0

[View source]
def move(desktop) #

Attempt to move the window to desktop.

# try to move the window to desktop #3
win.move 3

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

Move the mouse relative to this window.


[View source]
def name #

Get the window's name (WM_NAME), if any.


[View source]
def on_active(*, want_active = true, &) #

Wait for the window to become active or inactive, per want_active.


[View source]
def on_focus(*, want_focus = true, &) #

Wait for the window to gain or lose focus, per want_focus.


[View source]
def on_map_state(state : WindowMapState, &) #

Wait for the window's map state to become state.


[View source]
def on_size_change(&) #

Wait for the window's dimensions to change, and yield self.

window.on_size_change do
  puts "my new size is: #{window.size}"
end

[View source]
def on_size_from(width, height, use_hints = false, &) #

Wait for the window's dimensions to change from width x height to something else.

If use_hints is set to true, the supplied dimensions are measured according to the window's size hints (not necessarily pixels).


[View source]
def on_size_to(width, height, use_hints = false, &) #

Wait for the window's dimensions to change to width x height from something else.

If use_hints is set to true, the supplied dimensions are measured according to the window's size hints (not necessarily pixels).


[View source]
def override_redirect=(override_redirect : Bool) #

Set the window's override-redirect flag.

win.override_redirect = true

[View source]
def parent #

Attempt to find the window's parent.


[View source]
def pid #

Return the process ID associated with the window, or 0 if not found.


[View source]
def raise! #

Raises the window (bringing it to the foreground).


[View source]
def resize(width, height, flags : ResizeFlag = ResizeFlag::Pixels) #

Attempt to change the window's size to width x height, scaled by flags.

# make the window 100px by 100px
win.resize 100, 100

# make the window 500 by 500 size-hint units
win.resize 500, 500, ResizeFlag::UseHints

[View source]
def size #

Return the size of the window as a tuple of width and height.

width, height = win.size

[View source]
def translate_with_hint(width, height) #

Attempt to apply the window's sizing hints with the given width and height.

Uses XGetWMNormalHints() internally to determine the resize increment and base size.

win.translate_with_hint 100, 100

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

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

win.type "hello from Crystal!"

[View source]
def unmap! #

Unmaps the window, making it invisible. See #map!.


[View source]
def urgent=(urgent : Bool) #

Set the window's urgency hint.

# tell the WM to indicate the window's urgency to the user
win.urgent = true

[View source]
def wait_for_active(*, want_active = true) #

Wait for the window to become active or inactive, per want_active.


[View source]
def wait_for_focus(*, want_focus = true) #

Wait for the window to gain or lose focus, per want_focus.


[View source]
def wait_for_map_state(state : WindowMapState) #

Wait for the window's map state to become state.


[View source]
def wait_for_size_from(width, height, use_hints = false) #

Wait for the window's dimensions to change from width x height to something else.

If use_hints is set to true, the supplied dimensions are measured according to the window's size hints (not necessarily pixels).


[View source]
def wait_for_size_to(width, height, use_hints = false) #

Wait for the window's dimensions to change to width x height from something else.

If use_hints is set to true, the supplied dimensions are measured according to the window's size hints (not necessarily pixels).


[View source]
def window : LibXDo::Window #

[View source]