realinput

package
v1.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
const NoKeyDelay time.Duration = -1

NoKeyDelay as Options.KeyDelay means no wait between keys.

Variables

This section is empty.

Functions

func SwayCommand

func SwayCommand(ctx context.Context, command string) error

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

func TextCombos(text string) ([]string, error)

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

const (
	// ButtonLeft is BTN_LEFT.
	ButtonLeft Button = 0x110
	// ButtonRight is BTN_RIGHT.
	ButtonRight Button = 0x111
	// ButtonMiddle is BTN_MIDDLE.
	ButtonMiddle Button = 0x112
)

The buttons of the pointer.

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

func Connect(ctx context.Context, opts Options) (*Client, error)

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

func (c *Client) Click(ctx context.Context, p Point) error

Click moves the pointer to a position of the window and clicks the left button.

func (*Client) ClickHolding

func (c *Client) ClickHolding(ctx context.Context, p Point, modifier string) error

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

func (c *Client) Close() error

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

func (c *Client) DoubleClick(ctx context.Context, p Point) error

DoubleClick moves the pointer to a position of the window and clicks the left button twice, quickly.

func (*Client) Drag

func (c *Client) Drag(ctx context.Context, from, to Point, steps int) error

Drag presses the left button at one position, moves to another in steps, and releases it there.

func (*Client) Hold

func (c *Client) Hold(ctx context.Context, combo string, d time.Duration) error

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) MoveTo

func (c *Client) MoveTo(ctx context.Context, p Point) error

MoveTo moves the pointer to a position of the window.

func (*Client) Press

func (c *Client) Press(ctx context.Context, combos ...string) error

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

func (c *Client) PressBatch(ctx context.Context, combos ...string) error

PressBatch presses key combinations as Press does, with all the keys written to the compositor at once (see TypeBatch).

func (*Client) RightClick

func (c *Client) RightClick(ctx context.Context, p Point) error

RightClick moves the pointer to a position of the window and clicks the right button.

func (*Client) Scroll

func (c *Client) Scroll(ctx context.Context, p Point, clicksX, clicksY int) error

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

func (c *Client) SetWindow(origin Point, layout Rect)

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) Sync

func (c *Client) Sync(ctx context.Context) error

Sync waits for the compositor to handle everything sent so far.

func (*Client) Type

func (c *Client) Type(ctx context.Context, text string) error

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.

func (*Client) TypeBatch

func (c *Client) TypeBatch(ctx context.Context, text string) error

TypeBatch types the text as Type does, but all its keys are written to the compositor at once, with no round trip or wait between them: the application gets them in one read, as when an input method or a fast burst delivers several keys together.

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 Point

type Point struct{ X, Y float64 }

Point is a position in pixels.

type Rect

type Rect struct{ X, Y, Width, Height float64 }

Rect is a rectangle in pixels.

func SwayLayout

func SwayLayout(ctx context.Context) (Rect, error)

SwayLayout is the bounding box of the active outputs of sway, in layout pixels: what the absolute positions of the virtual pointer are counted against.

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

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL