Documentation
¶
Overview ¶
Package libei provides a pure-Go libei/portal implementation of the robotgo API for desktop automation on Wayland compositors that do NOT expose the wlroots virtual-input protocols — most importantly GNOME (Mutter) and KDE Plasma (KWin).
Unlike the wayland backend (which speaks zwlr_virtual_pointer_v1 and zwp_virtual_keyboard_v1 directly to the compositor socket), this backend drives input through the freedesktop xdg-desktop-portal RemoteDesktop interface over D-Bus. The portal is the cross-desktop, security-reviewed path for emulated input and is the same mechanism libei is reached through.
Requirements at runtime:
- A session D-Bus bus (DBUS_SESSION_BUS_ADDRESS).
- xdg-desktop-portal plus a desktop backend implementing org.freedesktop.portal.RemoteDesktop (xdg-desktop-portal-gnome, xdg-desktop-portal-kde, or xdg-desktop-portal-wlr).
The first run shows a one-time "allow remote control" consent dialog. A restore token (persist_mode = persistent) is cached under $XDG_STATE_HOME/robotgo so subsequent runs do not re-prompt.
Capability notes:
- Keyboard, relative pointer motion, buttons and scroll are supported.
- Absolute pointer motion (Move, MoveSmooth) works through a ScreenCast monitor stream linked to the session (LinkScreenCast, on by default); GetScreenSize/GetScreenRect report the stream geometry. Without a stream, Move falls back to a relative delta from the tracked position.
- Location returns the last position injected by this backend: the portal never reports the physical cursor position.
- Screen capture and window helpers report ErrNotSupported.
The transport is intentionally hidden behind the injector interface (see conn.go) so the real libei/EIS wire protocol (via RemoteDesktop.ConnectToEIS) can be slotted in later without changing this package's public API.
Index ¶
- Constants
- Variables
- func ActiveName(name string) error
- func ActivePid(pid int, args ...int) error
- func Alert(title, msg, ok, cancel string) bool
- func Capture(args ...int) (*image.RGBA, error)
- func CaptureImg(args ...int) (image.Image, error)
- func CheckAccess(prompt bool) bool
- func Click(args ...interface{}) error
- func Close()
- func CloseWindow(args ...int) error
- func CmdCtrl() string
- func DisplaysNum() int
- func DragSmooth(x, y int, args ...interface{}) error
- func FindIds(name string) ([]int, error)
- func FindName(pid int) (string, error)
- func FindNames() ([]string, error)
- func FindPath(pid int) (string, error)
- func GetActiveApp() (string, string, int)
- func GetBounds(pid int, args ...int) (int, int, int, int)
- func GetClient(pid int, args ...int) (int, int, int, int)
- func GetMousePos() (int, int)
- func GetPid() int
- func GetPixelColor(x, y int, displayId ...int) string
- func GetScaleSize(displayId ...int) (int, int)
- func GetScreenSize() (int, int)
- func GetTitle(args ...int) string
- func GetVersion() string
- func Height(img image.Image) int
- func KeyDown(key string, args ...interface{}) error
- func KeyPress(key string, args ...interface{}) error
- func KeyTap(key string, args ...interface{}) error
- func KeyToggle(key string, args ...interface{}) error
- func KeyUp(key string, args ...interface{}) error
- func Kill(pid int) error
- func Location() (int, int)
- func MainDisplayID() int
- func MaxWindow(pid int, args ...interface{}) error
- func MinWindow(pid int, args ...interface{}) error
- func MouseDown(key ...interface{}) error
- func MouseUp(key ...interface{}) error
- func Move(x, y int, displayId ...int) error
- func MoveClick(x, y int, args ...interface{}) error
- func MoveRelative(x, y int) error
- func MoveSmooth(x, y int, args ...interface{}) bool
- func PadHex(hex uint32) string
- func PidExists(pid int) (bool, error)
- func Pids() ([]int, error)
- func Run(path string) ([]byte, error)
- func Save(img image.Image, path string, quality ...int) error
- func SaveCapture(path string, args ...int) error
- func SaveJpeg(img image.Image, path string, quality ...int) error
- func SavePng(img image.Image, path string) error
- func ScaleF(displayId ...int) float64
- func Scroll(x, y int, args ...int) error
- func ScrollDir(x int, direction ...interface{}) error
- func ScrollSmooth(to int, args ...int) error
- func Toggle(key ...interface{}) error
- func Type(str string, args ...int) int
- func TypeDelay(str string, delay int) error
- func TypeStr(str string, args ...int) error
- func Width(img image.Image) int
- type Nps
- type Point
- type Rect
- type Size
Constants ¶
const ( KeyA = "a" KeyB = "b" KeyC = "c" KeyD = "d" KeyE = "e" KeyF = "f" KeyG = "g" KeyH = "h" KeyI = "i" KeyJ = "j" KeyK = "k" KeyL = "l" KeyM = "m" KeyN = "n" KeyO = "o" KeyP = "p" KeyQ = "q" KeyR = "r" KeyS = "s" KeyT = "t" KeyU = "u" KeyV = "v" KeyW = "w" KeyX = "x" KeyY = "y" KeyZ = "z" Backspace = "backspace" Delete = "delete" Enter = "enter" Tab = "tab" Esc = "esc" Escape = "escape" Up = "up" Down = "down" Right = "right" Left = "left" Home = "home" End = "end" Pageup = "pageup" Pagedown = "pagedown" F1 = "f1" F2 = "f2" F3 = "f3" F4 = "f4" F5 = "f5" F6 = "f6" F7 = "f7" F8 = "f8" F9 = "f9" F10 = "f10" F11 = "f11" F12 = "f12" Shift = "shift" Ctrl = "ctrl" Alt = "alt" Cmd = "cmd" ShiftL = "shiftl" ShiftR = "shiftr" CtrlL = "ctrll" CtrlR = "ctrlr" AltL = "altl" AltR = "altr" Space = "space" Capslock = "capslock" Caps = "caps" Print = "print" Insert = "insert" Menu = "menu" )
Key name constants matching robotgo's API.
const Version = "v0.1.0-libei"
Version is the robotgo-libei backend version string.
Variables ¶
var ErrNoConnection = errors.New("robotgo/libei: RemoteDesktop portal session not established")
ErrNoConnection is returned when the RemoteDesktop portal session could not be established (no session bus, no portal backend, or the user denied access).
var ErrNotSupported = errors.New("robotgo/libei: operation not supported by the RemoteDesktop portal")
ErrNotSupported is returned when the running portal cannot satisfy a request (for example, screen capture or window management, which this backend does not implement, or absolute pointer motion without a linked ScreenCast).
var LinkScreenCast = true
LinkScreenCast controls whether the portal session also negotiates a ScreenCast monitor source (org.freedesktop.portal.ScreenCast.SelectSources). A linked stream is what makes absolute pointer motion (Move, MoveSmooth to a target) and screen geometry (GetScreenSize, GetScreenRect) available; without it only relative motion works. Set to false before the first call to skip the extra "share screen" consent. Default true.
Functions ¶
func Alert ¶ added in v1.3.4
Alert shows a modal alert with the ok and cancel buttons (via zenity, else xmessage) and reports whether ok was chosen; false when no helper exists.
func CaptureImg ¶
CaptureImg is not supported by this backend.
func CheckAccess ¶ added in v1.2.0
CheckAccess reports whether input injection is permitted. Access is granted per session by the portal dialog, so it always returns true here; prompt is ignored.
func Click ¶
func Click(args ...interface{}) error
Click clicks a mouse button. Default is the left button. Pass a bool true to double-click.
func Close ¶
func Close()
Close closes the portal session and the bus connection. After Close, a subsequent call into the backend re-establishes a fresh session.
func CloseWindow ¶
CloseWindow is not supported by this backend.
func CmdCtrl ¶
func CmdCtrl() string
CmdCtrl returns "ctrl" on Linux (mirrors robotgo's cross-platform helper).
func DisplaysNum ¶
func DisplaysNum() int
DisplaysNum returns the number of ScreenCast streams linked to the session (0 unless a ScreenCast source was negotiated).
func DragSmooth ¶
DragSmooth moves the mouse smoothly while holding a button down. The button is released even if the move fails; the first error of the press, move and release is returned. A target clamped into a linked stream is not an error.
func GetActiveApp ¶ added in v1.2.0
GetActiveApp returns empty values; the portal does not expose the focused application.
func GetBounds ¶ added in v1.3.2
GetBounds returns zeros; the portal does not expose window geometry.
func GetClient ¶ added in v1.3.2
GetClient returns zeros; the portal does not expose window geometry.
func GetMousePos ¶
GetMousePos returns the current mouse position (alias of Location).
func GetPixelColor ¶
GetPixelColor returns "000000"; screen reading is unavailable on this backend.
func GetScaleSize ¶
GetScaleSize returns the size of the stream selected by displayId (stream geometry is already in logical pixels), or the union size when no display is given.
func GetScreenSize ¶
GetScreenSize returns the union size of all linked streams, or (0, 0) when no ScreenCast stream is linked.
func KeyDown ¶
KeyDown presses a key down. Extra args are forwarded to KeyToggle for API parity with the other backends.
func KeyTap ¶
KeyTap taps a key (press + release), optionally with modifiers.
KeyTap("a")
KeyTap("a", "ctrl")
KeyTap("a", "ctrl", "shift")
KeyTap("a", []string{"ctrl", "shift"})
func KeyToggle ¶
KeyToggle toggles a key down or up. Default is "down". Modifiers (strings or a []string) are pressed before the key and released in reverse order after it.
KeyToggle("a") // press
KeyToggle("a", "up") // release
KeyToggle("a", "down", []string{"ctrl", "shift"})
KeyToggle("a", "up", []string{"ctrl", "shift"})
func KeyUp ¶
KeyUp releases a key. Extra args are forwarded to KeyToggle for API parity with the other backends.
func Location ¶
Location returns the current mouse position.
The RemoteDesktop portal does not expose the real cursor position. On KDE Plasma it is read through a KWin script (and on Hyprland over its IPC socket), which also resyncs the tracked position. Elsewhere (GNOME) this returns the last position injected by this backend (Move, MoveRelative, MoveSmooth, ...). It is (0, 0) until the first move and does not follow movement made by the physical mouse. Relative motion alone cannot establish an absolute position; Location stays (0, 0) until Move establishes one.
It is a pure query: it never opens a portal session (and so never shows the consent dialog), and it keeps answering from the last session after the portal closed it (#783).
func MainDisplayID ¶ added in v1.3.4
func MainDisplayID() int
MainDisplayID returns the main display index: stream 0, the default used when no displayId is given.
func MouseDown ¶
func MouseDown(key ...interface{}) error
MouseDown sends a mouse button down event.
func Move ¶
Move moves the mouse to absolute position (x, y).
With a linked ScreenCast stream (see LinkScreenCast) the move is sent as NotifyPointerMotionAbsolute on the stream that contains (x, y) — or the one selected by displayId. Without a stream the portal only accepts relative motion, so Move sends a delta from the last tracked position; when no position has been tracked yet the pointer is first parked in the top-left corner with a large relative move so the origin is known.
func MoveRelative ¶
MoveRelative moves the mouse relative to its current position.
func MoveSmooth ¶
MoveSmooth moves the mouse smoothly to absolute position (x, y). Optional args: steps (default 20), sleep ms between steps (default 5). Returns true on success; false when a step fails or the target was clamped into a linked stream.
When the current position is unknown, it jumps via Move, using a corner reset first if no stream is linked.
func SaveCapture ¶
SaveCapture captures the screen and saves it to a file. Screen capture is not implemented by this backend (see screen.go).
func ScaleF ¶ added in v1.3.0
ScaleF returns the HiDPI scale factor. The RemoteDesktop/ScreenCast portal only reports logical stream geometry ("position"/"size"); the physical pixel size is carried by the PipeWire video format, which this backend does not consume, so the scale cannot be derived and is reported as 1.
func Scroll ¶
Scroll scrolls the mouse. Positive y scrolls down, negative up; positive x scrolls right, negative left. Scroll scrolls the mouse by wheel notches. Positive y scrolls up, negative scrolls down; positive x scrolls left, negative scrolls right (matching robotgo's Cgo backend convention). Optional arg: delay ms.
func ScrollDir ¶
ScrollDir scrolls in a named direction: "up", "down" (default), "left", "right". Any other direction is an error.
func ScrollSmooth ¶
ScrollSmooth scrolls the mouse smoothly by `to` steps, repeating `num` times (default 5) with `tm` ms between steps (default 100). An optional third arg sets the horizontal offset per step. It stops at the first failed scroll.
func Toggle ¶
func Toggle(key ...interface{}) error
Toggle toggles a mouse button down or up.
Toggle("left") // press
Toggle("left", "up") // release
func Type ¶
Type types a string. Each rune is sent as an X11 keysym via NotifyKeyboardKeysym, so it is layout independent and needs no shift bookkeeping. It returns the number of characters (runes) typed and stops at the first failed key event.
func TypeDelay ¶
TypeDelay types a string with a per-character delay in milliseconds. It returns an error if not every character was typed.
Types ¶
type Rect ¶
Rect represents a rectangle.
func GetScreenRect ¶
GetScreenRect returns the rectangle of the stream selected by displayId (default 0), or an empty Rect when no stream is linked.