doe 1.1.90

doe is a powerful Rust crate designed to enhance development workflow by providing an extensive collection of useful macros and utility functions. It not only simplifies common tasks but also offers convenient features for clipboard management,robust cryptographic functions,keyboard input, and mouse interaction.
Documentation
//! Internal screen-capture abstraction layer.
//!
//! Replaces the external `screenshots` crate with per-platform implementations
//! built on top of dependencies the crate already pulls in (the `windows`
#![allow(dead_code, unreachable_pub)]
//! crate on Windows, `core-graphics` on macOS) plus a single lightweight `x11`
//! crate on Linux. This module is `pub(crate)` and is not part of the public
//! API; [`crate::screenshot`] exposes the user-facing functions.
//!
//! # Platform backends
//!
//! | Platform | Backend |
//! |----------|---------|
//! | Windows  | GDI (`EnumDisplayMonitors` + `GetDIBits`) |
//! | macOS    | CoreGraphics (`CGDisplay::screenshot`) |
//! | Linux    | X11 (`x11` crate, `XGetImage`) or Wayland (external tools) |

#[allow(warnings)]
mod image_utils;

#[cfg(target_os = "windows")]
mod windows;
#[cfg(target_os = "windows")]
use windows as backend;

#[cfg(target_os = "macos")]
mod macos;
#[cfg(target_os = "macos")]
use macos as backend;

#[cfg(target_os = "linux")]
mod linux_x11;
#[cfg(target_os = "linux")]
mod linux_wayland;

use image::RgbaImage;

/// Description of a single physical display, plus a way to capture it.
///
/// This mirrors the small surface of the `screenshots::Screen` API that
/// `doe::screenshot` actually relies on (`all()` + `capture()`).
#[derive(Debug, Clone)]
pub struct Screen {
    /// Platform-specific display identifier.
    pub id: u32,
    /// Horizontal offset of this display within the virtual desktop.
    pub x: i32,
    /// Vertical offset of this display within the virtual desktop.
    pub y: i32,
    /// Logical width in pixels.
    pub width: u32,
    /// Logical height in pixels.
    pub height: u32,
    /// DPI scale factor (1.0 when unknown / non-Retina).
    pub scale_factor: f32,
}

impl Screen {
    /// Enumerates every available display.
    ///
    /// On Linux the backend is chosen automatically: Wayland sessions fall
    /// back to external tools (`grim` / `gnome-screenshot` / `spectacle`),
    /// everything else uses the X11 backend.
    pub fn all() -> Result<Vec<Screen>, String> {
        #[cfg(target_os = "linux")]
        {
            if crate::screens::linux_wayland::is_wayland() {
                return crate::screens::linux_wayland::all();
            }
            return crate::screens::linux_x11::all();
        }
        #[cfg(not(target_os = "linux"))]
        {
            backend::all()
        }
    }

    /// Captures the whole display as an RGBA image.
    pub fn capture(&self) -> Result<RgbaImage, String> {
        #[cfg(target_os = "linux")]
        {
            if crate::screens::linux_wayland::is_wayland() {
                return crate::screens::linux_wayland::capture(self);
            }
            return crate::screens::linux_x11::capture(self);
        }
        #[cfg(not(target_os = "linux"))]
        {
            backend::capture(self)
        }
    }

    /// Captures a sub-rectangle of the display.
    pub fn capture_area(&self, x: i32, y: i32, width: u32, height: u32) -> Result<RgbaImage, String> {
        #[cfg(target_os = "linux")]
        {
            if crate::screens::linux_wayland::is_wayland() {
                return crate::screens::linux_wayland::capture_area(self, x, y, width, height);
            }
            return crate::screens::linux_x11::capture_area(self, x, y, width, height);
        }
        #[cfg(not(target_os = "linux"))]
        {
            backend::capture_area(self, x, y, width, height)
        }
    }
}