ApplicationPrivateData.hpp (4140B)
1 /* 2 * DISTRHO Plugin Framework (DPF) 3 * Copyright (C) 2012-2021 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_PRIVATE_DATA_HPP_INCLUDED 18 #define DGL_APP_PRIVATE_DATA_HPP_INCLUDED 19 20 #include "../Application.hpp" 21 22 #include <list> 23 24 #ifdef DISTRHO_OS_WINDOWS 25 # ifndef NOMINMAX 26 # define NOMINMAX 27 # endif 28 # include <winsock2.h> 29 # include <windows.h> 30 typedef HANDLE d_ThreadHandle; 31 #else 32 # include <pthread.h> 33 typedef pthread_t d_ThreadHandle; 34 #endif 35 36 #ifdef DISTRHO_OS_MAC 37 typedef struct PuglWorldImpl PuglWorld; 38 #endif 39 40 START_NAMESPACE_DGL 41 42 class Window; 43 44 #ifndef DISTRHO_OS_MAC 45 typedef struct PuglWorldImpl PuglWorld; 46 #endif 47 48 // -------------------------------------------------------------------------------------------------------------------- 49 50 struct Application::PrivateData { 51 /** Pugl world instance. */ 52 PuglWorld* const world; 53 54 /** Whether the application is running as standalone, otherwise it is part of a plugin. */ 55 const bool isStandalone; 56 57 /** Whether the applicating is about to quit, or already stopped. Defaults to false. */ 58 bool isQuitting; 59 60 /** Helper for safely close everything from main thread. */ 61 bool isQuittingInNextCycle; 62 63 /** Whether the applicating is starting up, that is, no windows have been made visible yet. Defaults to true. */ 64 bool isStarting; 65 66 /** When true force all windows to be repainted on next idle. */ 67 bool needsRepaint; 68 69 /** Counter of visible windows, only used in standalone mode. 70 If 0->1, application is starting. If 1->0, application is quitting/stopping. */ 71 uint visibleWindows; 72 73 /** Handle that identifies the main thread. Used to check if calls belong to current thread or not. */ 74 d_ThreadHandle mainThreadHandle; 75 76 /** List of windows for this application. Only used during `close`. */ 77 std::list<DGL_NAMESPACE::Window*> windows; 78 79 /** List of idle callbacks for this application. */ 80 std::list<DGL_NAMESPACE::IdleCallback*> idleCallbacks; 81 82 /** Constructor and destructor */ 83 explicit PrivateData(bool standalone); 84 ~PrivateData(); 85 86 /** Flag one window as shown, which increments @a visibleWindows. 87 Sets @a isQuitting and @a isStarting as false if this is the first window. 88 For standalone mode only. */ 89 void oneWindowShown() noexcept; 90 91 /** Flag one window as closed, which decrements @a visibleWindows. 92 Sets @a isQuitting as true if this is the last window. 93 For standalone mode only. */ 94 void oneWindowClosed() noexcept; 95 96 /** Run Pugl world update for @a timeoutInMs, and then each idle callback in order of registration. */ 97 void idle(uint timeoutInMs); 98 99 /** Run each idle callback without updating pugl world. */ 100 void triggerIdleCallbacks(); 101 102 /** Trigger a repaint of all windows if @a needsRepaint is true. */ 103 void repaintIfNeeeded(); 104 105 /** Set flag indicating application is quitting, and close all windows in reverse order of registration. 106 For standalone mode only. */ 107 void quit(); 108 109 /** Get time via pugl */ 110 double getTime() const; 111 112 /** Set pugl world class name. */ 113 void setClassName(const char* name); 114 115 DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PrivateData) 116 }; 117 118 // -------------------------------------------------------------------------------------------------------------------- 119 120 END_NAMESPACE_DGL 121 122 #endif // DGL_APP_PRIVATE_DATA_HPP_INCLUDED