capture

package
v0.3.16 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2026 License: MIT Imports: 17 Imported by: 1 module, 4 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 capture copies screen contents out of the compositor: whole outputs and output regions through wlr-screencopy, single windows through ext-image-copy-capture (with the ext-foreign-toplevel-list enumeration and its capture sources) or Hyprland's toplevel-export, and continuous damage-driven output capture through an ext-image-copy-capture session (Stream). Screencopy frames and the frames of a persistent capture session on a window or an output (DmabufSession) can also land in a caller-allocated dmabuf imported through linux-dmabuf, the zero-copy path a screencast producer wants.

Capture runs on a private Wayland connection (Client), independent of the application's own session and event loop: every call blocks the calling goroutine until the compositor finished the copy, so run captures off the UI goroutine. Frames arrive in shared memory, are copied into a Go slice (Frame.Data), and convert to image.RGBA with Frame.Image for the 8-bit and 10-bit packed formats compositors hand out.

Protocols are feature-detected: Connect succeeds on any compositor, the Has* methods report what is offered, and a capture path whose protocol is missing fails with ErrUnsupported naming it.

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed = errors.New("capture: client closed")

ErrClosed reports use of a Client or a DmabufSession after Close.

View Source
var ErrDmabufRejected = errors.New("capture: the compositor rejected the dmabuf import")

ErrDmabufRejected reports that the compositor refused a dmabuf import (the params failed event): the format, modifier, or device does not suit it.

View Source
var ErrFailed = errors.New("capture: the compositor failed the copy")

ErrFailed reports that the compositor refused or aborted a copy: the frame's failed event, or a capture session that stopped.

View Source
var ErrFormat = errors.New("capture: unsupported pixel format")

ErrFormat reports a frame in a pixel format Image cannot convert.

View Source
var ErrReconfigured = errors.New("capture: the source's buffer constraints changed")

ErrReconfigured reports that a capture session's buffer constraints changed (the output switched mode, the window resized): the buffers allocated against the old ones no longer fit.

View Source
var ErrSessionStopped = fmt.Errorf("%w: the capture session stopped", ErrFailed)

ErrSessionStopped reports that the compositor ended a capture session: its source went away (the output was unplugged, the window closed). It is an ErrFailed.

View Source
var ErrToplevelBusy = errors.New("capture: the window already has a capture session open on this client")

ErrToplevelBusy reports a capture of a window that already has a capture session open on the same Client (a DmabufSession). wlroots (sway 1.12, wlroots 0.20) gives all of a window's sessions one shared capture source that renders only when the window's content changes, so a session joining an open one gets its first frame only at the window's next change, and on a static window never: the capture is refused rather than left to block.

View Source
var ErrUnsupported = errors.New("capture: protocol not offered by the compositor")

ErrUnsupported reports that the compositor does not offer a protocol a capture path needs. The wrapped message names the missing global.

Functions

This section is empty.

Types

type Client

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

Client is a private Wayland connection dedicated to screen capture. It binds whichever capture protocols the compositor offers and tracks the outputs; every capture call blocks on the calling goroutine until the compositor finished the copy (or refused it). A Client is safe for use from several goroutines, but its calls serialize: run captures that must overlap on separate Clients.

func Connect

func Connect() (*Client, error)

Connect opens a capture connection to the compositor named by WAYLAND_DISPLAY and binds the capture globals. Missing protocols are not an error here: each capture call reports ErrUnsupported for the path it needs, and the Has* methods probe ahead of time.

func ConnectTo

func ConnectTo(socket string) (*Client, error)

ConnectTo is Connect against an explicit socket: an absolute path as is, a name inside XDG_RUNTIME_DIR, or "" for WAYLAND_DISPLAY, as libwayland resolves them.

func (*Client) CaptureDynamic

func (c *Client) CaptureDynamic(opts Options) (*Frame, error)

CaptureDynamic copies one frame of the cast target. Before a target is first chosen, it blocks until one is.

func (*Client) CaptureHyprlandWindow

func (c *Client) CaptureHyprlandWindow(address uint64, opts Options) (*Frame, error)

CaptureHyprlandWindow copies one frame of a Hyprland window through hyprland-toplevel-export, addressed by the window's address (the hex handle `hyprctl clients` prints, as a number). The copy starts as soon as the shm layout arrives and ignores damage, so the first frame is always complete.

func (*Client) CaptureOutput

func (c *Client) CaptureOutput(o Output, opts Options) (*Frame, error)

CaptureOutput copies one frame of a whole output through wlr-screencopy into shared memory.

func (*Client) CaptureOutputDmabuf

func (c *Client) CaptureOutputDmabuf(o Output, cursor bool, buf *DmabufBuffer) ([]Rect, error)

CaptureOutputDmabuf copies one screencopy frame of the output straight into an imported dmabuf (zero copy: no shm readback). It returns the frame's damage. Fencing is the caller's: reuse a buffer only after its consumer finished reading it.

func (*Client) CaptureOutputOnce

func (c *Client) CaptureOutputOnce(o Output, opts Options) (*Frame, error)

CaptureOutputOnce copies one frame of a whole output through ext-image-copy-capture - the compositor-neutral alternative to CaptureOutput for compositors without wlr-screencopy.

func (*Client) CaptureOutputRegion

func (c *Client) CaptureOutputRegion(o Output, region image.Rectangle, opts Options) (*Frame, error)

CaptureOutputRegion copies a region of an output, given in the output's logical coordinates, through wlr-screencopy.

func (*Client) CaptureToplevel

func (c *Client) CaptureToplevel(t Toplevel, opts Options) (*Frame, error)

CaptureToplevel copies one frame of a window through ext-image-copy-capture: a capture source from the toplevel handle, a session whose constraints size the shm buffer, and one frame.

It must not overlap a DmabufSession on the same window: on this Client that is ErrToplevelBusy; on another Client or in another process, which this one cannot see, wlroots compositors (sway) copy the frame only once the window's content next changes, so the call blocks until then.

func (*Client) Close

func (c *Client) Close() error

Close drops the connection; every compositor-side capture object dies with it.

func (*Client) CopyOutputDmabuf

func (c *Client) CopyOutputDmabuf(o Output, cursor bool, buf *DmabufBuffer) error

CopyOutputDmabuf copies the output's next frame into an imported dmabuf without waiting for it to change (a plain screencopy copy): what a stream filling at its own rate, or a probe of an idle output, needs. CaptureOutputDmabuf waits for damage instead, and reports it.

func (*Client) CopyOutputRegionDmabuf

func (c *Client) CopyOutputRegionDmabuf(o Output, region image.Rectangle, cursor bool, buf *DmabufBuffer) error

CopyOutputRegionDmabuf is CopyOutputDmabuf for a region of the output, in its logical coordinates, into a buffer of its DmabufRegionFormat.

func (*Client) DmabufFormat

func (c *Client) DmabufFormat(o Output, cursor bool) (DmabufFormat, error)

DmabufFormat reports the dmabuf layout the compositor offers for the output's screencopy frames (wlr-screencopy v3's linux_dmabuf event), with the modifiers and device its linux-dmabuf v4 default feedback names, probing once per output with a frame that is never copied and caching the answer (the format is stable per output). ErrUnsupported means the compositor offers only shm here, lacks linux-dmabuf v4 feedback or screencopy v3, or imports the format in no explicit modifier - stay on the shm path.

func (*Client) DmabufRegionFormat

func (c *Client) DmabufRegionFormat(o Output, region image.Rectangle, cursor bool) (DmabufFormat, error)

DmabufRegionFormat is DmabufFormat for the frames of a region of the output, in its logical coordinates: the size is the region's in buffer pixels. Whether a compositor takes a region's frames in a dmabuf is its own to say, so each region is asked: ErrUnsupported stays on the shm path.

func (*Client) HandleDisplayError

func (c *Client) HandleDisplayError(ev wl.DisplayErrorEvent)

HandleDisplayError implements wl.DisplayErrorHandler: keep the compositor's fatal verdict so the failing call names it.

func (*Client) HandleForeignToplevelListV1Toplevel

func (c *Client) HandleForeignToplevelListV1Toplevel(ev wlr.ForeignToplevelListV1ToplevelEvent)

HandleForeignToplevelListV1Toplevel implements the list's toplevel handler: start tracking a new handle.

func (*Client) HandleRegistryGlobal

func (c *Client) HandleRegistryGlobal(ev wl.RegistryGlobalEvent)

HandleRegistryGlobal implements wl.RegistryGlobalHandler: bind the capture globals the compositor advertises.

func (*Client) HandleRegistryGlobalRemove

func (c *Client) HandleRegistryGlobalRemove(ev wl.RegistryGlobalRemoveEvent)

HandleRegistryGlobalRemove implements wl.RegistryGlobalRemoveHandler: an unplugged output leaves the list.

func (*Client) HandleSeatCapabilities

func (c *Client) HandleSeatCapabilities(ev wl.SeatCapabilitiesEvent)

HandleSeatCapabilities implements wl.SeatCapabilitiesHandler.

func (*Client) HasCursorCapture

func (c *Client) HasCursorCapture() bool

HasCursorCapture reports whether the pointer over a source can be followed through an ext-image-copy-capture cursor session: the copy manager is offered and the seat has a pointer.

func (*Client) HasDmabuf

func (c *Client) HasDmabuf() bool

HasDmabuf reports whether linux-dmabuf is bound, the precondition of the zero-copy screencopy target.

func (*Client) HasDynamicCapture

func (c *Client) HasDynamicCapture() bool

HasDynamicCapture reports whether the compositor's cast target can be captured through a lys-dynamic-capture source (Dynamic).

func (*Client) HasHyprlandExport

func (c *Client) HasHyprlandExport() bool

HasHyprlandExport reports whether Hyprland's toplevel-export protocol is available.

func (*Client) HasOutputCapture

func (c *Client) HasOutputCapture() bool

HasOutputCapture reports whether outputs can be captured through ext-image-copy-capture (the continuous Stream path).

func (*Client) HasScreencopy

func (c *Client) HasScreencopy() bool

HasScreencopy reports whether wlr-screencopy (whole-output and region capture) is available.

func (*Client) HasToplevelCapture

func (c *Client) HasToplevelCapture() bool

HasToplevelCapture reports whether single windows can be captured through ext-image-copy-capture: the copy manager, the foreign-toplevel source manager, and the toplevel list are all offered.

func (*Client) ImportDmabuf

func (c *Client) ImportDmabuf(d dmabuf.Buffer) (*DmabufBuffer, error)

ImportDmabuf imports a caller-allocated dmabuf as a wl_buffer and waits one roundtrip for the compositor's verdict. The import uses the asynchronous create, whose failure is an event: a rejected import surfaces here as ErrDmabufRejected with the connection intact, where create_immed's failure is a fatal protocol error.

func (*Client) OpenDmabufSession

func (c *Client) OpenDmabufSession(src Source, cursor bool) (*DmabufSession, error)

OpenDmabufSession opens a capture session on src, painting the cursor when cursor is set, and waits for its buffer constraints. ErrUnsupported means the compositor lacks the session's protocols or offers this source no dmabuf layout with an explicit modifier, and ErrSessionStopped that the source went away first.

A window takes one session at a time: while the session is open, CaptureToplevel and another OpenDmabufSession on the same window and Client fail with ErrToplevelBusy, as wlroots compositors (sway) would copy the joining session's first frame only once the window's content next changes. A session on the window from another Client or process cannot be detected here and has that wait.

func (*Client) OutputByName

func (c *Client) OutputByName(name string) (Output, bool)

OutputByName returns the output with the given connector name.

func (*Client) Outputs

func (c *Client) Outputs() []Output

Outputs lists the outputs in registry order, as of the last dispatch. Hotplug and mode changes are picked up by any later capture call (or Refresh).

func (*Client) Refresh

func (c *Client) Refresh() error

Refresh roundtrips the connection so output hotplug, mode changes, and toplevel list updates are current.

func (*Client) Toplevels

func (c *Client) Toplevels() ([]Toplevel, error)

Toplevels lists the windows the compositor currently advertises, in arrival order, after a roundtrip that brings the list up to date.

type Cursor

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

Cursor follows the pointer over one output or window through an ext-image-copy-capture cursor session, on its own connection and goroutine: the pointer's position and hotspot as the compositor reports them, and its image, copied anew only when the compositor says it changed. Err says why the loop ended on its own: ErrSessionStopped, ErrFailed after repeated refusals, or a dispatch failure.

func OpenDynamicCursor

func OpenDynamicCursor() (*Cursor, error)

OpenDynamicCursor follows the pointer over the cast target. ErrUnsupported means the compositor offers no dynamic source or cursor sessions, or the seat has no pointer.

func OpenOutputCursor

func OpenOutputCursor(outputName string) (*Cursor, error)

OpenOutputCursor follows the pointer over the output with the given connector name. ErrUnsupported means the compositor offers no cursor sessions or the seat has no pointer.

func OpenToplevelCursor

func OpenToplevelCursor(identifier string) (*Cursor, error)

OpenToplevelCursor follows the pointer over the window with the given ext-foreign-toplevel identifier. ErrUnsupported means the compositor offers no cursor sessions on windows or the seat has no pointer.

func (*Cursor) Close

func (k *Cursor) Close() error

Close stops the capture goroutine, waits for it, and drops the connection and the images.

func (*Cursor) Done

func (l *Cursor) Done() <-chan struct{}

Done is closed when the capture loop ended, on Close or on its own; Err then says why.

func (*Cursor) Err

func (l *Cursor) Err() error

Err is why the capture loop ended on its own; nil while it runs and after Close.

func (*Cursor) OnChange

func (k *Cursor) OnChange(wake func())

OnChange has wake called, from the capture goroutine and without its state locked, whenever the state changes. wake must not block.

func (*Cursor) ReadImage

func (k *Cursor) ReadImage(shape uint64, dst []byte, maxWidth, maxHeight int) (width, height int, ok bool)

ReadImage copies the image numbered shape into dst as rows of its format's pixels without padding, cropped from the top left to at most maxWidth x maxHeight and to what dst holds, and reports the size copied. It reports false when shape is no longer the current image or the cursor is closed.

func (*Cursor) State

func (k *Cursor) State() CursorState

State is the pointer now.

type CursorState

type CursorState struct {
	// Inside is whether the pointer is over the source.
	Inside bool
	// X and Y are where the pointer's hotspot is in the source, in its
	// buffer pixels, as of when it was last inside.
	X, Y int
	// HotspotX and HotspotY are the hotspot's place in the image.
	HotspotX, HotspotY int
	// Shape numbers the image: it grows with each new one the compositor
	// hands out, and is 0 until the first.
	Shape uint64
	// Width, Height, Stride and Format are the image's layout.
	Width, Height, Stride int
	Format                Format
}

CursorState is the pointer over a Cursor's source.

type DmabufBuffer

type DmabufBuffer struct {

	// Attrs is the imported description.
	Attrs dmabuf.Buffer
	// contains filtered or unexported fields
}

DmabufBuffer is an imported dmabuf, ready to receive screencopy and capture session frames.

func (*DmabufBuffer) Destroy

func (b *DmabufBuffer) Destroy()

Destroy releases the compositor-side buffer. The caller's plane fds are untouched.

type DmabufFormat

type DmabufFormat struct {
	Fourcc        fourcc.Format
	Width, Height int
	// Modifiers are the explicit modifiers the compositor imports
	// Fourcc in, in its preference order: allocate in one of them.
	Modifiers []fourcc.Modifier
	// Device is the dev_t of the DRM device the compositor wants the
	// buffer allocated on (gpu.OpenNode).
	Device uint64
}

DmabufFormat is a dmabuf layout the compositor takes capture frames in - an output's screencopy frames (Client.DmabufFormat) or a capture session's (DmabufSession.Formats): a DRM fourcc and the buffer size.

type DmabufSession

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

DmabufSession is a persistent ext-image-copy-capture session on one Source (a window, an output) that copies frames into dmabufs the caller allocates and imports: the zero-copy path a window share streams over. Its constraints hold until the source resizes, which Capture reports as ErrReconfigured.

The session runs on its Client. While Capture waits for the source to change, the Client's other calls proceed, so a stream can import and destroy buffers around a still window; only one wait runs on a Client at a time, so a share runs its session on a Client of its own. Close may be called from any goroutine and wakes a waiting Capture.

func (*DmabufSession) Capture

func (s *DmabufSession) Capture(buf *DmabufBuffer) (FrameInfo, error)

Capture copies the source's next frame into buf, an import of a dmabuf in one of Formats, and reports the frame. The session's first frame is copied at once; every later one waits until the source's content changes, and its Damage is what changed since the previous one. A buffer that no longer fits because the source resized is ErrReconfigured: allocate against Formats again. A frame the compositor fails for its buffer constraints waits one roundtrip for the constraints that made it fail before it is told from a refusal. ErrSessionStopped means the source went away, ErrFailed that the compositor refused the copy (a GPU that cannot render into the buffer's layout), and ErrClosed that Close ended the wait. Fencing is the caller's: reuse a buffer only after its consumer finished reading it.

func (*DmabufSession) Close

func (s *DmabufSession) Close() error

Close ends the session, waking a Capture waiting for the source to change, and releases the compositor-side session and source. The imported buffers stay the caller's to destroy. Closing twice is a no-op.

func (*DmabufSession) Formats

func (s *DmabufSession) Formats() ([]DmabufFormat, error)

Formats are the dmabuf layouts the session currently takes, in the compositor's preference order, each with the buffer size, the explicit modifiers and the device to allocate on. They change when Capture reports ErrReconfigured; an error means the new constraints take no dmabuf (ErrUnsupported) or the session ended.

type Dynamic

type Dynamic struct{}

Dynamic is the compositor's cast target as a Source: a session on it captures whatever window or output the user points the target at, and goes on across changes, reporting a size change as ErrReconfigured. Its sessions claim nothing: they may overlap.

type Format

type Format uint32

Format is a wl_shm pixel format code (the wl_shm.format enum: DRM fourcc values, except the two legacy codes for ARGB8888 and XRGB8888).

const (
	FormatARGB8888    Format = wl.ShmFormatArgb8888
	FormatXRGB8888    Format = wl.ShmFormatXrgb8888
	FormatABGR8888    Format = wl.ShmFormatAbgr8888
	FormatXBGR8888    Format = wl.ShmFormatXbgr8888
	FormatARGB2101010 Format = wl.ShmFormatArgb2101010
	FormatXRGB2101010 Format = wl.ShmFormatXrgb2101010
	FormatABGR2101010 Format = wl.ShmFormatAbgr2101010
	FormatXBGR2101010 Format = wl.ShmFormatXbgr2101010
	FormatRGB888      Format = wl.ShmFormatRgb888
	FormatBGR888      Format = wl.ShmFormatBgr888
)

The formats a Frame converts to an image: the packed 32-bit formats (8-bit channels, and the 2:10:10:10 variants 10-bit outputs hand out) and the 24-bit ones GPU renderers offer; all little endian.

func FormatFromFourcc

func FormatFromFourcc(drm fourcc.Format) Format

FormatFromFourcc maps a DRM format (a dmabuf's) to the wl_shm format code of the same memory layout.

func (Format) BytesPerPixel

func (f Format) BytesPerPixel() int

BytesPerPixel is the pixel size of a supported format, 0 for the rest.

func (Format) Fourcc

func (f Format) Fourcc() fourcc.Format

Fourcc is the DRM format of the format, the inverse of FormatFromFourcc.

func (Format) String

func (f Format) String() string

func (Format) Supported

func (f Format) Supported() bool

Supported reports whether Frame.Image can convert the format.

type Frame

type Frame struct {
	Width, Height int
	Stride        int
	Format        Format
	Data          []byte
	// YInvert is set when the rows arrive bottom-up (the screencopy
	// y_invert flag); Image flips them back.
	YInvert bool
	// Transform is the buffer transform the compositor reported for
	// the frame (ext-image-copy-capture) or TransformNormal.
	Transform Transform
	// Damage lists the regions that changed since the previous frame
	// of the same source, when the compositor reported any; empty
	// means treat the whole frame as damaged.
	Damage []Rect
}

Frame is one captured image, copied out of the shared memory buffer the compositor wrote: Height rows of Stride bytes in Format.

func (*Frame) Image

func (f *Frame) Image() (*image.RGBA, error)

Image converts the frame to a new RGBA image in presentation row order (YInvert undone; the Transform is left to the caller, who knows whether it wants buffer or presentation orientation). Formats without alpha convert fully opaque; alpha formats are premultiplied already, which is what image.RGBA stores.

func (*Frame) ImageInto

func (f *Frame) ImageInto(dst *image.RGBA) error

ImageInto converts the frame into dst as Image does, for a caller that owns the pixels' memory (reused across frames, or off the Go heap). dst must be exactly the frame's size; its stride and origin are its own.

type FrameInfo

type FrameInfo struct {
	// Damage is what changed since the session's previous frame;
	// empty means the whole frame.
	Damage []Rect
	// Transform is the buffer transform of this frame.
	Transform Transform
	// PTSNanos is the compositor's presentation time in nanoseconds
	// (CLOCK_MONOTONIC), 0 when it reported none.
	PTSNanos uint64
}

FrameInfo is what the compositor reports about one ext-image-copy frame it copied.

type Intent

type Intent uint8

Intent is what a capture is for, which decides what a compositor that keeps surfaces out of screen sharing lets it show.

const (
	// Screencast is a capture whose frames may leave the user's sight: a
	// share, a recording, a preview of either. The compositor masks the
	// surfaces kept out of screen sharing.
	Screencast Intent = iota
	// Screenshot is a one-shot capture the user asked for, declared so
	// through lys_capture_hint_v1 where the compositor offers it; it then
	// shows what a screenshot may show.
	Screenshot
)

type Options

type Options struct {
	// Cursor composites the pointer into the frame.
	Cursor bool
	// Intent is what the capture is for; the zero value is Screencast.
	Intent Intent
	// Dst is reused for the frame's pixels when it is large enough,
	// sparing the continuous-capture paths an allocation per frame.
	Dst []byte
	// AwaitDamage waits for the output to change before copying and
	// reports what changed in Frame.Damage (copy_with_damage, screencopy
	// v2+): what a continuous capture paces itself on. Without it the
	// copy takes the next frame, so a static screen still captures.
	AwaitDamage bool
}

Options tunes one capture.

type Output

type Output struct {
	// Name is the connector name (DP-1, HDMI-A-1); empty when the
	// compositor offers wl_output below version 4.
	Name string
	// Description is the human-readable output description.
	Description string
	// X and Y are the output's position in the global compositor space.
	X, Y int32
	// Width and Height are the current mode in hardware pixels, before
	// the transform.
	Width, Height int32
	// RefreshMHz is the current mode's refresh rate in mHz; 0 when no
	// mode carried the current flag.
	RefreshMHz int32
	// Scale is the integer buffer scale (1 before any scale event).
	Scale int32
	// Transform is how the compositor rotates/flips buffer contents on
	// this output.
	Transform Transform
	// contains filtered or unexported fields
}

Output is one wl_output as the capture connection sees it: the connector identity (wl_output v4 name and description), the current mode in hardware pixels, the integer scale, and the geometry event's position and transform. The position is what wl_output.geometry reports - logical coordinates on wlroots compositors, which is what layouts of several outputs are built from.

type Rect

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

Rect is a damaged region in buffer pixels.

type Source

type Source interface {
	// contains filtered or unexported methods
}

Source is what an ext-image-copy-capture session captures: an Output, a Toplevel, as the Client that opens the session lists them, or the compositor's cast target (Dynamic).

type Stream

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

Stream captures one output continuously through ext-image-copy-capture on its own connection and goroutine. Unlike repeated screencopy, the session negotiates its constraints once, and a frame's capture completes only when the output's content changed: a static screen costs no copies at all. Consumers poll Latest and copy the newest frame out. Err says why the loop ended on its own: ErrSessionStopped, ErrReconfigured, ErrFailed after repeated refusals, or a dispatch failure.

func OpenOutputStream

func OpenOutputStream(outputName string, cursor bool) (*Stream, error)

OpenOutputStream starts continuous capture of the output with the given connector name, painting the cursor when cursor is set. It returns once the session negotiated its constraints and the buffer ring exists, so Info is final; the capture goroutine is running. ErrUnsupported means the compositor lacks the ext capture protocols: fall back to per-frame screencopy.

func (*Stream) Close

func (s *Stream) Close() error

Close stops the capture goroutine, waits for it, and drops the connection and the ring. Frames already handed out read nothing afterwards.

func (*Stream) Done

func (l *Stream) Done() <-chan struct{}

Done is closed when the capture loop ended, on Close or on its own; Err then says why.

func (*Stream) Err

func (l *Stream) Err() error

Err is why the capture loop ended on its own; nil while it runs and after Close.

func (*Stream) Info

func (s *Stream) Info() StreamInfo

Info is the negotiated geometry.

func (*Stream) Latest

func (s *Stream) Latest(dst *StreamFrame) bool

Latest copies the most recent published frame into dst, reusing its Damage's storage, and reports false before the first.

type StreamFrame

type StreamFrame struct {
	// Seq increments per published frame; an unchanged Seq means
	// nothing new was captured (the screen is static).
	Seq uint64
	FrameInfo
	// contains filtered or unexported fields
}

StreamFrame is one captured frame a Stream published, copied out by Latest. Its pixels stay in a ring buffer the capture goroutine reuses a couple of frames later, so copy them out (ReadInto, Frame) promptly.

func (*StreamFrame) Frame

func (f *StreamFrame) Frame() (*Frame, error)

Frame copies the pixels out into a standalone Frame.

func (*StreamFrame) ReadInto

func (f *StreamFrame) ReadInto(dst []byte) int

ReadInto copies the frame's pixels (Info().Stride-byte rows) into dst, returning the bytes copied; 0 once the stream is closed.

type StreamInfo

type StreamInfo struct {
	Width, Height, Stride int
	Format                Format
	// RefreshMHz is the output's current refresh rate, 0 if unknown.
	RefreshMHz int32
	// Transform is the output's transform when the stream opened.
	Transform Transform
}

StreamInfo is the geometry a Stream negotiated, fixed for its lifetime: what a consumer (a PipeWire producer, say) advertises.

type Toplevel

type Toplevel struct {
	// Title and AppID are the window's latest title and app id.
	Title, AppID string
	// Identifier is the compositor's stable identifier for the
	// window, unique for its lifetime.
	Identifier string
	// contains filtered or unexported fields
}

Toplevel is one window as ext-foreign-toplevel-list reports it. The list carries no focus or activation state, so the caller decides which toplevel to capture (typically by matching the compositor's active window on AppID and Title).

type Transform

type Transform uint32

Transform is a wl_output.transform value: how the compositor rotates (counter-clockwise, in 90 degree steps) and flips buffer contents when presenting them.

const (
	TransformNormal     Transform = wl.OutputTransformNormal
	Transform90         Transform = wl.OutputTransform90
	Transform180        Transform = wl.OutputTransform180
	Transform270        Transform = wl.OutputTransform270
	TransformFlipped    Transform = wl.OutputTransformFlipped
	TransformFlipped90  Transform = wl.OutputTransformFlipped90
	TransformFlipped180 Transform = wl.OutputTransformFlipped180
	TransformFlipped270 Transform = wl.OutputTransformFlipped270
)

The eight wl_output transforms.

func (Transform) SwapsAxes

func (t Transform) SwapsAxes() bool

SwapsAxes reports whether the transform exchanges width and height (the 90 and 270 degree variants).

Jump to

Keyboard shortcuts

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