Skip to main content

Crate latchshot

Crate latchshot 

Source
Expand description

Latchshot is a lightweight yet intelligent window-aware screenshot tool.

Latchshot keeps scene discovery, frame capture, interactive selection, and image output as separate steps. Applications can use the complete built-in flow or replace individual steps through SceneReader, FrameCapture, and Selector.

§Interactive screenshot

Capture the desktop before opening the overlay so the selection is made against a frozen frame. The frame returned by overlay::select is the same frame to which the selected logical geometry refers.

use anyhow::Result;
use latchshot::output::Target;
use latchshot::overlay::select;
use latchshot::{Compositor, FrameCapture, Selection, SelectionResult, WaylandCapture};

fn main() -> Result<()> {
    let compositor = Compositor::detect().unwrap_or(Compositor::Generic);
    let mut compositor = compositor.connect()?;
    let mut scene = compositor.scene()?;

    let mut capture = WaylandCapture::connect()?;
    let frame = capture.capture(&scene)?;
    compositor.refine_scene(&mut scene, &frame)?;

    let (result, frame) = select(scene, frame, true)?;
    let selection = match result {
        SelectionResult::Selected(selection) => selection,
        SelectionResult::Cancelled => return Ok(()),
    };
    let region = match selection {
        Selection::Window(region) | Selection::Region(region) => region,
    };

    Target::File("screenshot.png".into()).write(&frame.crop(region))?;
    Ok(())
}

For a custom frontend, drive Selector with pointer events and use DesktopFrame::crop once it returns a SelectionResult.

Re-exports§

pub use animation::AnimatedRect;
pub use capture::DesktopFrame;
pub use capture::FrameCapture;
pub use capture::OutputFrame;
pub use capture::WaylandCapture;
pub use compositor::Compositor;
pub use compositor::SceneReader;
pub use geometry::Point;
pub use geometry::Rect;
pub use geometry::Size;
pub use scene::Output;
pub use scene::OutputId;
pub use scene::OutputTransform;
pub use scene::Scene;
pub use scene::Window;
pub use selection::Selection;
pub use selection::SelectionResult;
pub use selection::Selector;

Modules§

animation
capture
Desktop frame capture and logical-coordinate cropping.
compositor
Compositor discovery and scene snapshots.
geometry
output
PNG encoding and output destinations for captured images.
overlay
The built-in interactive Wayland selection overlay.
scene
selection
UI-independent window and region selection.