Browse Source

Fixup mess surrounding application class name once and for all

Signed-off-by: falkTX <falktx@falktx.com>
pull/272/head
falkTX 4 years ago
parent
commit
cbe0727877
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
5 changed files with 54 additions and 18 deletions
  1. +11
    -0
      dgl/Application.hpp
  2. +5
    -0
      dgl/src/Application.cpp
  3. +8
    -12
      dgl/src/ApplicationPrivateData.cpp
  4. +3
    -0
      dgl/src/ApplicationPrivateData.hpp
  5. +27
    -6
      distrho/src/DistrhoUIInternal.hpp

+ 11
- 0
dgl/Application.hpp View File

@@ -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;


+ 5
- 0
dgl/src/Application.cpp View File

@@ -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

+ 8
- 12
dgl/src/ApplicationPrivateData.cpp View File

@@ -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

+ 3
- 0
dgl/src/ApplicationPrivateData.hpp View File

@@ -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)
};



+ 27
- 6
distrho/src/DistrhoUIInternal.hpp View File

@@ -1,6 +1,6 @@
/*
* DISTRHO Plugin Framework (DPF)
* Copyright (C) 2012-2020 Filipe Coelho <falktx@falktx.com>
* Copyright (C) 2012-2021 Filipe Coelho <falktx@falktx.com>
*
* 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;


Loading…
Cancel
Save