Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

capture

A live preview of one output (monitor) through ext-image-copy-capture-v1, else wlr-screencopy. Reach for it for an overview, a monitor picker or a screenshot preview. Without either protocol it draws nothing and logs one warning.

A rounded preview of the first screen at up to 30 frames per second:

local first_output = mantle.screens:map(function(screens)
    return screens and screens[1] and screens[1].name or ""
end)

local preview = rect {
    width = 320,
    height = 180,
    radius = 8,
    clip = "Rounded",
    background = "#000000",
    children = {
        capture { output = first_output, live = 30, fit = "contain", width = "Fill", height = "Fill" },
    },
}

mantle.screens lists the connected outputs by connector name.

Properties

capture takes the common properties, plus:

PropertyTypeDefaultBehaviour
outputstring|Bound""Connector name, e.g. "DP-1"; "" draws nothing. An unknown name draws nothing and warns once. Changing it starts a fresh capture
fit"cover"|"contain"|"stretch"|Bound"cover"As on image
liveboolean|number|Boundfalsefalse: capture on show and on each output change. true: every frame, one in flight. A number: at most that many fps, (0, 1000]. Hiding the node or unmapping its surface drops the capture; showing starts a fresh one
regionRect|Bound, [0, 8192]The whole outputPart of the output in its logical px, placed by fit as the whole frame. Every key is required and in that range; the size is non-zero
paint_cursorboolean|BoundfalseInclude the pointer in the frame

It has no intrinsic size: without width and height it draws nothing. A hidden node or unmapped surface drops its capture and starts a fresh one when it shows again. A live capture gets a new frame only when the screen changes. A capture that fails pauses, with one warning, until the output list changes.

A region prefers wlr-screencopy, which crops at the source. Through ext-image-copy-capture-v1 the engine crops instead, and on a rotated or flipped output it cannot: it draws the whole output and logs one warning.

How do I…

TaskAnswer
Preview a monitorThe example above
Preview every monitorA list over mantle.screens, key = the screen’s name, one capture per item
Show a part of the screenregion = { x = 0, y = 0, width = 960, height = 540 }
Keep CPU lowLeave live = false for a still, or cap it: live = 10
Include the mouse pointerpaint_cursor = true
Round the cornersWrap it in a rect with radius and clip = "Rounded", as above

Gotchas

TrapFix
Nothing drawsGive it a size; check output against mantle.screens names; check mantle log for a missing-protocol warning
The preview is frozenlive is false, which captures once. Set true or a frame rate
live = 0 is refusedUse false for a single frame
A region shows the whole outputThe output is rotated or flipped and only ext-image-copy-capture-v1 is offered
region = { width = 100, height = 100 } is refusedAll four keys are required

See also: image, surfaces.

Source: vocabulary, content parsers, capture.