sip 0.3.0

Interactive Wayland screen-region selector with slurp-compatible output
Documentation
//! Wayland region selection for Rust applications.
//!
//! ```no_run
//! let selection = sip::select_region(sip::SelectOptions::default())?;
//! println!("{},{} {}x{}", selection.rect.x, selection.rect.y,
//!          selection.rect.width, selection.rect.height);
//! # Ok::<(), sip::Error>(())
//! ```

mod app;
mod color;
mod error;
mod font;
mod freeze;
mod geometry;
mod lock;
mod render;

pub use color::{Color, ParseColorError};
pub use error::Error;
pub use geometry::Rect;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct ChoiceBox {
    pub rect: Rect,
    pub label: Option<String>,
    pub id: Option<String>,
}

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Selection {
    pub rect: Rect,
    pub label: Option<String>,
    pub output: Option<String>,
    pub output_geometry: Option<Rect>,
}

#[derive(Debug, Clone)]
pub struct SelectOptions {
    pub background: Color,
    pub border: Color,
    pub selection: Color,
    pub choice: Color,
    pub border_weight: f32,
    pub font_family: Option<String>,
    pub display_dimensions: bool,
    pub single_point: bool,
    pub restrict: bool,
    pub crosshairs: bool,
    pub aspect_ratio: Option<(u32, u32)>,
    pub all_outputs: bool,
    /// Keep the screen contents from the start of selection visible.
    pub freeze: bool,
}

impl Default for SelectOptions {
    fn default() -> Self {
        Self {
            background: Color::from_rgba_u32(0xFFFFFF40),
            border: Color::from_rgba_u32(0x000000FF),
            selection: Color::from_rgba_u32(0x00000000),
            choice: Color::from_rgba_u32(0xFFFFFF40),
            border_weight: 2.0,
            font_family: None,
            display_dimensions: false,
            single_point: false,
            restrict: false,
            crosshairs: false,
            aspect_ratio: None,
            all_outputs: false,
            freeze: false,
        }
    }
}

/// Prompt for a free-form region selection.
pub fn select_region(options: SelectOptions) -> Result<Selection, Error> {
    app::run(Vec::new(), options)
}

/// Prompt for a selection with predefined choice boxes available.
///
/// With [`SelectOptions::restrict`] set, the user must pick one of `boxes`;
/// otherwise they may still drag a free region.
pub fn select_from_boxes(
    boxes: Vec<ChoiceBox>,
    options: SelectOptions,
) -> Result<Selection, Error> {
    app::run(boxes, options)
}