LMMS
Loading...
Searching...
No Matches
gui.h
Go to the documentation of this file.
1#pragma once
2
3#include "../plugin.h"
4
43
44static CLAP_CONSTEXPR const char CLAP_EXT_GUI[] = "clap.gui";
45
46// If your windowing API is not listed here, please open an issue and we'll figure it out.
47// https://github.com/free-audio/clap/issues/new
48
49// uses physical size
50// embed using https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setparent
51static const CLAP_CONSTEXPR char CLAP_WINDOW_API_WIN32[] = "win32";
52
53// uses logical size, don't call clap_plugin_gui->set_scale()
54static const CLAP_CONSTEXPR char CLAP_WINDOW_API_COCOA[] = "cocoa";
55
56// uses physical size
57// embed using https://specifications.freedesktop.org/xembed-spec/xembed-spec-latest.html
58static const CLAP_CONSTEXPR char CLAP_WINDOW_API_X11[] = "x11";
59
60// uses physical size
61// embed is currently not supported, use floating windows
62static const CLAP_CONSTEXPR char CLAP_WINDOW_API_WAYLAND[] = "wayland";
63
64#ifdef __cplusplus
65extern "C" {
66#endif
67
68typedef void *clap_hwnd;
69typedef void *clap_nsview;
70typedef unsigned long clap_xwnd;
71
72// Represent a window reference.
73typedef struct clap_window {
74 const char *api; // one of CLAP_WINDOW_API_XXX
75 union {
79 void *ptr; // for anything defined outside of clap
80 uintptr_t uptr;
81 };
83
84// Information to improve window resizing when initiated by the host or window manager.
94
95// Size (width, height) is in pixels; the corresponding windowing system extension is
96// responsible for defining if it is physical pixels or logical pixels.
97typedef struct clap_plugin_gui {
98 // Returns true if the requested gui api is supported
99 // [main-thread]
100 bool (CLAP_ABI *is_api_supported)(const clap_plugin_t *plugin, const char *api, bool is_floating);
101
102 // Returns true if the plugin has a preferred api.
103 // The host has no obligation to honor the plugin preferrence, this is just a hint.
104 // [main-thread]
105 bool (CLAP_ABI *get_preferred_api)(const clap_plugin_t *plugin, const char **api, bool *is_floating);
106
107 // Create and allocate all resources necessary for the gui.
108 //
109 // If is_floating is true, then the window will not be managed by the host. The plugin
110 // can set its window to stays above the parent window, see set_transient().
111 // api may be null or blank for floating window.
112 //
113 // If is_floating is false, then the plugin has to embbed its window into the parent window, see
114 // set_parent().
115 //
116 // After this call, the GUI may not be visible yet; don't forget to call show().
117 // [main-thread]
118 bool (CLAP_ABI *create)(const clap_plugin_t *plugin, const char *api, bool is_floating);
119
120 // Free all resources associated with the gui.
121 // [main-thread]
122 void (CLAP_ABI *destroy)(const clap_plugin_t *plugin);
123
124 // Set the absolute GUI scaling factor, and override any OS info.
125 // Should not be used if the windowing api relies upon logical pixels.
126 //
127 // If the plugin prefers to work out the scaling factor itself by querying the OS directly,
128 // then ignore the call.
129 //
130 // Returns true if the scaling could be applied
131 // Returns false if the call was ignored, or the scaling could not be applied.
132 // [main-thread]
133 bool (CLAP_ABI *set_scale)(const clap_plugin_t *plugin, double scale);
134
135 // Get the current size of the plugin UI.
136 // clap_plugin_gui->create() must have been called prior to asking the size.
137 // [main-thread]
138 bool (CLAP_ABI *get_size)(const clap_plugin_t *plugin, uint32_t *width, uint32_t *height);
139
140 // Returns true if the window is resizeable (mouse drag).
141 // Only for embedded windows.
142 // [main-thread]
143 bool (CLAP_ABI *can_resize)(const clap_plugin_t *plugin);
144
145 // Returns true if the plugin can provide hints on how to resize the window.
146 // [main-thread]
147 bool (CLAP_ABI *get_resize_hints)(const clap_plugin_t *plugin, clap_gui_resize_hints_t *hints);
148
149 // If the plugin gui is resizable, then the plugin will calculate the closest
150 // usable size which fits in the given size.
151 // This method does not change the size.
152 //
153 // Only for embedded windows.
154 // [main-thread]
155 bool (CLAP_ABI *adjust_size)(const clap_plugin_t *plugin, uint32_t *width, uint32_t *height);
156
157 // Sets the window size. Only for embedded windows.
158 // [main-thread]
160
161 // Embbeds the plugin window into the given window.
162 // [main-thread & !floating]
163 bool (CLAP_ABI *set_parent)(const clap_plugin_t *plugin, const clap_window_t *window);
164
165 // Set the plugin floating window to stay above the given window.
166 // [main-thread & floating]
167 bool (CLAP_ABI *set_transient)(const clap_plugin_t *plugin, const clap_window_t *window);
168
169 // Suggests a window title. Only for floating windows.
170 // [main-thread & floating]
171 void (CLAP_ABI *suggest_title)(const clap_plugin_t *plugin, const char *title);
172
173 // Show the window.
174 // [main-thread]
175 bool (CLAP_ABI *show)(const clap_plugin_t *plugin);
176
177 // Hide the window, this method does not free the resources, it just hides
178 // the window content. Yet it may be a good idea to stop painting timers.
179 // [main-thread]
180 bool (CLAP_ABI *hide)(const clap_plugin_t *plugin);
182
183typedef struct clap_host_gui {
184 // The host should call get_resize_hints() again.
185 // [thread-safe]
186 void (CLAP_ABI *resize_hints_changed)(const clap_host_t *host);
187
188 /* Request the host to resize the client area to width, height.
189 * Return true if the new size is accepted, false otherwise.
190 * The host doesn't have to call set_size().
191 *
192 * Note: if not called from the main thread, then a return value simply means that the host
193 * acknowledged the request and will process it asynchronously. If the request then can't be
194 * satisfied then the host will call set_size() to revert the operation.
195 *
196 * [thread-safe] */
197 bool (CLAP_ABI *request_resize)(const clap_host_t *host, uint32_t width, uint32_t height);
198
199 /* Request the host to show the plugin gui.
200 * Return true on success, false otherwise.
201 * [thread-safe] */
202 bool (CLAP_ABI *request_show)(const clap_host_t *host);
203
204 /* Request the host to hide the plugin gui.
205 * Return true on success, false otherwise.
206 * [thread-safe] */
207 bool (CLAP_ABI *request_hide)(const clap_host_t *host);
208
209 // The floating window has been closed, or the connection to the gui has been lost.
210 //
211 // If was_destroyed is true, then the host must call clap_plugin_gui->destroy() to acknowledge
212 // the gui destruction.
213 // [thread-safe]
214 void (CLAP_ABI *closed)(const clap_host_t *host, bool was_destroyed);
216
217#ifdef __cplusplus
218}
219#endif
struct clap_plugin_gui clap_plugin_gui_t
unsigned long clap_xwnd
Definition gui.h:70
void * clap_hwnd
Definition gui.h:68
static CLAP_CONSTEXPR const char CLAP_EXT_GUI[]
Definition gui.h:44
static const CLAP_CONSTEXPR char CLAP_WINDOW_API_WIN32[]
Definition gui.h:51
static const CLAP_CONSTEXPR char CLAP_WINDOW_API_WAYLAND[]
Definition gui.h:62
struct clap_gui_resize_hints clap_gui_resize_hints_t
struct clap_window clap_window_t
static const CLAP_CONSTEXPR char CLAP_WINDOW_API_X11[]
Definition gui.h:58
static const CLAP_CONSTEXPR char CLAP_WINDOW_API_COCOA[]
Definition gui.h:54
struct clap_host_gui clap_host_gui_t
void * clap_nsview
Definition gui.h:69
struct clap_host clap_host_t
#define CLAP_ABI
Definition macros.h:24
#define CLAP_CONSTEXPR
Definition macros.h:32
unsigned int uint32_t
Definition mid.cpp:100
struct clap_plugin clap_plugin_t
Definition gui.h:85
bool can_resize_horizontally
Definition gui.h:86
uint32_t aspect_ratio_height
Definition gui.h:92
uint32_t aspect_ratio_width
Definition gui.h:91
bool preserve_aspect_ratio
Definition gui.h:90
bool can_resize_vertically
Definition gui.h:87
Definition gui.h:183
bool(CLAP_ABI *request_hide)(const clap_host_t *host)
void(CLAP_ABI *closed)(const clap_host_t *host
bool(CLAP_ABI *request_show)(const clap_host_t *host)
uint32_t width
Definition gui.h:197
void(CLAP_ABI *resize_hints_changed)(const clap_host_t *host)
uint32_t uint32_t height
Definition gui.h:197
bool was_destroyed
Definition gui.h:214
bool(CLAP_ABI *request_resize)(const clap_host_t *host
Definition gui.h:97
uint32_t uint32_t * height
Definition gui.h:138
bool(CLAP_ABI *is_api_supported)(const clap_plugin_t *plugin
const char * api
Definition gui.h:100
bool(CLAP_ABI *set_transient)(const clap_plugin_t *plugin
bool(CLAP_ABI *show)(const clap_plugin_t *plugin)
bool(CLAP_ABI *set_size)(const clap_plugin_t *plugin
const char bool is_floating
Definition gui.h:100
bool(CLAP_ABI *hide)(const clap_plugin_t *plugin)
bool(CLAP_ABI *create)(const clap_plugin_t *plugin
bool(CLAP_ABI *can_resize)(const clap_plugin_t *plugin)
const clap_window_t * window
Definition gui.h:163
bool(CLAP_ABI *set_scale)(const clap_plugin_t *plugin
clap_gui_resize_hints_t * hints
Definition gui.h:147
double scale
Definition gui.h:133
bool(CLAP_ABI *get_resize_hints)(const clap_plugin_t *plugin
void(CLAP_ABI *destroy)(const clap_plugin_t *plugin)
uint32_t * width
Definition gui.h:138
bool(CLAP_ABI *adjust_size)(const clap_plugin_t *plugin
bool(CLAP_ABI *get_size)(const clap_plugin_t *plugin
bool(CLAP_ABI *set_parent)(const clap_plugin_t *plugin
const char * title
Definition gui.h:171
Definition gui.h:73
void * ptr
Definition gui.h:79
clap_xwnd x11
Definition gui.h:77
uintptr_t uptr
Definition gui.h:80
const char * api
Definition gui.h:74
clap_hwnd win32
Definition gui.h:78
clap_nsview cocoa
Definition gui.h:76
#define void
Definition unzip.h:396