Skip to main content

miracle_plugin/
host.rs

1unsafe extern "C" {
2    /// Retrieve the application info for a given window.
3    /// Returns the internal ID on success, or -1 if the buffer is too small.
4    pub fn miracle_window_info_get_application(
5        window_info_internal: i64,
6        name_buf_ptr: i32,
7        name_buf_len: i32,
8    ) -> i64;
9
10    /// Retrieve the workspace that a window is on.
11    pub fn miracle_window_info_get_workspace(
12        window_info_internal: i64,
13        out_ptr: i32,
14        name_buf: i32,
15        name_buf_len: i32,
16    ) -> i32;
17
18    /// Retrieve the output that a workspace is on.
19    pub fn miracle_workspace_get_output(
20        workspace_internal: i64,
21        out_ptr: i32,
22        name_buf: i32,
23        name_buf_len: i32,
24    ) -> i32;
25
26    /// Retrieve the number of outputs.
27    pub fn miracle_num_outputs() -> u32;
28
29    /// Retrieve an output by index.
30    pub fn miracle_get_output_at(index: u32, out_ptr: i32, name_buf: i32, name_buf_len: i32)
31    -> i32;
32
33    /// Retrieve a tree from a workspace by index.
34    pub fn miracle_workspace_get_tree(workspace_internal: i64, index: u32, out_ptr: i32) -> i32;
35
36    /// Retrieve a child container from a parent container by index.
37    pub fn miracle_container_get_child_at(container_internal: i64, index: u32, out_ptr: i32)
38    -> i32;
39
40    /// Retrieve the window info from a window container.
41    pub fn miracle_container_get_window(
42        container_internal: i64,
43        out_ptr: i32,
44        name_buf: i32,
45        name_buf_len: i32,
46    ) -> i32;
47
48    /// Retrieve the workspace on the output by index.
49    pub unsafe fn miracle_output_get_workspace(
50        output_internal: i64,
51        index: u32,
52        out_ptr: i32,
53        name_buf: i32,
54        name_buf_len: i32,
55    ) -> i32;
56
57    /// Retrieve the currently active workspace on the focused output.
58    pub fn miracle_get_active_workspace(out_ptr: i32, name_buf: i32, name_buf_len: i32) -> i32;
59
60    /// Retrieve the number of windows managed by the given plugin handle.
61    pub fn miracle_num_managed_windows(plugin_handle: u32) -> u32;
62
63    /// Retrieve a managed window by index.
64    /// Returns 0 on success, non-zero on failure.
65    pub fn miracle_get_managed_window_at(
66        plugin_handle: u32,
67        index: u32,
68        out_ptr: i32,
69        name_buf: i32,
70        name_buf_len: i32,
71    ) -> i32;
72
73    /// Set the state of a managed window.
74    /// Returns 0 on success, -1 on error.
75    pub fn miracle_window_set_state(window_internal: i64, state: i32) -> i32;
76
77    /// Move a managed window to a different workspace.
78    /// Returns 0 on success, -1 on error.
79    pub fn miracle_window_set_workspace(window_internal: i64, workspace_internal: i64) -> i32;
80
81    /// Set the position and size of a managed window.
82    /// Returns 0 on success, -1 on error.
83    pub fn miracle_window_set_rectangle(
84        window_internal: i64,
85        x: i32,
86        y: i32,
87        width: i32,
88        height: i32,
89        animate: i32,
90    ) -> i32;
91
92    /// Set the 4x4 column-major transform matrix of a managed window.
93    /// `transform_ptr` is a WASM linear memory offset pointing to 16 contiguous f32 values.
94    /// Returns 0 on success, -1 on error.
95    pub fn miracle_window_set_transform(window_internal: i64, transform_ptr: i32) -> i32;
96
97    /// Set the alpha (opacity) of a managed window.
98    /// `alpha_ptr` is a WASM linear memory offset pointing to a single f32 value.
99    /// Returns 0 on success, -1 on error.
100    pub fn miracle_window_set_alpha(window_internal: i64, alpha_ptr: i32) -> i32;
101
102    /// Request keyboard focus on a managed window.
103    /// Returns 0 on success, -1 on error.
104    pub fn miracle_window_request_focus(window_internal: i64) -> i32;
105
106    /// Request a workspace by optional number and/or name.
107    ///
108    /// If a workspace with the given number or name already exists, it is returned.
109    /// Otherwise, a new workspace is created on the focused output.
110    pub fn miracle_request_workspace(
111        has_number: i32,
112        number: i32,
113        name_in_ptr: i32,
114        name_in_len: i32,
115        out_workspace_ptr: i32,
116        out_name_buf_ptr: i32,
117        out_name_buf_len: i32,
118        focus: i32,
119    ) -> i32;
120
121    /// Retrieve the JSON-encoded userdata configured for this plugin.
122    ///
123    /// Returns the number of bytes written on success (>0), 0 if no userdata is
124    /// configured, or -1 if the provided buffer is too small.
125    pub fn miracle_get_plugin_userdata(handle: u32, buf_ptr: i32, buf_len: i32) -> i32;
126
127    /// Queue a custom per-frame animation.
128    ///
129    /// The compositor will call the plugin's `custom_animate` WASM export each frame
130    /// until the plugin returns 1 (complete). The plugin is responsible for all visual
131    /// side effects via the existing host functions.
132    ///
133    /// `plugin_handle` should be the value from `miracle_get_plugin_handle()`.
134    /// `out_animation_id_ptr` is a WASM memory offset where the host will write the
135    /// generated unique animation ID as a `uint32_t`.
136    ///
137    /// Returns 0 on success, -1 on error.
138    pub fn miracle_queue_custom_animation(
139        plugin_handle: i32,
140        out_animation_id_ptr: i32,
141        duration_seconds_ptr: i32,
142    ) -> i32;
143}