From cbb95d5855b97321370f11cd0f03279bc5d2acdb Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 30 Apr 2021 21:53:47 +0100 Subject: [PATCH] Wrap the entire pugl in a cpp file so we can namespace it Signed-off-by: falkTX --- dgl/Makefile | 3 +- dgl/src/ApplicationPrivateData.cpp | 15 ++++--- dgl/src/ApplicationPrivateData.hpp | 5 +-- dgl/src/pugl.cpp | 65 ++++++++++++++++++++++++++++++ dgl/src/pugl.hpp | 37 +++++++++++++++++ 5 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 dgl/src/pugl.cpp create mode 100644 dgl/src/pugl.hpp diff --git a/dgl/Makefile b/dgl/Makefile index 1aee6ebc..a76490a4 100644 --- a/dgl/Makefile +++ b/dgl/Makefile @@ -9,7 +9,8 @@ include ../Makefile.base.mk # --------------------------------------------------------------------------------------------------------------------- BUILD_C_FLAGS += $(DGL_FLAGS) -I. -Isrc -BUILD_CXX_FLAGS += $(DGL_FLAGS) -I. -Isrc -Isrc/pugl-upstream/include -DDONT_SET_USING_DGL_NAMESPACE -Wno-unused-parameter +BUILD_CXX_FLAGS += $(DGL_FLAGS) -I. -Isrc -DDONT_SET_USING_DGL_NAMESPACE -Wno-unused-parameter +# -Isrc/pugl-upstream/include LINK_FLAGS += $(DGL_LIBS) # TODO fix these after pugl-upstream is done diff --git a/dgl/src/ApplicationPrivateData.cpp b/dgl/src/ApplicationPrivateData.cpp index 24a48def..83bed9e2 100644 --- a/dgl/src/ApplicationPrivateData.cpp +++ b/dgl/src/ApplicationPrivateData.cpp @@ -17,7 +17,7 @@ #include "ApplicationPrivateData.hpp" #include "../Window.hpp" -#include "pugl-upstream/include/pugl/pugl.h" +#include "pugl.hpp" START_NAMESPACE_DGL @@ -27,10 +27,11 @@ Application::PrivateData::PrivateData(const bool standalone) : world(puglNewWorld(standalone ? PUGL_PROGRAM : PUGL_MODULE, standalone ? PUGL_WORLD_THREADS : 0x0)), isStandalone(standalone), - isStarting(true), isQuitting(false), visibleWindows(0), +#ifndef DPF_TEST_APPLICATION_CPP windows(), +#endif idleCallbacks() { DISTRHO_SAFE_ASSERT_RETURN(world != nullptr,); @@ -44,11 +45,12 @@ Application::PrivateData::PrivateData(const bool standalone) Application::PrivateData::~PrivateData() { - DISTRHO_SAFE_ASSERT(!isStarting); DISTRHO_SAFE_ASSERT(isQuitting); DISTRHO_SAFE_ASSERT(visibleWindows == 0); +#ifndef DPF_TEST_APPLICATION_CPP windows.clear(); +#endif idleCallbacks.clear(); if (world != nullptr) @@ -62,10 +64,7 @@ void Application::PrivateData::oneWindowShown() noexcept DISTRHO_SAFE_ASSERT_RETURN(isStandalone,); if (++visibleWindows == 1) - { - isStarting = false; isQuitting = false; - } } void Application::PrivateData::oneWindowHidden() noexcept @@ -81,11 +80,13 @@ void Application::PrivateData::idle(const uint timeoutInMs) { puglUpdate(world, timeoutInMs == 0 ? 0.0 : static_cast(timeoutInMs) / 1000.0); +#ifndef DPF_TEST_APPLICATION_CPP for (std::list::iterator it = windows.begin(), ite = windows.end(); it != ite; ++it) { Window* const window(*it); window->_idle(); } +#endif for (std::list::iterator it = idleCallbacks.begin(), ite = idleCallbacks.end(); it != ite; ++it) { @@ -98,11 +99,13 @@ void Application::PrivateData::quit() { isQuitting = true; +#ifndef DPF_TEST_APPLICATION_CPP for (std::list::reverse_iterator rit = windows.rbegin(), rite = windows.rend(); rit != rite; ++rit) { Window* const window(*rit); window->close(); } +#endif } // -------------------------------------------------------------------------------------------------------------------- diff --git a/dgl/src/ApplicationPrivateData.hpp b/dgl/src/ApplicationPrivateData.hpp index 3d6910d0..8aa858c0 100644 --- a/dgl/src/ApplicationPrivateData.hpp +++ b/dgl/src/ApplicationPrivateData.hpp @@ -36,9 +36,6 @@ struct Application::PrivateData { /** Whether the application is running as standalone, otherwise it is part of a plugin. */ const bool isStandalone; - /** Whether the applicating is starting up, not yet fully initialized. Defaults to true. */ - bool isStarting; - /** Whether the applicating is about to quit, or already stopped. Defaults to false. */ bool isQuitting; @@ -46,8 +43,10 @@ struct Application::PrivateData { If 0->1, application is starting. If 1->0, application is quitting/stopping. */ uint visibleWindows; +#ifndef DPF_TEST_APPLICATION_CPP /** List of windows for this application. Used as a way to call each window `idle`. */ std::list windows; +#endif /** List of idle callbacks for this application. Run after all windows `idle`. */ std::list idleCallbacks; diff --git a/dgl/src/pugl.cpp b/dgl/src/pugl.cpp new file mode 100644 index 00000000..a43e626c --- /dev/null +++ b/dgl/src/pugl.cpp @@ -0,0 +1,65 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2021 Filipe Coelho + * + * Permission to use, copy, modify, and/or distribute this software for any purpose with + * or without fee is hereby granted, provided that the above copyright notice and this + * permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#include "pugl.hpp" + +/* we will include all header files used in pugl in their C++ friendly form, then pugl stuff in custom namespace */ +#include +#include +#include +#include +#include + +#if defined(DISTRHO_OS_HAIKU) +#elif defined(DISTRHO_OS_MAC) +#elif defined(DISTRHO_OS_WINDOWS) +#else +# include +# include +# include +# include +# include +# include +# include +# ifdef HAVE_XRANDR +# include +# endif +# ifdef HAVE_XSYNC +# include +# include +# endif +# ifdef HAVE_XCURSOR +# include +# include +# endif +#endif + +START_NAMESPACE_DGL + +// -------------------------------------------------------------------------------------------------------------------- + +#if defined(DISTRHO_OS_HAIKU) +#elif defined(DISTRHO_OS_MAC) +#elif defined(DISTRHO_OS_WINDOWS) +#else +# include "pugl-upstream/src/x11.c" +#endif + +#include "pugl-upstream/src/implementation.c" + +// -------------------------------------------------------------------------------------------------------------------- + +END_NAMESPACE_DGL diff --git a/dgl/src/pugl.hpp b/dgl/src/pugl.hpp new file mode 100644 index 00000000..1fb58a34 --- /dev/null +++ b/dgl/src/pugl.hpp @@ -0,0 +1,37 @@ +/* + * DISTRHO Plugin Framework (DPF) + * Copyright (C) 2012-2021 Filipe Coelho + * + * Permission to use, copy, modify, and/or distribute this software for any purpose with + * or without fee is hereby granted, provided that the above copyright notice and this + * permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD + * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL + * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER + * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN + * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +#ifndef DGL_PUGL_HPP_INCLUDED +#define DGL_PUGL_HPP_INCLUDED + +#include "../Base.hpp" + +/* we will include all header files used in pugl in their C++ friendly form, then pugl stuff in custom namespace */ +#include +#include +#include + +START_NAMESPACE_DGL + +// -------------------------------------------------------------------------------------------------------------------- + +#include "pugl-upstream/include/pugl/pugl.h" + +// -------------------------------------------------------------------------------------------------------------------- + +END_NAMESPACE_DGL + +#endif // DGL_PUGL_HPP_INCLUDED