$ show nashaofu/xcap
XCap is a cross-platform screen capture library written in Rust, supporting Linux (X11, Wayland), macOS, Windows, and HarmonyOS (OHOS). It provides a unified API for capturing images of monitors and windows, as well as video recording (currently work-in-progress). The library abstracts platform-specific implementations behind common `Monitor`, `Window`, and `VideoRecorder` structs, using native APIs such as XCB, PipeWire, CoreGraphics, AVFoundation, GDI, Windows Graphics Capture, and OHOS PixelMap. It is well-structured with clean error handling and modular platform modules, though some features like Wayland capture and window recording are still incomplete. The codebase demonstrates solid Rust engineering practices and is actively maintained.
The LLM identified 2 files worth highlighting for reuse:
Defines `XCapError` using `thiserror` with variants for each supported platform (Linux, macOS, Windows, OHOS) and common errors like `NotSupported` and `InvalidCaptureRegion`. It provides a clean, extensible error type that can be reused in any Rust project requiring platform-specific error handling, and demonstrates idiomatic use of `thiserror` with conditional compilation.
Provides the `Frame` struct (width, height, raw pixel data) and `RecorderWaker` (a parking/condvar-based synchronization primitive for pausing/resuming frame capture). The `VideoRecorder` struct wraps platform-specific implementations. The `Frame` type is a simple, reusable data container for video frames, and the `RecorderWaker` pattern can be extracted for any producer-consumer scenario requiring controlled start/stop.