libei

package
v1.3.9 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2026 License: Apache-2.0 Imports: 20 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 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

View Source
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.

View Source
const Version = "v0.1.0-libei"

Version is the robotgo-libei backend version string.

Variables

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

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

View Source
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 ActiveName

func ActiveName(name string) error

ActiveName is not supported by this backend.

func ActivePid added in v1.3.2

func ActivePid(pid int, args ...int) error

ActivePid is not supported by the portal backend.

func Alert added in v1.3.4

func Alert(title, msg, ok, cancel string) bool

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 Capture

func Capture(args ...int) (*image.RGBA, error)

Capture is not supported by this backend.

func CaptureImg

func CaptureImg(args ...int) (image.Image, error)

CaptureImg is not supported by this backend.

func CheckAccess added in v1.2.0

func CheckAccess(prompt bool) bool

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

func CloseWindow(args ...int) error

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

func DragSmooth(x, y int, args ...interface{}) error

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 FindIds

func FindIds(name string) ([]int, error)

FindIds finds PIDs by name substring (case-insensitive).

func FindName

func FindName(pid int) (string, error)

FindName returns the process name for a given PID.

func FindNames

func FindNames() ([]string, error)

FindNames returns all process names.

func FindPath

func FindPath(pid int) (string, error)

FindPath returns the executable path for a PID.

func GetActiveApp added in v1.2.0

func GetActiveApp() (string, string, int)

GetActiveApp returns empty values; the portal does not expose the focused application.

func GetBounds added in v1.3.2

func GetBounds(pid int, args ...int) (int, int, int, int)

GetBounds returns zeros; the portal does not expose window geometry.

func GetClient added in v1.3.2

func GetClient(pid int, args ...int) (int, int, int, int)

GetClient returns zeros; the portal does not expose window geometry.

func GetMousePos

func GetMousePos() (int, int)

GetMousePos returns the current mouse position (alias of Location).

func GetPid

func GetPid() int

GetPid returns the current process's PID.

func GetPixelColor

func GetPixelColor(x, y int, displayId ...int) string

GetPixelColor returns "000000"; screen reading is unavailable on this backend.

func GetScaleSize

func GetScaleSize(displayId ...int) (int, int)

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

func GetScreenSize() (int, int)

GetScreenSize returns the union size of all linked streams, or (0, 0) when no ScreenCast stream is linked.

func GetTitle

func GetTitle(args ...int) string

GetTitle returns an empty string; window titles are unavailable on this backend.

func GetVersion

func GetVersion() string

GetVersion returns the robotgo version.

func Height

func Height(img image.Image) int

Height returns the height of an image.

func KeyDown

func KeyDown(key string, args ...interface{}) error

KeyDown presses a key down. Extra args are forwarded to KeyToggle for API parity with the other backends.

func KeyPress

func KeyPress(key string, args ...interface{}) error

KeyPress presses and releases a key (alias of KeyTap).

func KeyTap

func KeyTap(key string, args ...interface{}) error

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

func KeyToggle(key string, args ...interface{}) error

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

func KeyUp(key string, args ...interface{}) error

KeyUp releases a key. Extra args are forwarded to KeyToggle for API parity with the other backends.

func Kill

func Kill(pid int) error

Kill kills a process by PID.

func Location

func Location() (int, int)

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 MaxWindow

func MaxWindow(pid int, args ...interface{}) error

MaxWindow is not supported by this backend.

func MinWindow

func MinWindow(pid int, args ...interface{}) error

MinWindow is not supported by this backend.

func MouseDown

func MouseDown(key ...interface{}) error

MouseDown sends a mouse button down event.

func MouseUp

func MouseUp(key ...interface{}) error

MouseUp sends a mouse button up event.

func Move

func Move(x, y int, displayId ...int) error

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 MoveClick

func MoveClick(x, y int, args ...interface{}) error

MoveClick moves to (x, y) then clicks. It does not click if the move fails.

func MoveRelative

func MoveRelative(x, y int) error

MoveRelative moves the mouse relative to its current position.

func MoveSmooth

func MoveSmooth(x, y int, args ...interface{}) bool

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 PadHex

func PadHex(hex uint32) string

PadHex pads a hex color value to 6 characters.

func PidExists

func PidExists(pid int) (bool, error)

PidExists checks if a process exists.

func Pids

func Pids() ([]int, error)

Pids returns all process IDs by reading /proc.

func Run

func Run(path string) ([]byte, error)

Run runs a shell command and returns its output.

func Save

func Save(img image.Image, path string, quality ...int) error

Save saves an image to a file. Format is determined by the extension.

func SaveCapture

func SaveCapture(path string, args ...int) error

SaveCapture captures the screen and saves it to a file. Screen capture is not implemented by this backend (see screen.go).

func SaveJpeg

func SaveJpeg(img image.Image, path string, quality ...int) error

SaveJpeg saves an image as JPEG.

func SavePng

func SavePng(img image.Image, path string) error

SavePng saves an image as PNG.

func ScaleF added in v1.3.0

func ScaleF(displayId ...int) float64

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

func Scroll(x, y int, args ...int) error

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

func ScrollDir(x int, direction ...interface{}) error

ScrollDir scrolls in a named direction: "up", "down" (default), "left", "right". Any other direction is an error.

func ScrollSmooth

func ScrollSmooth(to int, args ...int) error

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

func Type(str string, args ...int) int

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

func TypeDelay(str string, delay int) error

TypeDelay types a string with a per-character delay in milliseconds. It returns an error if not every character was typed.

func TypeStr

func TypeStr(str string, args ...int) error

TypeStr types a string (alias of Type). It returns an error if not every character was typed.

func Width

func Width(img image.Image) int

Width returns the width of an image.

Types

type Nps

type Nps struct {
	Pid  int
	Name string
}

Nps represents a process.

func Process

func Process() ([]Nps, error)

Process returns all processes as []Nps.

type Point

type Point struct {
	X, Y int
}

Point represents a 2D point.

type Rect

type Rect struct {
	Point
	Size
}

Rect represents a rectangle.

func GetScreenRect

func GetScreenRect(displayId ...int) Rect

GetScreenRect returns the rectangle of the stream selected by displayId (default 0), or an empty Rect when no stream is linked.

type Size

type Size struct {
	W, H int
}

Size represents a 2D size.

Jump to

Keyboard shortcuts

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