Documentation
¶
Overview ¶
Package realinput types and clicks the way a keyboard and a mouse do: it is a Wayland client that makes one virtual keyboard (zwp_virtual_keyboard_manager_v1) and one virtual pointer (zwlr_virtual_pointer_manager_v1) on a compositor, so that Emetos receives the keys through wl_keyboard and Glutter's key and text input path, and the pointer through wl_pointer. The fake platform of gluttertest skips both paths, which is how the bug of 2026-10-27 (an input box that kept only its first key) was missed by every widget test (SPEC §15.1 "Real input", step 17b.1).
The package uses the standard library only (and github.com/rm4n0s/errors). A Client talks to the compositor named by WAYLAND_DISPLAY; it makes the keyboard once, with a US xkb keymap in a sealed file, and keeps it for its whole life, because a compositor that loses its last keyboard sends the no_keymap keymap to the clients, and a client then drops keys. Every key and every pointer event is followed by a round trip (wl_display.sync), so that when a method returns the compositor has passed the event on.
Positions are window coordinates (logical pixels from the top left of the window's content) once SetWindow has told the client where the window is; sway's IPC (SwayWindowOf, SwayLayout) gives that. sway.go speaks i3's IPC protocol over $SWAYSOCK directly, so no swaymsg process is needed.
The display tests that use it live under the emetos_display build tag and run under scripts/headless-wayland.sh; scripts/realinput.sh runs the same scenarios in a nested sway window on the user's desktop. A client must only be pointed at a compositor of its own (a headless or nested sway): never at the user's session.
Index ¶
- Constants
- func SwayCommand(ctx context.Context, command string) error
- func TextCombos(text string) ([]string, error)
- type Button
- type Client
- func (c *Client) Click(ctx context.Context, p Point) error
- func (c *Client) ClickHolding(ctx context.Context, p Point, modifier string) error
- func (c *Client) Close() error
- func (c *Client) DoubleClick(ctx context.Context, p Point) error
- func (c *Client) Drag(ctx context.Context, from, to Point, steps int) error
- func (c *Client) Hold(ctx context.Context, combo string, d time.Duration) error
- func (c *Client) MoveTo(ctx context.Context, p Point) error
- func (c *Client) Press(ctx context.Context, combos ...string) error
- func (c *Client) PressBatch(ctx context.Context, combos ...string) error
- func (c *Client) RightClick(ctx context.Context, p Point) error
- func (c *Client) Scroll(ctx context.Context, p Point, clicksX, clicksY int) error
- func (c *Client) SetWindow(origin Point, layout Rect)
- func (c *Client) Sync(ctx context.Context) error
- func (c *Client) Type(ctx context.Context, text string) error
- func (c *Client) TypeBatch(ctx context.Context, text string) error
- type Options
- type Point
- type Rect
- type SwayWindow
Constants ¶
const NoKeyDelay time.Duration = -1
NoKeyDelay as Options.KeyDelay means no wait between keys.
Variables ¶
This section is empty.
Functions ¶
func SwayCommand ¶
SwayCommand runs a command of sway (what swaymsg would be given) and returns an error with the tag RealInputSwayFailed when sway says it failed.
func TextCombos ¶
TextCombos are the key combinations that type the text on the US layout, one for each character ("shift+a" for "A", "enter" for a new line), to be pressed with Press or PressBatch after or before other keys. A character that has no key on the layout fails with the tag RealInputKeyUnknown.
Types ¶
type Button ¶
type Button uint32
Button is a button of the pointer, as Linux names it (linux/input-event-codes.h).
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
A Client is one virtual keyboard and one virtual pointer on a compositor. It is safe for concurrent use; the calls are made one at a time.
func Connect ¶
Connect connects to the compositor, makes the one virtual keyboard (with its keymap) and the virtual pointer, and returns when the compositor has them. The errors have the tags RealInputConnectFailed, RealInputProtocolMissing (the compositor lacks the seat or one of the two virtual device protocols), RealInputKeymapFailed, RealInputCompositorError, RealInputWriteFailed and RealInputReadFailed.
func (*Client) Click ¶
Click moves the pointer to a position of the window and clicks the left button.
func (*Client) ClickHolding ¶
ClickHolding moves the pointer to a position of the window and clicks the left button while a modifier key ("ctrl", "alt", "shift") is held, which is released after the click. It fails with RealInputComboInvalid for a name that is not a modifier.
func (*Client) Close ¶
Close removes the devices by closing the connection, and releases the keymap. Close it only when the application under test has ended: a compositor that loses its last keyboard tells the clients there is no keymap, and they drop keys.
func (*Client) DoubleClick ¶
DoubleClick moves the pointer to a position of the window and clicks the left button twice, quickly.
func (*Client) Drag ¶
Drag presses the left button at one position, moves to another in steps, and releases it there.
func (*Client) Hold ¶
Hold holds a key down for a time and releases it. The compositor sends no repeats (in Wayland the client makes them, from the repeat rate and delay of wl_keyboard.repeat_info, 25 a second after 600 ms unless the compositor says otherwise), so a key held long enough repeats in the application as it does for a user.
func (*Client) Press ¶
Press presses key combinations one after the other: "ctrl+p", "Escape", "alt+Left", "ctrl+shift+v", "f2", "enter". A combination that cannot be read fails with the tag RealInputComboInvalid, before any key is pressed.
func (*Client) PressBatch ¶
PressBatch presses key combinations as Press does, with all the keys written to the compositor at once (see TypeBatch).
func (*Client) RightClick ¶
RightClick moves the pointer to a position of the window and clicks the right button.
func (*Client) Scroll ¶
Scroll moves the pointer to a position of the window and turns the wheel: clicksY notches down when positive (up when negative), clicksX notches to the right when positive.
func (*Client) SetWindow ¶
SetWindow tells the client where windows coordinates are: the position of the top left of the window's content in the layout, and the bounding box of the outputs (SwayWindowOf and SwayLayout give both). Pointer methods take window coordinates.
func (*Client) Type ¶
Type types the text on the US layout, a character at a time, with Shift for capitals and symbols; a new line is Enter and a tab is Tab. A character that has no key on the layout fails with the tag RealInputKeyUnknown, before anything is typed.
type Options ¶
type Options struct {
// Socket is the Wayland socket of the compositor: a path, or a name in XDG_RUNTIME_DIR. WAYLAND_DISPLAY (and
// XDG_RUNTIME_DIR) when empty.
Socket string
// KeyDelay is how long the client waits after each key (and after its round trip), so that the application sees the
// keys at the pace of a fast typist rather than in one burst; 10 ms when zero, and a negative value (NoKeyDelay) is no
// wait at all: the next key follows as soon as the compositor has passed the last one on. Zero is therefore not "all keys
// in one batch"; TypeBatch and PressBatch send keys in one batch.
KeyDelay time.Duration
// Timeout bounds every wait for the compositor (a round trip, a write); 5 s when zero.
Timeout time.Duration
// contains filtered or unexported fields
}
Options configure Connect.
type SwayWindow ¶
type SwayWindow struct {
// PID is the process that owns the window.
PID int
// AppID and Title are the application id and the title.
AppID, Title string
// Outer is the rectangle of the window with sway's decoration, in layout pixels.
Outer Rect
// Content is the rectangle of the window's own surface in layout pixels: window coordinates count from its top left.
Content Rect
// Focused tells whether the window has the keyboard focus.
Focused bool
}
SwayWindow is a window of sway.
func SwayWindowOf ¶
func SwayWindowOf(ctx context.Context, pid int) (SwayWindow, error)
SwayWindowOf waits for the window of a process to be mapped, up to the deadline of ctx, and returns it. The error has the tag RealInputWindowNotFound when ctx ends first.
func SwayWindows ¶
func SwayWindows(ctx context.Context) ([]SwayWindow, error)
SwayWindows lists the windows of sway (the leaves of its tree that belong to a process).