asdf-overlay-common 0.5.1

Asdf Overlay Ipc messages, client and server
Documentation
use core::{fmt::Debug, num::NonZeroUsize};

use bincode::{Decode, Encode};

use crate::{cursor::Cursor, key::Key, size::PercentLength};

#[derive(Debug, Encode, Decode, Clone)]
pub enum Request {
    SetPosition(SetPosition),
    SetAnchor(SetAnchor),
    SetMargin(SetMargin),
    GetSize(GetSize),
    SetInputCaptureKeybind(SetInputCaptureKeybind),
    SetCaptureCursor(SetCaptureCursor),
    UpdateSharedHandle(UpdateSharedHandle),
}

#[derive(Debug, Default, Encode, Decode, Clone, PartialEq)]
/// Set overlay position
pub struct SetPosition {
    pub x: PercentLength,
    pub y: PercentLength,
}

#[derive(Debug, Default, Encode, Decode, Clone, PartialEq)]
/// Set overlay anchor
pub struct SetAnchor {
    pub x: PercentLength,
    pub y: PercentLength,
}

#[derive(Debug, Default, Encode, Decode, Clone, PartialEq)]
/// Change overlay margin
pub struct SetMargin {
    pub top: PercentLength,
    pub right: PercentLength,
    pub bottom: PercentLength,
    pub left: PercentLength,
}

impl SetMargin {
    pub const fn xy(x: PercentLength, y: PercentLength) -> Self {
        Self {
            top: y,
            right: x,
            bottom: y,
            left: x,
        }
    }
}

#[derive(Debug, Default, Encode, Decode, Clone, PartialEq)]
/// Get size of overlay window
pub struct GetSize {
    pub hwnd: u32,
}

#[derive(Debug, Default, Encode, Decode, Clone, PartialEq)]
/// Set input capture keybind of a window
pub struct SetInputCaptureKeybind {
    pub hwnd: u32,

    // keyboard scan code each slot, up to 4 keys
    pub keybind: [Option<Key>; 4],
}

#[derive(Debug, Default, Encode, Decode, Clone, PartialEq)]
/// Set cursor of a window being input captured
pub struct SetCaptureCursor {
    pub hwnd: u32,
    pub cursor: Option<Cursor>,
}

#[derive(Debug, Encode, Decode, Clone, PartialEq)]
/// Update overlay to new texture using shared dx11 texture handle
pub struct UpdateSharedHandle {
    pub handle: Option<NonZeroUsize>,
}