Skip to main content

vst_audio_protocol/
editor.rs

1//! Framework-independent native editor operations. Unsupported native features
2//! return RequestError; no operation falls back to loading code in the parent.
3/// A native window of the application that an editor may live inside.
4#[derive(Clone, Copy, Debug, Eq, PartialEq)]
5pub enum ParentWindow {
6    /// An HWND of another process.
7    Win32 { hwnd: u64 },
8    /// An X11 window ID on the worker's display.
9    X11 { window: u64 },
10}
11
12#[derive(Clone, Debug, PartialEq)]
13pub enum EditorAction {
14    Show,
15    Hide,
16    Focus,
17    Resize { width: u32, height: u32 },
18    Scale(f32),
19    Inspect,
20    Capture,
21}
22/// How an editor is fitted to the display's scale when it opens.
23#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)]
24#[repr(u8)]
25#[non_exhaustive]
26pub enum EditorScaling {
27    /// The plugin scales itself when it can; otherwise the system stretches
28    /// it where the platform can (Windows), else it stays 1:1.
29    #[default]
30    Auto = 0,
31    /// Only the plugin scales; a plugin that cannot stays 1:1.
32    Plugin = 1,
33    /// The system stretches a 1:1 drawing (sharpness is lost). Supported by
34    /// Windows floating editors and, in a Wayland session with `DISPLAY`, by a
35    /// floating X11 editor that the desktop's XWayland scales. Embedded views,
36    /// plain X11 sessions and Wayland sessions without `DISPLAY` reject it.
37    Stretch = 2,
38    /// No scaling: the plugin is told nothing and draws 1:1 physical pixels.
39    Off = 3,
40}
41/// The backend actually hosting the editor, independent of the requested policy.
42#[derive(Clone, Copy, Debug, Eq, PartialEq)]
43#[repr(u8)]
44#[non_exhaustive]
45pub enum EditorPlatform {
46    Win32 = 0,
47    Cocoa = 1,
48    X11 = 2,
49    Wayland = 3,
50}
51#[derive(Clone, Debug, PartialEq)]
52pub struct EditorStatus {
53    pub platform: EditorPlatform,
54    pub scaling: EditorScaling,
55    pub visible: bool,
56    pub embedded: bool,
57    /// Client size in pixels, at most [`crate::MAX_EDITOR_EXTENT`]; 0 while the
58    /// window is minimized or unmapped.
59    pub width: u32,
60    pub height: u32,
61    pub scale: f32,
62    pub resize_supported: bool,
63    pub scale_supported: bool,
64}
65#[derive(Clone, Debug, Eq, PartialEq)]
66pub struct EditorImage {
67    pub width: u32,
68    pub height: u32,
69    pub rgba: Vec<u8>,
70}
71impl EditorImage {
72    pub fn valid(&self) -> bool {
73        self.width > 0
74            && self.height > 0
75            && self.width <= 2048
76            && self.height <= 2048
77            && self.rgba.len() == self.width as usize * self.height as usize * 4
78    }
79}
80#[derive(Debug)]
81pub enum EditorReply {
82    Status(EditorStatus),
83    Image(EditorImage),
84}