From 3e966c521ef40b0c039fd6bb09efbb32974b2af5 Mon Sep 17 00:00:00 2001 From: Paul Date: Sun, 13 Feb 2022 16:11:28 -0500 Subject: [PATCH] Use OS DarkMode from sst; Use strnatcmp from sst (#5887) sst_plugininfra provides an isDarkMode API (currently only returning correct values on macOS). This diff does the following 1. Move the menu colors to either follow OS or follow skin 2. Since that involves an upgrade to sstplugininfra, also fix the strnatcmp dependency, addressing #5868 --- libs/sst/sst-plugininfra | 2 +- libs/strnatcmp/CMakeLists.txt | 9 -- libs/strnatcmp/README.md | 22 --- libs/strnatcmp/strnatcmp.cpp | 185 ---------------------- libs/strnatcmp/strnatcmp.h | 31 ---- src/common/CMakeLists.txt | 3 +- src/common/ModulatorPresetManager.cpp | 2 +- src/common/SkinModelImpl.cpp | 2 +- src/common/SurgeStorage.cpp | 2 +- src/surge-testrunner/UnitTestsINFRA.cpp | 2 +- src/surge-xt/gui/SurgeGUIEditor.cpp | 8 +- src/surge-xt/gui/SurgeJUCELookAndFeel.cpp | 32 ++-- 12 files changed, 27 insertions(+), 273 deletions(-) delete mode 100644 libs/strnatcmp/CMakeLists.txt delete mode 100644 libs/strnatcmp/README.md delete mode 100644 libs/strnatcmp/strnatcmp.cpp delete mode 100644 libs/strnatcmp/strnatcmp.h diff --git a/libs/sst/sst-plugininfra b/libs/sst/sst-plugininfra index 43218303d3a..0fc69d56fb0 160000 --- a/libs/sst/sst-plugininfra +++ b/libs/sst/sst-plugininfra @@ -1 +1 @@ -Subproject commit 43218303d3a1bfa2ce9b3101fe45fca942d1c2a0 +Subproject commit 0fc69d56fb0b20cc44d598841d6472487c975d21 diff --git a/libs/strnatcmp/CMakeLists.txt b/libs/strnatcmp/CMakeLists.txt deleted file mode 100644 index 56acb745e33..00000000000 --- a/libs/strnatcmp/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -# vi:set sw=2 et: -project(strnatcmp) - -add_library(${PROJECT_NAME} - strnatcmp.cpp - strnatcmp.h -) -add_library(surge::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) -target_include_directories(${PROJECT_NAME} PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/libs/strnatcmp/README.md b/libs/strnatcmp/README.md deleted file mode 100644 index d7c3fb91f3d..00000000000 --- a/libs/strnatcmp/README.md +++ /dev/null @@ -1,22 +0,0 @@ -This library contains strnatcmp from http://sourcefrog.net/projects/natsort/ and is -zlib-compatible licensed - -The only modifications made are - -1: Rename from .c to .cpp - ---------- - -This software is copyright by Martin Pool, and made available under the same licence as zlib: - -This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. - -Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: - -1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. - -2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. - -3. This notice may not be removed or altered from any source distribution. - -This licence applies only to the C implementation. You are free to reimplement the idea fom scratch in any language. diff --git a/libs/strnatcmp/strnatcmp.cpp b/libs/strnatcmp/strnatcmp.cpp deleted file mode 100644 index 612555bd339..00000000000 --- a/libs/strnatcmp/strnatcmp.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* -*- mode: c; c-file-style: "k&r" -*- - - strnatcmp.c -- Perform 'natural order' comparisons of strings in C. - Copyright (C) 2000, 2004 by Martin Pool - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - -/* partial change history: - * - * 2004-10-10 mbp: Lift out character type dependencies into macros. - * - * Eric Sosman pointed out that ctype functions take a parameter whose - * value must be that of an unsigned int, even on platforms that have - * negative chars in their default char type. - */ - -#include -#include -#include -#include - -#include "strnatcmp.h" - -/* These are defined as macros to make it easier to adapt this code to - * different characters types or comparison functions. */ -static inline int nat_isdigit(nat_char a) { return isdigit((unsigned char)a); } - -static inline int nat_isspace(nat_char a) { return isspace((unsigned char)a); } - -static inline nat_char nat_toupper(nat_char a) { return toupper((unsigned char)a); } - -static int compare_right(nat_char const *a, nat_char const *b) -{ - int bias = 0; - - /* The longest run of digits wins. That aside, the greatest - value wins, but we can't know that it will until we've scanned - both numbers to know that they have the same magnitude, so we - remember it in BIAS. */ - for (;; a++, b++) - { - if (!nat_isdigit(*a) && !nat_isdigit(*b)) - return bias; - else if (!nat_isdigit(*a)) - return -1; - else if (!nat_isdigit(*b)) - return +1; - else if (*a < *b) - { - if (!bias) - bias = -1; - } - else if (*a > *b) - { - if (!bias) - bias = +1; - } - else if (!*a && !*b) - return bias; - } - - return 0; -} - -static int compare_left(nat_char const *a, nat_char const *b) -{ - /* Compare two left-aligned numbers: the first to have a - different value wins. */ - for (;; a++, b++) - { - if (!nat_isdigit(*a) && !nat_isdigit(*b)) - return 0; - else if (!nat_isdigit(*a)) - return -1; - else if (!nat_isdigit(*b)) - return +1; - else if (*a < *b) - return -1; - else if (*a > *b) - return +1; - } - - return 0; -} - -static int strnatcmp0(nat_char const *a, nat_char const *b, int fold_case) -{ - int ai, bi; - nat_char ca, cb; - int fractional, result; - - assert(a && b); - ai = bi = 0; - - // Modification: Strip all leading spaces and any consecutive internal spaces - bool fa{true}, fb{true}; - while (1) - { - ca = a[ai]; - cb = b[bi]; - - /* skip over leading spaces or zeros */ - if (fa) - { - while (nat_isspace(ca)) - ca = a[++ai]; - } - else - { - while (ca && nat_isspace(ca) && nat_isspace(a[ai + 1])) - ca = a[++ai]; - } - fa = false; - - if (fb) - { - while (nat_isspace(cb)) - cb = b[++bi]; - } - else - { - while (cb && nat_isspace(cb) && nat_isspace(b[bi + 1])) - cb = b[++bi]; - } - fb = false; - - /* process run of digits */ - if (nat_isdigit(ca) && nat_isdigit(cb)) - { - fractional = (ca == '0' || cb == '0'); - - if (fractional) - { - if ((result = compare_left(a + ai, b + bi)) != 0) - return result; - } - else - { - if ((result = compare_right(a + ai, b + bi)) != 0) - return result; - } - } - - if (!ca && !cb) - { - /* The strings compare the same. Perhaps the caller - will want to call strcmp to break the tie. */ - return 0; - } - - if (fold_case) - { - ca = nat_toupper(ca); - cb = nat_toupper(cb); - } - - if (ca < cb) - return -1; - else if (ca > cb) - return +1; - - ++ai; - ++bi; - } -} - -int strnatcmp(nat_char const *a, nat_char const *b) { return strnatcmp0(a, b, 0); } - -/* Compare, recognizing numeric string and ignoring case. */ -int strnatcasecmp(nat_char const *a, nat_char const *b) { return strnatcmp0(a, b, 1); } diff --git a/libs/strnatcmp/strnatcmp.h b/libs/strnatcmp/strnatcmp.h deleted file mode 100644 index 51a3c4e8cb6..00000000000 --- a/libs/strnatcmp/strnatcmp.h +++ /dev/null @@ -1,31 +0,0 @@ -/* -*- mode: c; c-file-style: "k&r" -*- - - strnatcmp.c -- Perform 'natural order' comparisons of strings in C. - Copyright (C) 2000, 2004 by Martin Pool - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. -*/ - - -/* CUSTOMIZATION SECTION - * - * You can change this typedef, but must then also change the inline - * functions in strnatcmp.c */ -typedef char nat_char; - -int strnatcmp(nat_char const *a, nat_char const *b); -int strnatcasecmp(nat_char const *a, nat_char const *b); diff --git a/src/common/CMakeLists.txt b/src/common/CMakeLists.txt index 2e21c978636..877cc559282 100644 --- a/src/common/CMakeLists.txt +++ b/src/common/CMakeLists.txt @@ -4,7 +4,6 @@ project(surge-common) surge_add_lib_subdirectory(airwindows) surge_add_lib_subdirectory(eurorack) surge_add_lib_subdirectory(fmt) -surge_add_lib_subdirectory(strnatcmp) surge_add_lib_subdirectory(oddsound-mts) if(MINGW) set(HAVE_VISIBILITY 0 CACHE INTERNAL "Force-disable libsamplerate's visibility check on MinGW") @@ -323,10 +322,10 @@ target_link_libraries(${PROJECT_NAME} sst-plugininfra sst-plugininfra::filesystem sst-plugininfra::tinyxml + sst-plugininfra::strnatcmp surge::oddsound-mts surge::sqlite - surge::strnatcmp surge-common-binary tuning-library PRIVATE diff --git a/src/common/ModulatorPresetManager.cpp b/src/common/ModulatorPresetManager.cpp index d8df8a4451d..a34aaee163b 100644 --- a/src/common/ModulatorPresetManager.cpp +++ b/src/common/ModulatorPresetManager.cpp @@ -19,7 +19,7 @@ #include "SurgeStorage.h" #include "tinyxml/tinyxml.h" #include "DebugHelpers.h" -#include "strnatcmp.h" +#include "sst/plugininfra/strnatcmp.h" namespace Surge { diff --git a/src/common/SkinModelImpl.cpp b/src/common/SkinModelImpl.cpp index 1c21597dd09..e7950d3b9fe 100644 --- a/src/common/SkinModelImpl.cpp +++ b/src/common/SkinModelImpl.cpp @@ -21,7 +21,7 @@ #include #include "resource.h" #include "SkinColors.h" -#include "strnatcmp.h" +#include "sst/plugininfra/strnatcmp.h" /* * This file implements the innards of the Connector class and the SkinColor class diff --git a/src/common/SurgeStorage.cpp b/src/common/SurgeStorage.cpp index 800658ff4f3..e9d98f358b2 100644 --- a/src/common/SurgeStorage.cpp +++ b/src/common/SurgeStorage.cpp @@ -34,7 +34,7 @@ #include "UserDefaults.h" #include "version.h" -#include "strnatcmp.h" +#include "sst/plugininfra/strnatcmp.h" #include "libMTSClient.h" #include "FxPresetAndClipboardManager.h" #include "ModulatorPresetManager.h" diff --git a/src/surge-testrunner/UnitTestsINFRA.cpp b/src/surge-testrunner/UnitTestsINFRA.cpp index 5b856014b96..13f03ab4910 100644 --- a/src/surge-testrunner/UnitTestsINFRA.cpp +++ b/src/surge-testrunner/UnitTestsINFRA.cpp @@ -6,7 +6,7 @@ #include "QuadFilterUnit.h" #include "MemoryPool.h" -#include "strnatcmp.h" +#include "sst/plugininfra/strnatcmp.h" #include "catch2/catch2.hpp" diff --git a/src/surge-xt/gui/SurgeGUIEditor.cpp b/src/surge-xt/gui/SurgeGUIEditor.cpp index 0e52ee8b530..06cdf7ea4ef 100644 --- a/src/surge-xt/gui/SurgeGUIEditor.cpp +++ b/src/surge-xt/gui/SurgeGUIEditor.cpp @@ -3657,11 +3657,9 @@ juce::PopupMenu SurgeGUIEditor::makeSkinMenu(const juce::Point &where) Surge::Storage::updateUserDefaultValue(&(synth->storage), Surge::Storage::MenuLightness, i); juceEditor->surgeLF->onSkinChanged(); }; - skinSubMenu.addItem(Surge::GUI::toOSCaseForMenu("Always Dark Menus"), true, menuMode == 0, - [resetMenuTo]() { resetMenuTo(0); }); - skinSubMenu.addItem(Surge::GUI::toOSCaseForMenu("Always Light Menus"), true, menuMode == 1, - [resetMenuTo]() { resetMenuTo(1); }); - skinSubMenu.addItem(Surge::GUI::toOSCaseForMenu("Menus From Skin"), true, menuMode == 2, + skinSubMenu.addItem(Surge::GUI::toOSCaseForMenu("Menu Follows OS Light/Dark Mode"), true, + menuMode == 1, [resetMenuTo]() { resetMenuTo(1); }); + skinSubMenu.addItem(Surge::GUI::toOSCaseForMenu("Menus Follows Skin"), true, menuMode == 2, [resetMenuTo]() { resetMenuTo(2); }); skinSubMenu.addSeparator(); diff --git a/src/surge-xt/gui/SurgeJUCELookAndFeel.cpp b/src/surge-xt/gui/SurgeJUCELookAndFeel.cpp index c7aaa3a66a6..bdb85ff60bc 100644 --- a/src/surge-xt/gui/SurgeJUCELookAndFeel.cpp +++ b/src/surge-xt/gui/SurgeJUCELookAndFeel.cpp @@ -22,6 +22,7 @@ #include #include "UserDefaults.h" +#include "sst/plugininfra/misc_platform.h" // here and only here we using namespace juce so I can copy and override stuff from v4 easily using namespace juce; @@ -50,21 +51,24 @@ void SurgeJUCELookAndFeel::onSkinChanged() menuMode = Surge::Storage::getUserDefaultValue(storage, Surge::Storage::MenuLightness, 2); if (menuMode == 1) { - setColour(PopupMenu::backgroundColourId, Colour(255, 255, 255)); - setColour(PopupMenu::highlightedBackgroundColourId, Colour(220, 220, 230)); - setColour(PopupMenu::textColourId, juce::Colours::black); - setColour(PopupMenu::headerTextColourId, juce::Colours::black); - setColour(PopupMenu::highlightedTextColourId, juce::Colour(0, 0, 40)); - } - else if (menuMode == 0) // FIXME = mode 2 is follow skin - { - setColour(PopupMenu::backgroundColourId, Colour(48, 48, 48)); - setColour(PopupMenu::highlightedBackgroundColourId, Colour(96, 96, 96)); - setColour(PopupMenu::textColourId, juce::Colours::white); - setColour(PopupMenu::headerTextColourId, juce::Colours::white); - setColour(PopupMenu::highlightedTextColourId, juce::Colour(240, 240, 250)); + if (sst::plugininfra::misc_platform::isDarkMode()) + { + setColour(PopupMenu::backgroundColourId, Colour(48, 48, 48)); + setColour(PopupMenu::highlightedBackgroundColourId, Colour(96, 96, 96)); + setColour(PopupMenu::textColourId, juce::Colours::white); + setColour(PopupMenu::headerTextColourId, juce::Colours::white); + setColour(PopupMenu::highlightedTextColourId, juce::Colour(240, 240, 250)); + } + else + { + setColour(PopupMenu::backgroundColourId, Colour(255, 255, 255)); + setColour(PopupMenu::highlightedBackgroundColourId, Colour(220, 220, 230)); + setColour(PopupMenu::textColourId, juce::Colours::black); + setColour(PopupMenu::headerTextColourId, juce::Colours::black); + setColour(PopupMenu::highlightedTextColourId, juce::Colour(0, 0, 40)); + } } - else if (menuMode == 2) + else { setColour(PopupMenu::backgroundColourId, skin->getColor(Colors::PopupMenu::Background)); setColour(PopupMenu::highlightedBackgroundColourId,