From 930a0ca31e0092dc5f35e81cbb39c3f622751c6c Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 10 Oct 2022 21:37:27 +0100 Subject: [PATCH] Ignore dynamic light/dark mode in headless builds Signed-off-by: falkTX --- include/helpers.hpp | 6 ++++++ src/custom/asset.cpp | 4 ++++ src/custom/dep.cpp | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/include/helpers.hpp b/include/helpers.hpp index 2cf4ad0..6c21c34 100644 --- a/include/helpers.hpp +++ b/include/helpers.hpp @@ -36,9 +36,11 @@ namespace rack { +#ifndef HEADLESS namespace asset { void updateForcingBlackSilverScrewMode(std::string slug); } +#endif struct CardinalPluginModelHelper : plugin::Model { virtual app::ModuleWidget* createModuleWidgetFromEngineLoad(engine::Module* m) = 0; @@ -76,7 +78,9 @@ struct CardinalPluginModel : CardinalPluginModelHelper } tm = dynamic_cast(m); } + #ifndef HEADLESS asset::updateForcingBlackSilverScrewMode(slug); + #endif app::ModuleWidget* const tmw = new TModuleWidget(tm); DISTRHO_CUSTOM_SAFE_ASSERT_RETURN(m != nullptr ? m->model->name.c_str() : "null", tmw->module == m, nullptr); tmw->setModel(this); @@ -91,7 +95,9 @@ struct CardinalPluginModel : CardinalPluginModelHelper TModule* const tm = dynamic_cast(m); DISTRHO_SAFE_ASSERT_RETURN(tm != nullptr, nullptr); + #ifndef HEADLESS asset::updateForcingBlackSilverScrewMode(slug); + #endif TModuleWidget* const tmw = new TModuleWidget(tm); DISTRHO_SAFE_ASSERT_RETURN(tmw->module == m, nullptr); tmw->setModel(this); diff --git a/src/custom/asset.cpp b/src/custom/asset.cpp index efee14a..dcc4016 100644 --- a/src/custom/asset.cpp +++ b/src/custom/asset.cpp @@ -31,8 +31,10 @@ namespace rack { namespace asset { +#ifndef HEADLESS extern bool forceBlackScrew; extern bool forceSilverScrew; +#endif std::string userDir; // ignored std::string systemDir; // points to plugin resources dir (or installed/local Rack dir) @@ -53,10 +55,12 @@ std::string user(std::string filename) { // get system resource, trimming "res/" prefix if we are loaded as a plugin bundle std::string system(std::string filename) { + #ifndef HEADLESS /**/ if (forceBlackScrew && string::endsWith(filename, "/ScrewBlack.svg")) filename = filename.substr(0, filename.size()-15) + "/./ScrewBlack.svg"; else if (forceSilverScrew && string::endsWith(filename, "/ScrewSilver.svg")) filename = filename.substr(0, filename.size()-16) + "/./ScrewSilver.svg"; + #endif return system::join(systemDir, bundlePath.empty() ? filename : trim(filename)); } diff --git a/src/custom/dep.cpp b/src/custom/dep.cpp index 13379e9..0cebcd0 100644 --- a/src/custom/dep.cpp +++ b/src/custom/dep.cpp @@ -23,6 +23,7 @@ #include namespace rack { +#ifndef HEADLESS namespace asset { bool forceBlackScrew = false; bool forceSilverScrew = false; @@ -59,6 +60,7 @@ void updateForcingBlackSilverScrewMode(std::string slug) { ); } } +#endif namespace settings { bool darkMode = true; int rateLimit = 0; @@ -92,6 +94,7 @@ NVGcolor nvgRGBblank(const unsigned char r, const unsigned char g, const unsigne #undef nsvgParseFromFile #include +#ifndef HEADLESS enum DarkMode { kMode21kHz, kModeAaronStatic, @@ -1149,12 +1152,14 @@ bool invertPaintForLightMode(const LightMode mode, NSVGshape* const shape, NSVGp paint.color = invertColor(paint.color); return true; } +#endif // HEADLESS extern "C" { NSVGimage* nsvgParseFromFileCardinal(const char* filename, const char* units, float dpi); void nsvgDeleteCardinal(NSVGimage*); } +#ifndef HEADLESS struct ExtendedNSVGimage { NSVGimage* const handle; NSVGimage* handleOrig; @@ -1239,11 +1244,13 @@ void deleteExtendedNSVGimage(ExtendedNSVGimage& ext) ext.handleOrig = nullptr; } } +#endif // HEADLESS NSVGimage* nsvgParseFromFileCardinal(const char* const filename, const char* const units, const float dpi) { if (NSVGimage* const handle = nsvgParseFromFile(filename, units, dpi)) { + #ifndef HEADLESS const size_t filenamelen = std::strlen(filename); bool hasDarkMode = false; @@ -1419,6 +1426,7 @@ postparse: std::memcpy(handle, handleMOD, sizeof(NSVGimage)); } } + #endif // HEADLESS return handle; } @@ -1428,6 +1436,7 @@ postparse: void nsvgDeleteCardinal(NSVGimage* const handle) { + #ifndef HEADLESS for (auto it = loadedDarkSVGs.begin(), end = loadedDarkSVGs.end(); it != end; ++it) { ExtendedNSVGimage& ext(*it); @@ -1451,12 +1460,14 @@ void nsvgDeleteCardinal(NSVGimage* const handle) loadedLightSVGs.erase(it); break; } + #endif nsvgDelete(handle); } void switchDarkMode(const bool darkMode) { + #ifndef HEADLESS if (rack::settings::darkMode == darkMode) return; @@ -1477,12 +1488,14 @@ void switchDarkMode(const bool darkMode) else if (ext.handleMOD != nullptr) std::memcpy(ext.handle, !darkMode ? ext.handleMOD : ext.handleOrig, sizeof(NSVGimage)); } + #endif } namespace rack { namespace asset { void destroy() { + #ifndef HEADLESS for (auto it = loadedDarkSVGs.begin(), end = loadedDarkSVGs.end(); it != end; ++it) { ExtendedNSVGimage& ext(*it); @@ -1497,6 +1510,7 @@ void destroy() { loadedDarkSVGs.clear(); loadedLightSVGs.clear(); + #endif } }