Skip to main content

Crate wlr_capture

Crate wlr_capture 

Source
Expand description

wlr-capture — the reusable bricks behind the wlr-utils tools.

Always available (headless-friendly, no egui/EGL display deps):

  • wl: native Wayland client that enumerates foreign toplevels + outputs and captures them (full-resolution, zero-copy GPU dma-buf path) via ext-image-copy-capture.
  • clipboard: put a captured blob on the wlroots clipboard (data-control).
  • gl: EGL/GL dma-buf import + headless readback (gl::GpuReadback).
  • sink: the sink::FrameSink seam shared by screenshot/record/timelapse, with GPU dma-buf readback under the default path.
  • stream: the shared live-capture session driver (arm/poll/reopen/give-up), used by the mirror, recorder and change monitor.
  • diff: a frame-difference metric for change detection.

Behind the compose feature (resamples with image):

  • capture: resolve a source (output/window/region) to a wl::CapturedImage, compositing across mixed-scale outputs. Shared by wlr-shot and wlr-peek.

Behind the video feature (links system FFmpeg via ffmpeg-next, headless):

  • video: a sink::FrameSink that encodes a capture stream to a file with a pluggable hardware/software backend (NVENC / VAAPI / libx264).

Behind the focus feature (compositor IPC, pulls serde_json):

  • focus: “the active window” / “the current output” via the compositor’s own IPC (Sway today). Wayland gives no portable way to query focus.

This crate carries no localised UI strings: it exposes an API and typed CaptureErrors, and any on-screen text (e.g. the overlay hints, the mirror labels) is passed in by the caller. Each tool crate owns its own catalog via wlr-i18n.

Behind the toolkit feature (on by default) — the egui/EGL overlay toolkit:

  • render: egui → egui_glow rendering on an EGL context bound to a surface.
  • icons / theme: shared overlay UI helpers.

Consumers (wlr-chooser, wlr-pip, …) build their own windowing host on top and reuse this engine for the heavy lifting; a future headless recorder can use the capture engine + readback without pulling in the toolkit.

Re-exports§

pub use error::CaptureError;

Modules§

capturecompose
High-level capture: resolve a source (output, window, logical region) to a ready-to-use CapturedImage, compositing across outputs when a region spans several (possibly mixed-scale) monitors.
clipboard
Native Wayland clipboard copy via zwlr_data_control_v1 (the wlroots clipboard-manager protocol, the same one wl-copy and grim use).
diff
Frame-difference metric for change detection.
doctor
Environment + compositor-capability probe, shared by every tool’s doctor command.
error
The capture engine’s typed error surface.
focusfocus
Focus-aware capture helpers: “the active window” and “the current output”.
gl
EGL/GLES core: dma-buf → GL texture import and headless readback.
iconstoolkit
Resolve an application icon from its app-id and rasterize it to RGBA8 (unmultiplied alpha), for display next to window names. PNG/JPEG via image, SVG via resvg.
mirrormirror
xdg-toplevel windowing host for the live mirror.
overlayoverlay
Interactive frozen-screen overlay: a wlr-layer-shell surface per output showing that output’s frozen capture, shared by several interactions (Mode): select_region (drag a rectangle), pick_point (the wlr-peek colour picker, with a loupe) and magnify (a full-screen zoom that follows the cursor). Coordinates are tracked in the global logical space so they span outputs. Rendered with egui on the shared render::Gpu, like the chooser’s overlay — one surface (and GL context) per output.
paths
Filesystem locations shared by the tools (control sockets, single-instance locks).
rendertoolkit
Shared egui → egui_glow rendering core on an EGL/GLES context bound to a Wayland surface, plus zero-copy dma-buf → GL texture import.
sink
Common output seam for capture-consuming tools (screenshot, record, timelapse).
stream
Shared driver for a live capture session over one source.
themetoolkit
Colour & font theme. Sensible generic-dark defaults, overridable from ~/.config/wlr-chooser/theme.toml (or $XDG_CONFIG_HOME/wlr-chooser/theme.toml).
videovideo
Video encoding sink: turn a capture stream into a file via FFmpeg.
wl
Native Wayland client: enumerate foreign toplevels and outputs, and capture them via ext-image-copy-capture-v1.

Structs§

Connection
The Wayland connection