Dusk Audio Framework
Loading...
Searching...
No Matches
Application.hpp
1/*
2 * DISTRHO Plugin Framework (DPF)
3 * Copyright (C) 2012-2025 Filipe Coelho <falktx@falktx.com>
4 *
5 * Permission to use, copy, modify, and/or distribute this software for any purpose with
6 * or without fee is hereby granted, provided that the above copyright notice and this
7 * permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
10 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
11 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
12 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
13 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
14 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
15 */
16
17#ifndef DGL_APP_HPP_INCLUDED
18#define DGL_APP_HPP_INCLUDED
19
20#include "Base.hpp"
21
22#ifdef DAF_NAMESPACE
24class PluginApplication;
26#endif
27
28START_NAMESPACE_DGL
29
30// --------------------------------------------------------------------------------------------------------------------
31// build config sentinels
32
33/**
34 This set of static variables act as a build sentinel that detects a configuration error.
35
36 Usually this means the way DGL was built and how it is being used and linked into your program is different,
37 we want to avoid such combinations as memory layout would then also be different
38 leading to all sort of subtle but very nasty memory corruption issues.
39
40 Make sure the flags used to build DGL match the ones used by your program and the link errors should go away.
41 */
42#define BUILD_CONFIG_SENTINEL(NAME) \
43 static struct DAF_JOIN_MACRO(_, NAME) { bool ok; DAF_JOIN_MACRO(_, NAME)() noexcept; } NAME;
44
45#ifdef DAF_DEBUG
46BUILD_CONFIG_SENTINEL(fail_to_link_is_mismatch_daf_debug_on)
47#else
48BUILD_CONFIG_SENTINEL(fail_to_link_is_mismatch_daf_debug_off)
49#endif
50
51#ifdef DGL_USE_FILE_BROWSER
52BUILD_CONFIG_SENTINEL(fail_to_link_is_mismatch_dgl_use_file_browser_on)
53#else
54BUILD_CONFIG_SENTINEL(fail_to_link_is_mismatch_dgl_use_file_browser_off)
55#endif
56
57#ifdef DGL_USE_WEB_VIEW
58BUILD_CONFIG_SENTINEL(fail_to_link_is_mismatch_dgl_use_web_view_on)
59#else
60BUILD_CONFIG_SENTINEL(fail_to_link_is_mismatch_dgl_use_web_view_off)
61#endif
62
63#ifdef DGL_NO_SHARED_RESOURCES
64BUILD_CONFIG_SENTINEL(fail_to_link_is_mismatch_dgl_no_shared_resources_on)
65#else
66BUILD_CONFIG_SENTINEL(fail_to_link_is_mismatch_dgl_no_shared_resources_off)
67#endif
68
69#ifdef DGL_RUNTIME_BACKEND
70BUILD_CONFIG_SENTINEL(fail_to_link_is_mismatch_dgl_runtime_backend_on)
71#else
72BUILD_CONFIG_SENTINEL(fail_to_link_is_mismatch_dgl_runtime_backend_off)
73#endif
74
75#undef BUILD_CONFIG_SENTINEL
76
77// --------------------------------------------------------------------------------------------------------------------
78
79/**
80 Base DGL Application class.
81
82 One application instance is required for creating a window.
83 There's no single/global application instance in DGL, and multiple windows can share the same app instance.
84
85 In standalone mode an application will automatically quit its event-loop when all its windows are closed.
86
87 Unless stated otherwise, functions within this class are not thread-safe.
88 */
89class DAF_API Application
90{
91public:
92 /**
93 Type of application to setup, either "classic" or "modern".
94
95 What this means depends on the OS.
96 */
97 enum Type {
98 kTypeAuto,
99 kTypeClassic,
100 kTypeModern,
101 };
102
103 /**
104 Windowing system to open the application's windows on.
105
106 Only Linux and the other X11/Wayland systems have one to choose. A DGL_BACKEND=both build picks X11 or
107 Wayland at runtime, by the rule in dgl/src/runtime-backend.md, unless the application asks for one.
108 The request is final: if that system cannot be used, or the build does not have it, no window opens
109 and a message says why, rather than the application ending up on the other one.
110 It takes the place of the DAF_WINDOW_BACKEND environment variable.
111
112 On macOS, Windows and the other platforms with a single windowing system the request is ignored.
113 */
115 kWindowSystemAuto,
116 kWindowSystemX11,
117 kWindowSystemWayland,
118 };
119
120 /**
121 Constructor for standalone or plugin application.
122 */
123 Application(bool isStandalone = true, Type type = kTypeAuto, WindowSystem windowSystem = kWindowSystemAuto);
124
125 /**
126 Constructor for a standalone application.
127 This specific constructor is required if using web views in standalone applications.
128 On Linux a web view needs X11, see WindowSystem.
129 */
130 Application(int argc, char* argv[], WindowSystem windowSystem = kWindowSystemAuto);
131
132 /**
133 Destructor.
134 */
135 virtual ~Application();
136
137 /**
138 Idle function.
139 This runs the application event-loop once.
140 */
141 void idle();
142
143 /**
144 Run the application event-loop until all Windows are closed.
145 idle() is called at regular intervals.
146 @note This function is meant for standalones only, *never* call this from plugins.
147 */
148 void exec(uint idleTimeInMs = 30);
149
150 /**
151 Quit the application.
152 This stops the event-loop and closes all Windows.
153 This function is thread-safe.
154 */
155 void quit();
156
157 /**
158 Check if the application is about to quit.
159 Returning true means there's no event-loop running at the moment (or it's just about to stop).
160 This function is thread-safe.
161 */
162 bool isQuitting() const noexcept;
163
164 /**
165 Check if the application is standalone, otherwise running as a module or plugin.
166 This function is thread-safe.
167 */
168 bool isStandalone() const noexcept;
169
170 /**
171 Return the time in seconds.
172
173 This is a monotonically increasing clock with high resolution.@n
174 The returned time is only useful to compare against other times returned by this function,
175 its absolute value has no meaning.
176 */
177 double getTime() const;
178
179 /**
180 Return the application type, either kTypeClassic or kTypeModern.
181 This function never return kTypeAuto.
182 */
183 Type getType() const noexcept;
184
185 /**
186 Return the windowing system the application's windows open on, kWindowSystemX11 or kWindowSystemWayland.
187 Returns kWindowSystemAuto where the platform has no choice of one, and when none could be opened.
188 */
190
191 /**
192 Add a callback function to be triggered on every idle cycle.
193 You can add more than one, and remove them at anytime with removeIdleCallback().
194 Idle callbacks trigger right after OS event handling and Window idle events (within the same cycle).
195 There are no guarantees in terms of timing, use Window::addIdleCallback for time-relative callbacks.
196 Registrations added during dispatch start on the next idle call. Removing a registration
197 cancels its pending call immediately; nested idle calls do not re-enter an active registration.
198 */
200
201 /**
202 Remove an idle callback previously added via addIdleCallback().
203 */
205
206 /**
207 Get the class name of the application.
208
209 This is a stable identifier for the application, used as the window class/instance name on X11 and Windows.
210 It is not displayed to the user, but can be used in scripts and by window managers,
211 so it should be the same for every instance of the application, but different from other applications.
212
213 Plugins created with DAF have their class name automatically set based on DGL_NAMESPACE and plugin name.
214 */
215 const char* getClassName() const noexcept;
216
217 /**
218 Set the class name of the application.
219 @see getClassName
220 */
221 void setClassName(const char* name);
222
223private:
224 struct PrivateData;
225 PrivateData* const pData;
226 friend class Window;
227 #ifdef DAF_NAMESPACE
228 friend class DAF_NAMESPACE::PluginApplication;
229 #endif
230
231 DAF_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(Application)
232};
233
234// --------------------------------------------------------------------------------------------------------------------
235
236END_NAMESPACE_DGL
237
238#endif // DGL_APP_HPP_INCLUDED
void removeIdleCallback(IdleCallback *callback)
void setClassName(const char *name)
virtual ~Application()
double getTime() const
WindowSystem getWindowSystem() const noexcept
const char * getClassName() const noexcept
void exec(uint idleTimeInMs=30)
bool isStandalone() const noexcept
WindowSystem
Definition Application.hpp:114
bool isQuitting() const noexcept
Application(bool isStandalone=true, Type type=kTypeAuto, WindowSystem windowSystem=kWindowSystemAuto)
Type getType() const noexcept
Type
Definition Application.hpp:97
void addIdleCallback(IdleCallback *callback)
Application(int argc, char *argv[], WindowSystem windowSystem=kWindowSystemAuto)
#define END_NAMESPACE_DAF
Definition DafInfo.hpp:996
#define START_NAMESPACE_DAF
Definition DafInfo.hpp:990
Definition Base.hpp:293