wayland

package
v1.0.13 Latest Latest
Warning

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

Go to latest
Published: Dec 5, 2026 License: AGPL-3.0 Imports: 12 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 wayland reaches the screen and the input of a Wayland desktop through the compositor's D-Bus API. A Wayland client cannot read the screen or send input to other clients the way an X11 client can; the compositor offers both itself, and hands the picture over as a PipeWire stream. See docs/design/wayland-host.md.

Only Linux has an implementation. The first one is GNOME's: Mutter's org.gnome.Mutter.ScreenCast and org.gnome.Mutter.RemoteDesktop, which is what GNOME's own portal backend and gnome-remote-desktop use.

Index

Constants

View Source
const (
	BtnLeft   int32  = 0x110
	BtnRight  int32  = 0x111
	BtnMiddle int32  = 0x112
	BtnSide   int32  = 0x113 // back
	BtnExtra  int32  = 0x114 // forward
	AxisVert  uint32 = 0
	AxisHoriz uint32 = 1
)

Evdev pointer buttons, as Button takes them (linux/input-event-codes.h).

Variables

View Source
var ErrEnded = errors.New("the screen sharing was stopped on the host")

ErrEnded is the error of a session the desktop ended: the user stopped the screen sharing from GNOME's indicator, or logged out.

Functions

func HasMutter

func HasMutter(c *dbus.Conn) bool

HasMutter reports whether GNOME's compositor offers its screen cast and remote desktop API on the bus.

func SessionBus

func SessionBus() (*dbus.Conn, error)

SessionBus connects to the logged-in user's session bus: $DBUS_SESSION_BUS_ADDRESS, else the user bus socket in /run/user/<uid>/bus. A host started from ssh or a system unit often has no variable although the desktop's bus is there. The connection is the caller's own; Close ends it.

Types

type Capture

type Capture struct {
	// Connector is the monitor to record; "" records the primary one.
	// It is ignored when Area is set.
	Connector string
	// Area, when not empty, records that part of the desktop instead,
	// in the layout's coordinates: several monitors in one picture.
	Area image.Rectangle
	// Cursor draws the pointer into the picture.
	Cursor bool
}

Capture says what a Mutter session records.

type Monitor

type Monitor struct {
	// Connector names the monitor ("eDP-1", "HDMI-1"); a recording of one
	// monitor asks for it by this name.
	Connector string
	// X and Y are the monitor's position in the desktop's layout.
	X, Y int
	// Width and Height are the monitor's current mode in pixels, turned
	// as the monitor is (a portrait monitor is taller than wide).
	Width, Height int
	// Scale is the monitor's scale factor (1, 1.25, 2, ...).
	Scale   float64
	Primary bool
}

Monitor is one of the desktop's monitors as the compositor lays them out.

func MutterMonitors

func MutterMonitors(ctx context.Context, c *dbus.Conn) ([]Monitor, error)

MutterMonitors lists the desktop's monitors left to right, then top to bottom. A mirrored logical monitor (several connectors showing the same picture) is listed once, by its first connector.

type MutterSession

type MutterSession struct {
	// contains filtered or unexported fields
}

MutterSession is a running Mutter remote desktop session with one recorded stream. Input sent through it reaches the whole desktop.

func StartMutter

func StartMutter(ctx context.Context, c *dbus.Conn, cap Capture) (s *MutterSession, err error)

StartMutter starts a remote desktop session that records what cap asks for, and waits until its PipeWire stream is there. GNOME shows its screen sharing indicator while the session runs.

Give each session a connection of its own and close it after the session: Mutter refuses to stop a session that never started, so what a failed start left behind in the compositor ends only with the connection.

func (*MutterSession) Button

func (s *MutterSession) Button(code int32, down bool) error

Button presses or releases an evdev pointer button (BtnLeft, ...).

func (*MutterSession) Clipboard

func (s *MutterSession) Clipboard(ctx context.Context) (string, error)

Clipboard reads the desktop's clipboard as text. It fails when the clipboard is empty or holds no text.

func (*MutterSession) Close

func (s *MutterSession) Close() error

Close stops the session. It is safe to call more than once and after the desktop ended the session.

func (*MutterSession) Done

func (s *MutterSession) Done() <-chan struct{}

Done is closed when the session ends; Err then says why (nil after Close).

func (*MutterSession) Err

func (s *MutterSession) Err() error

Err is why the session ended, or nil while it runs or after Close.

func (*MutterSession) Key

func (s *MutterSession) Key(code uint32, down bool) error

Key presses or releases a key by its evdev code; the desktop's keyboard layout decides what it types.

func (*MutterSession) Keysym

func (s *MutterSession) Keysym(sym uint32, down bool) error

Keysym presses or releases the key that types sym in the desktop's layout. Mutter ignores a keysym the layout cannot type, without an error.

func (*MutterSession) Pointer

func (s *MutterSession) Pointer(x, y float64) error

Pointer moves the pointer to x, y in the recorded stream's pixels (0, 0 is its top left corner).

func (*MutterSession) PointerBy

func (s *MutterSession) PointerBy(dx, dy float64) error

PointerBy moves the pointer by dx, dy pixels (a pointer the viewer has locked).

func (*MutterSession) SetClipboard

func (s *MutterSession) SetClipboard(ctx context.Context, text string) (<-chan struct{}, error)

SetClipboard makes text the desktop's clipboard, offered by this session until another program takes the clipboard or the session ends. The returned channel receives a value each time a program has read it.

func (*MutterSession) Stream

func (s *MutterSession) Stream() Stream

Stream is the recorded stream.

func (*MutterSession) Wheel

func (s *MutterSession) Wheel(axis uint32, steps int32) error

Wheel turns the wheel by steps notches on axis (AxisVert, AxisHoriz); positive steps scroll down or right.

type Stream

type Stream struct {
	Node                uint32
	X, Y, Width, Height int
}

Stream is one recorded area: the PipeWire node that carries its picture, and where it lies on the desktop.

Directories

Path Synopsis
Package waylandtest starts a private headless GNOME desktop for tests: a session bus, PipeWire, WirePlumber and Mutter with one virtual monitor.
Package waylandtest starts a private headless GNOME desktop for tests: a session bus, PipeWire, WirePlumber and Mutter with one virtual monitor.

Jump to

Keyboard shortcuts

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