clap_sys/ext/
gui.rs

1use crate::{cstr, host::*, plugin::*};
2
3use std::ffi::{c_char, c_ulong, c_void, CStr};
4use std::fmt::Debug;
5
6pub const CLAP_EXT_GUI: &CStr = cstr!("clap.gui");
7
8pub const CLAP_WINDOW_API_WIN32: &CStr = cstr!("win32");
9pub const CLAP_WINDOW_API_COCOA: &CStr = cstr!("cocoa");
10pub const CLAP_WINDOW_API_X11: &CStr = cstr!("x11");
11pub const CLAP_WINDOW_API_WAYLAND: &CStr = cstr!("wayland");
12
13pub type clap_hwnd = *mut c_void;
14pub type clap_nsview = *mut c_void;
15pub type clap_xwnd = c_ulong;
16
17#[repr(C)]
18#[derive(Debug, Copy, Clone)]
19pub struct clap_window {
20    pub api: *const c_char,
21    pub specific: clap_window_handle,
22}
23
24unsafe impl Send for clap_window {}
25unsafe impl Sync for clap_window {}
26
27/// Defined as an anonymous union in [`clap_window`] in the C-version.
28#[repr(C)]
29#[derive(Copy, Clone)]
30pub union clap_window_handle {
31    pub cocoa: clap_nsview,
32    pub x11: clap_xwnd,
33    pub win32: clap_hwnd,
34    pub ptr: *mut c_void,
35}
36
37unsafe impl Send for clap_window_handle {}
38unsafe impl Sync for clap_window_handle {}
39
40#[repr(C)]
41#[derive(Debug, Copy, Clone)]
42pub struct clap_gui_resize_hints {
43    pub can_resize_horizontally: bool,
44    pub can_resize_vertically: bool,
45    pub preserve_aspect_ratio: bool,
46    pub aspect_ratio_width: u32,
47    pub aspect_ratio_height: u32,
48}
49
50#[repr(C)]
51#[derive(Debug, Copy, Clone)]
52pub struct clap_plugin_gui {
53    pub is_api_supported: Option<
54        unsafe extern "C" fn(
55            plugin: *const clap_plugin,
56            api: *const c_char,
57            is_floating: bool,
58        ) -> bool,
59    >,
60    pub get_preferred_api: Option<
61        unsafe extern "C" fn(
62            plugin: *const clap_plugin,
63            api: *mut *const c_char,
64            is_floating: *mut bool,
65        ) -> bool,
66    >,
67    pub create: Option<
68        unsafe extern "C" fn(
69            plugin: *const clap_plugin,
70            api: *const c_char,
71            is_floating: bool,
72        ) -> bool,
73    >,
74    pub destroy: Option<unsafe extern "C" fn(plugin: *const clap_plugin)>,
75    pub set_scale: Option<unsafe extern "C" fn(plugin: *const clap_plugin, scale: f64) -> bool>,
76    pub get_size: Option<
77        unsafe extern "C" fn(plugin: *const clap_plugin, width: *mut u32, height: *mut u32) -> bool,
78    >,
79    pub can_resize: Option<unsafe extern "C" fn(plugin: *const clap_plugin) -> bool>,
80    pub get_resize_hints: Option<
81        unsafe extern "C" fn(plugin: *const clap_plugin, hints: *mut clap_gui_resize_hints) -> bool,
82    >,
83    pub adjust_size: Option<
84        unsafe extern "C" fn(plugin: *const clap_plugin, width: *mut u32, height: *mut u32) -> bool,
85    >,
86    pub set_size:
87        Option<unsafe extern "C" fn(plugin: *const clap_plugin, width: u32, height: u32) -> bool>,
88    pub set_parent: Option<
89        unsafe extern "C" fn(plugin: *const clap_plugin, window: *const clap_window) -> bool,
90    >,
91    pub set_transient: Option<
92        unsafe extern "C" fn(plugin: *const clap_plugin, window: *const clap_window) -> bool,
93    >,
94    pub suggest_title:
95        Option<unsafe extern "C" fn(plugin: *const clap_plugin, title: *const c_char)>,
96    pub show: Option<unsafe extern "C" fn(plugin: *const clap_plugin) -> bool>,
97    pub hide: Option<unsafe extern "C" fn(plugin: *const clap_plugin) -> bool>,
98}
99
100#[repr(C)]
101#[derive(Debug, Copy, Clone)]
102pub struct clap_host_gui {
103    pub resize_hints_changed: Option<unsafe extern "C" fn(host: *const clap_host)>,
104    pub request_resize:
105        Option<unsafe extern "C" fn(host: *const clap_host, width: u32, height: u32) -> bool>,
106    pub request_show: Option<unsafe extern "C" fn(host: *const clap_host) -> bool>,
107    pub request_hide: Option<unsafe extern "C" fn(host: *const clap_host) -> bool>,
108    pub closed: Option<unsafe extern "C" fn(host: *const clap_host, was_destroyed: bool)>,
109}
110
111impl Debug for clap_window_handle {
112    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
113        // We can't know which variant this actually is without supposed to be without checking the
114        // `api` field in `clap_window`, but that cannot be done safely
115        f.debug_struct("clap_window_handle").finish_non_exhaustive()
116    }
117}