diff --git a/dgl/Application.hpp b/dgl/Application.hpp index 2c166b8e..3bac2f8a 100644 --- a/dgl/Application.hpp +++ b/dgl/Application.hpp @@ -84,6 +84,17 @@ public: */ void removeIdleCallback(IdleCallback* callback); + /** + Set the class name of the application. + + This is a stable identifier for the application, used as the window class/instance name on X11 and Windows. + It is not displayed to the user, but can be used in scripts and by window managers, + so it should be the same for every instance of the application, but different from other applications. + + Plugins created with DPF have their class name automatically set based on DGL_NAMESPACE and plugin name. + */ + void setClassName(const char* name); + private: struct PrivateData; PrivateData* const pData; diff --git a/dgl/src/Application.cpp b/dgl/src/Application.cpp index cd6e8a34..80d5957c 100644 --- a/dgl/src/Application.cpp +++ b/dgl/src/Application.cpp @@ -67,6 +67,11 @@ void Application::removeIdleCallback(IdleCallback* const callback) pData->idleCallbacks.remove(callback); } +void Application::setClassName(const char* const name) +{ + pData->setClassName(name); +} + // -------------------------------------------------------------------------------------------------------------------- END_NAMESPACE_DGL diff --git a/dgl/src/ApplicationPrivateData.cpp b/dgl/src/ApplicationPrivateData.cpp index 07cb21fb..409085b2 100644 --- a/dgl/src/ApplicationPrivateData.cpp +++ b/dgl/src/ApplicationPrivateData.cpp @@ -41,18 +41,7 @@ Application::PrivateData::PrivateData(const bool standalone) DISTRHO_SAFE_ASSERT_RETURN(world != nullptr,); puglSetWorldHandle(world, this); - - // FIXME - static int wc_count = 0; - char classNameBuf[256]; - std::srand((std::time(NULL))); - std::snprintf(classNameBuf, sizeof(classNameBuf), "%s_%d-%d-%p", - "TESTING", std::rand(), ++wc_count, this); - // DISTRHO_MACRO_AS_STRING(DGL_NAMESPACE) - classNameBuf[sizeof(classNameBuf)-1] = '\0'; - d_stderr("--------------------------------------------------------------- className is %s", classNameBuf); - - puglSetClassName(world, classNameBuf); + puglSetClassName(world, DISTRHO_MACRO_AS_STRING(DGL_NAMESPACE)); #ifdef HAVE_X11 sofdFileDialogSetup(world); #endif @@ -136,6 +125,13 @@ void Application::PrivateData::quit() #endif } +void Application::PrivateData::setClassName(const char* const name) +{ + DISTRHO_SAFE_ASSERT_RETURN(name != nullptr && name[0] != '\0',); + + puglSetClassName(world, name); +} + // -------------------------------------------------------------------------------------------------------------------- END_NAMESPACE_DGL diff --git a/dgl/src/ApplicationPrivateData.hpp b/dgl/src/ApplicationPrivateData.hpp index 4841c969..627f2a1f 100644 --- a/dgl/src/ApplicationPrivateData.hpp +++ b/dgl/src/ApplicationPrivateData.hpp @@ -76,6 +76,9 @@ struct Application::PrivateData { For standalone mode only. */ void quit(); + /** Set pugl world class name. */ + void setClassName(const char* name); + DISTRHO_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PrivateData) }; diff --git a/distrho/src/DistrhoUIInternal.hpp b/distrho/src/DistrhoUIInternal.hpp index d628c619..21a0625e 100644 --- a/distrho/src/DistrhoUIInternal.hpp +++ b/distrho/src/DistrhoUIInternal.hpp @@ -1,6 +1,6 @@ /* * DISTRHO Plugin Framework (DPF) - * Copyright (C) 2012-2020 Filipe Coelho + * 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 @@ -53,14 +53,35 @@ UI* createUiWrapper(void* dspPtr, uintptr_t winId, double scaleFactor, const cha UI* createUiWrapper(void* dspPtr, Window* window); #endif +#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI +// ----------------------------------------------------------------------- +// Plugin Application, will set class name based on plugin details + +class PluginApplication : public Application +{ +public: + PluginApplication() + : Application(DISTRHO_UI_IS_STANDALONE) + { + const char* const className = ( +#ifdef DISTRHO_PLUGIN_BRAND + DISTRHO_PLUGIN_BRAND +#else + DISTRHO_MACRO_AS_STRING(DISTRHO_NAMESPACE) +#endif + "-" DISTRHO_PLUGIN_NAME + ); + setClassName(className); + } +}; + // ----------------------------------------------------------------------- // Plugin Window, needed to take care of resize properly -#if !DISTRHO_PLUGIN_HAS_EXTERNAL_UI class UIExporterWindow : public Window { public: - UIExporterWindow(Application& app, const intptr_t winId, const double scaleFactor, void* const dspPtr) + UIExporterWindow(PluginApplication& app, const intptr_t winId, const double scaleFactor, void* const dspPtr) : Window(app, winId, scaleFactor, DISTRHO_UI_USER_RESIZABLE), fUI(createUiWrapper(dspPtr, this)), fIsReady(false) @@ -143,7 +164,7 @@ public: #if DISTRHO_PLUGIN_HAS_EXTERNAL_UI : fUI(createUiWrapper(dspPtr, winId, scaleFactor, bundlePath)), #else - : glApp(DISTRHO_UI_IS_STANDALONE), + : glApp(), glWindow(glApp, winId, scaleFactor, dspPtr), fChangingSize(false), fUI(glWindow.getUI()), @@ -461,8 +482,8 @@ private: // ------------------------------------------------------------------- // DGL Application and Window for this widget - Application glApp; - UIExporterWindow glWindow; + PluginApplication glApp; + UIExporterWindow glWindow; // prevent recursion bool fChangingSize;