From 3d5d88a41def9d7e17fabfe44b20992f1419f5c8 Mon Sep 17 00:00:00 2001 From: Nicholas Bennett Date: Thu, 22 Sep 2022 17:26:31 -0700 Subject: [PATCH 01/20] inintial buggy fix for syncing OS themes --- .../AppearanceConfig.cpp | 31 ++++++++++++- .../TerminalSettingsModel/AppearanceConfig.h | 3 ++ .../CascadiaSettings.cpp | 19 +++++--- .../IAppearanceConfig.idl | 2 + .../TerminalSettingsModel/MTSMSettings.h | 1 - .../TerminalSettings.cpp | 45 ++++++++++++++++--- .../TerminalSettingsModel/TerminalSettings.h | 3 +- 7 files changed, 89 insertions(+), 15 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp index d48763eca1c..4c84fae3822 100644 --- a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp @@ -18,6 +18,7 @@ static constexpr std::string_view SelectionBackgroundKey{ "selectionBackground" static constexpr std::string_view CursorColorKey{ "cursorColor" }; static constexpr std::string_view LegacyAcrylicTransparencyKey{ "acrylicOpacity" }; static constexpr std::string_view OpacityKey{ "opacity" }; +static constexpr std::string_view ColorSchemeKey{ "colorScheme" }; AppearanceConfig::AppearanceConfig(winrt::weak_ref sourceProfile) : _sourceProfile(std::move(sourceProfile)) @@ -32,6 +33,9 @@ winrt::com_ptr AppearanceConfig::CopyAppearance(const Appearan appearance->_SelectionBackground = source->_SelectionBackground; appearance->_CursorColor = source->_CursorColor; appearance->_Opacity = source->_Opacity; + appearance->_ColorSchemeName = source->_ColorSchemeName; + appearance->_DarkColorSchemeName = source->_DarkColorSchemeName; + appearance->_LightColorSchemeName = source->_LightColorSchemeName; #define APPEARANCE_SETTINGS_COPY(type, name, jsonKey, ...) \ appearance->_##name = source->_##name; @@ -50,7 +54,17 @@ Json::Value AppearanceConfig::ToJson() const JsonUtils::SetValueForKey(json, SelectionBackgroundKey, _SelectionBackground); JsonUtils::SetValueForKey(json, CursorColorKey, _CursorColor); JsonUtils::SetValueForKey(json, OpacityKey, _Opacity, JsonUtils::OptionalConverter{}); - + if (HasColorSchemeName() && HasLightColorSchemeName()) + { + JsonUtils::SetValueForKey(json["colorScheme"], "dark", _DarkColorSchemeName); + JsonUtils::SetValueForKey(json["colorScheme"], "light", _LightColorSchemeName); + } + else if (HasColorSchemeName()) + { + JsonUtils::SetValueForKey(json["colorScheme"], "dark", _ColorSchemeName); + JsonUtils::SetValueForKey(json["colorScheme"], "light", _ColorSchemeName); + } + #define APPEARANCE_SETTINGS_TO_JSON(type, name, jsonKey, ...) \ JsonUtils::SetValueForKey(json, jsonKey, _##name); MTSM_APPEARANCE_SETTINGS(APPEARANCE_SETTINGS_TO_JSON) @@ -79,6 +93,21 @@ void AppearanceConfig::LayerJson(const Json::Value& json) JsonUtils::GetValueForKey(json, LegacyAcrylicTransparencyKey, _Opacity); JsonUtils::GetValueForKey(json, OpacityKey, _Opacity, JsonUtils::OptionalConverter{}); + if (json["colorScheme"].isString()) + { + // to make the UI happy, set ColorSchemeName. + JsonUtils::GetValueForKey(json, ColorSchemeKey, _ColorSchemeName); + JsonUtils::GetValueForKey(json, ColorSchemeKey, _DarkColorSchemeName); + JsonUtils::GetValueForKey(json, ColorSchemeKey, _LightColorSchemeName); + } + else if (json["colorScheme"].isObject()) + { + // to make the UI happy, set ColorSchemeName to whatever the dark value is. + JsonUtils::GetValueForKey(json["colorScheme"], "dark", _ColorSchemeName); + JsonUtils::GetValueForKey(json["colorScheme"], "dark", _DarkColorSchemeName); + JsonUtils::GetValueForKey(json["colorScheme"], "light", _LightColorSchemeName); + } + #define APPEARANCE_SETTINGS_LAYER_JSON(type, name, jsonKey, ...) \ JsonUtils::GetValueForKey(json, jsonKey, _##name); diff --git a/src/cascadia/TerminalSettingsModel/AppearanceConfig.h b/src/cascadia/TerminalSettingsModel/AppearanceConfig.h index bbc30927eb7..9fd8d96231f 100644 --- a/src/cascadia/TerminalSettingsModel/AppearanceConfig.h +++ b/src/cascadia/TerminalSettingsModel/AppearanceConfig.h @@ -41,6 +41,9 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation INHERITABLE_NULLABLE_SETTING(Model::IAppearanceConfig, Microsoft::Terminal::Core::Color, SelectionBackground, nullptr); INHERITABLE_NULLABLE_SETTING(Model::IAppearanceConfig, Microsoft::Terminal::Core::Color, CursorColor, nullptr); INHERITABLE_SETTING(Model::IAppearanceConfig, double, Opacity, 1.0); + INHERITABLE_SETTING(Model::IAppearanceConfig, hstring, ColorSchemeName, L"Campbell"); + INHERITABLE_SETTING(Model::IAppearanceConfig, hstring, DarkColorSchemeName, L"Campbell"); + INHERITABLE_SETTING(Model::IAppearanceConfig, hstring, LightColorSchemeName, L"Campbell"); #define APPEARANCE_SETTINGS_INITIALIZE(type, name, jsonKey, ...) \ INHERITABLE_SETTING(Model::IAppearanceConfig, type, name, ##__VA_ARGS__) diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp index 9712c6e51cf..01b2dcf2d67 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp @@ -430,22 +430,29 @@ void CascadiaSettings::_validateSettings() void CascadiaSettings::_validateAllSchemesExist() { const auto colorSchemes = _globals->ColorSchemes(); - auto foundInvalidScheme = false; + auto foundInvalidDarkScheme = false; + auto foundInvalidLightScheme = false; for (const auto& profile : _allProfiles) { for (const auto& appearance : std::array{ profile.DefaultAppearance(), profile.UnfocusedAppearance() }) { - if (appearance && !colorSchemes.HasKey(appearance.ColorSchemeName())) + if (appearance && !colorSchemes.HasKey(appearance.DarkColorSchemeName())) { - // Clear the user set color scheme. We'll just fallback instead. - appearance.ClearColorSchemeName(); - foundInvalidScheme = true; + // Clear the user set dark color scheme. We'll just fallback instead. + appearance.ClearDarkColorSchemeName(); + foundInvalidDarkScheme = true; + } + if (appearance && !colorSchemes.HasKey(appearance.LightColorSchemeName())) + { + // Clear the user set light color scheme. We'll just fallback instead. + appearance.ClearLightColorSchemeName(); + foundInvalidLightScheme = true; } } } - if (foundInvalidScheme) + if (foundInvalidDarkScheme || foundInvalidLightScheme) { _warnings.Append(SettingsLoadWarnings::UnknownColorScheme); } diff --git a/src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl b/src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl index 2cfa305dec4..47e3dc593a1 100644 --- a/src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl +++ b/src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl @@ -34,6 +34,8 @@ namespace Microsoft.Terminal.Settings.Model { Microsoft.Terminal.Settings.Model.Profile SourceProfile { get; }; INHERITABLE_APPEARANCE_SETTING(String, ColorSchemeName); + INHERITABLE_APPEARANCE_SETTING(String, DarkColorSchemeName); + INHERITABLE_APPEARANCE_SETTING(String, LightColorSchemeName); INHERITABLE_APPEARANCE_SETTING(Windows.Foundation.IReference, Foreground); INHERITABLE_APPEARANCE_SETTING(Windows.Foundation.IReference, Background); INHERITABLE_APPEARANCE_SETTING(Windows.Foundation.IReference, SelectionBackground); diff --git a/src/cascadia/TerminalSettingsModel/MTSMSettings.h b/src/cascadia/TerminalSettingsModel/MTSMSettings.h index 3cae1919883..91ff1b068a4 100644 --- a/src/cascadia/TerminalSettingsModel/MTSMSettings.h +++ b/src/cascadia/TerminalSettingsModel/MTSMSettings.h @@ -109,7 +109,6 @@ Author(s): X(bool, RetroTerminalEffect, "experimental.retroTerminalEffect", false) \ X(hstring, PixelShaderPath, "experimental.pixelShaderPath") \ X(ConvergedAlignment, BackgroundImageAlignment, "backgroundImageAlignment", ConvergedAlignment::Horizontal_Center | ConvergedAlignment::Vertical_Center) \ - X(hstring, ColorSchemeName, "colorScheme", L"Campbell") \ X(hstring, BackgroundImagePath, "backgroundImage") \ X(Model::IntenseStyle, IntenseTextStyle, "intenseTextStyle", Model::IntenseStyle::Bright) \ X(Core::AdjustTextMode, AdjustIndistinguishableColors, "adjustIndistinguishableColors", Core::AdjustTextMode::Never) diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 0ba57857303..09127b4c537 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -57,7 +57,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation const auto globals = appSettings.GlobalSettings(); settings->_ApplyProfileSettings(profile); settings->_ApplyGlobalSettings(globals); - settings->_ApplyAppearanceSettings(profile.DefaultAppearance(), globals.ColorSchemes()); + settings->_ApplyAppearanceSettings(profile.DefaultAppearance(), globals.ColorSchemes(), globals.CurrentTheme()); return settings; } @@ -91,7 +91,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { const auto globals = appSettings.GlobalSettings(); auto childImpl = settings->CreateChild(); - childImpl->_ApplyAppearanceSettings(unfocusedAppearance, globals.ColorSchemes()); + childImpl->_ApplyAppearanceSettings(unfocusedAppearance, globals.ColorSchemes(), globals.CurrentTheme()); child = *childImpl; } @@ -183,17 +183,50 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation return settingsPair; } - void TerminalSettings::_ApplyAppearanceSettings(const IAppearanceConfig& appearance, const Windows::Foundation::Collections::IMapView& schemes) + void TerminalSettings::_ApplyAppearanceSettings(const IAppearanceConfig& appearance, const Windows::Foundation::Collections::IMapView& schemes, const winrt::Microsoft::Terminal::Settings::Model::Theme currentTheme) { _CursorShape = appearance.CursorShape(); _CursorHeight = appearance.CursorHeight(); - if (!appearance.ColorSchemeName().empty()) + if (currentTheme.Name() == L"dark") { - if (const auto scheme = schemes.TryLookup(appearance.ColorSchemeName())) + if (!appearance.DarkColorSchemeName().empty()) { - ApplyColorScheme(scheme); + if (const auto scheme = schemes.TryLookup(appearance.DarkColorSchemeName())) + { + ApplyColorScheme(scheme); + } + } + } + else if (currentTheme.Name() == L"light") + { + if (!appearance.LightColorSchemeName().empty()) + { + if (const auto scheme = schemes.TryLookup(appearance.LightColorSchemeName())) + { + ApplyColorScheme(scheme); + } } } + else if (currentTheme.Name() == L"system" && Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark) + { + if (!appearance.DarkColorSchemeName().empty()) + { + if (const auto scheme = schemes.TryLookup(appearance.DarkColorSchemeName())) + { + ApplyColorScheme(scheme); + } + } + } + else if (currentTheme.Name() == L"system" && Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Light) + { + if (!appearance.LightColorSchemeName().empty()) + { + if (const auto scheme = schemes.TryLookup(appearance.LightColorSchemeName())) + { + ApplyColorScheme(scheme); + } + } + } if (appearance.Foreground()) { _DefaultForeground = til::color{ appearance.Foreground().Value() }; diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.h b/src/cascadia/TerminalSettingsModel/TerminalSettings.h index 0dd65cdfbb7..e92ce3aeed9 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.h @@ -170,7 +170,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation void _ApplyGlobalSettings(const Model::GlobalAppSettings& globalSettings) noexcept; void _ApplyAppearanceSettings(const Microsoft::Terminal::Settings::Model::IAppearanceConfig& appearance, - const Windows::Foundation::Collections::IMapView& schemes); + const Windows::Foundation::Collections::IMapView& schemes, + const winrt::Microsoft::Terminal::Settings::Model::Theme currentTheme); friend class SettingsModelLocalTests::TerminalSettingsTests; }; From 5f547501b56d112447d87f121bb28b8f664162f1 Mon Sep 17 00:00:00 2001 From: Nicholas Bennett Date: Mon, 3 Oct 2022 14:39:36 -0700 Subject: [PATCH 02/20] fixed control preview bug --- .../ColorSchemeTests.cpp | 17 +++++++++++++++++ .../TerminalSettingsTests.cpp | 17 +++++++++-------- .../TerminalControl/IControlAppearance.idl | 1 + .../TerminalSettingsModel/AppearanceConfig.cpp | 15 ++++++++++++--- .../TerminalSettingsModel/CascadiaSettings.cpp | 3 +++ .../TerminalSettingsModel/TerminalSettings.cpp | 11 ++++++++++- .../TerminalSettingsModel/TerminalSettings.h | 1 + src/cascadia/inc/ControlProperties.h | 3 ++- 8 files changed, 55 insertions(+), 13 deletions(-) diff --git a/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp b/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp index 721e426761b..fb84a1db5df 100644 --- a/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp @@ -217,6 +217,14 @@ namespace SettingsModelLocalTests { "name": "Different reference", "colorScheme": "One Half Dark" + }, + { + "name": "Different reference / Light and Dark", + "colorScheme": + { + "dark": "One Half Dark", + "light": "One Half Light" + } } ] }, @@ -322,5 +330,14 @@ namespace SettingsModelLocalTests VERIFY_ARE_EQUAL(L"One Half Dark", prof.DefaultAppearance().ColorSchemeName()); VERIFY_IS_TRUE(prof.DefaultAppearance().HasColorSchemeName()); } + { + const auto& prof{ profiles.GetAt(4) }; + VERIFY_ARE_EQUAL(L"One Half Dark", prof.DefaultAppearance().DarkColorSchemeName()); + VERIFY_ARE_EQUAL(L"One Half Light", prof.DefaultAppearance().LightColorSchemeName()); + VERIFY_ARE_EQUAL(L"One Half Dark", prof.DefaultAppearance().ColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasDarkColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasLightColorSchemeName()); + } } } diff --git a/src/cascadia/LocalTests_SettingsModel/TerminalSettingsTests.cpp b/src/cascadia/LocalTests_SettingsModel/TerminalSettingsTests.cpp index 8680e7f9cd2..0ae0bcc164e 100644 --- a/src/cascadia/LocalTests_SettingsModel/TerminalSettingsTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/TerminalSettingsTests.cpp @@ -779,21 +779,22 @@ namespace SettingsModelLocalTests VERIFY_ARE_EQUAL(6u, settings->ActiveProfiles().Size()); VERIFY_ARE_EQUAL(2u, settings->GlobalSettings().ColorSchemes().Size()); - auto createTerminalSettings = [&](const auto& profile, const auto& schemes) { + auto createTerminalSettings = [&](const auto& profile, const auto& schemes, const auto& Theme) { auto terminalSettings{ winrt::make_self() }; terminalSettings->_ApplyProfileSettings(profile); - terminalSettings->_ApplyAppearanceSettings(profile.DefaultAppearance(), schemes); + terminalSettings->_ApplyAppearanceSettings(profile.DefaultAppearance(), schemes, Theme); return terminalSettings; }; const auto activeProfiles = settings->ActiveProfiles(); const auto colorSchemes = settings->GlobalSettings().ColorSchemes(); - const auto terminalSettings0 = createTerminalSettings(activeProfiles.GetAt(0), colorSchemes); - const auto terminalSettings1 = createTerminalSettings(activeProfiles.GetAt(1), colorSchemes); - const auto terminalSettings2 = createTerminalSettings(activeProfiles.GetAt(2), colorSchemes); - const auto terminalSettings3 = createTerminalSettings(activeProfiles.GetAt(3), colorSchemes); - const auto terminalSettings4 = createTerminalSettings(activeProfiles.GetAt(4), colorSchemes); - const auto terminalSettings5 = createTerminalSettings(activeProfiles.GetAt(5), colorSchemes); + const auto currentTheme = settings->GlobalSettings().CurrentTheme(); + const auto terminalSettings0 = createTerminalSettings(activeProfiles.GetAt(0), colorSchemes, currentTheme); + const auto terminalSettings1 = createTerminalSettings(activeProfiles.GetAt(1), colorSchemes, currentTheme); + const auto terminalSettings2 = createTerminalSettings(activeProfiles.GetAt(2), colorSchemes, currentTheme); + const auto terminalSettings3 = createTerminalSettings(activeProfiles.GetAt(3), colorSchemes, currentTheme); + const auto terminalSettings4 = createTerminalSettings(activeProfiles.GetAt(4), colorSchemes, currentTheme); + const auto terminalSettings5 = createTerminalSettings(activeProfiles.GetAt(5), colorSchemes, currentTheme); VERIFY_ARE_EQUAL(til::color(0x12, 0x34, 0x56), terminalSettings0->CursorColor()); // from color scheme VERIFY_ARE_EQUAL(DEFAULT_CURSOR_COLOR, terminalSettings1->CursorColor()); // default diff --git a/src/cascadia/TerminalControl/IControlAppearance.idl b/src/cascadia/TerminalControl/IControlAppearance.idl index 96c3db75a11..8cd18b2513e 100644 --- a/src/cascadia/TerminalControl/IControlAppearance.idl +++ b/src/cascadia/TerminalControl/IControlAppearance.idl @@ -14,6 +14,7 @@ namespace Microsoft.Terminal.Control // IntenseIsBold and IntenseIsBright are in Core Appearance Double Opacity { get; }; + String ColorSchemeName { get; }; // Experimental settings Boolean RetroTerminalEffect { get; }; String PixelShaderPath { get; }; diff --git a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp index 4c84fae3822..056faede661 100644 --- a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp @@ -54,10 +54,19 @@ Json::Value AppearanceConfig::ToJson() const JsonUtils::SetValueForKey(json, SelectionBackgroundKey, _SelectionBackground); JsonUtils::SetValueForKey(json, CursorColorKey, _CursorColor); JsonUtils::SetValueForKey(json, OpacityKey, _Opacity, JsonUtils::OptionalConverter{}); - if (HasColorSchemeName() && HasLightColorSchemeName()) + if (HasDarkColorSchemeName() && HasLightColorSchemeName()) { - JsonUtils::SetValueForKey(json["colorScheme"], "dark", _DarkColorSchemeName); - JsonUtils::SetValueForKey(json["colorScheme"], "light", _LightColorSchemeName); + // check if the setting is coming from the UI, if so grab the ColorSchemeName until the settings UI is fixed.. + if (_ColorSchemeName != _DarkColorSchemeName) + { + JsonUtils::SetValueForKey(json["colorScheme"], "dark", _ColorSchemeName); + JsonUtils::SetValueForKey(json["colorScheme"], "light", _ColorSchemeName); + } + else + { + JsonUtils::SetValueForKey(json["colorScheme"], "dark", _DarkColorSchemeName); + JsonUtils::SetValueForKey(json["colorScheme"], "light", _LightColorSchemeName); + } } else if (HasColorSchemeName()) { diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp index 01b2dcf2d67..9c1e4a473a8 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp @@ -326,6 +326,9 @@ Model::Profile CascadiaSettings::DuplicateProfile(const Model::Profile& source) DUPLICATE_SETTING_MACRO_SUB(appearance, target, SelectionBackground); DUPLICATE_SETTING_MACRO_SUB(appearance, target, CursorColor); DUPLICATE_SETTING_MACRO_SUB(appearance, target, Opacity); + DUPLICATE_SETTING_MACRO_SUB(appearance, target, DarkColorSchemeName); + DUPLICATE_SETTING_MACRO_SUB(appearance, target, LightColorSchemeName); + DUPLICATE_SETTING_MACRO_SUB(appearance, target, ColorSchemeName); } // UnfocusedAppearance is treated as a single setting, diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 09127b4c537..985925dc3d9 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -187,7 +187,15 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { _CursorShape = appearance.CursorShape(); _CursorHeight = appearance.CursorHeight(); - if (currentTheme.Name() == L"dark") + // check if this setting update is coming from the UI. DarkColorSchemeName doesn't update till the save button is hit. This means if they differ, it is just the control preview that needs the update. + if (appearance.DarkColorSchemeName() != appearance.ColorSchemeName()) + { + if (const auto scheme = schemes.TryLookup(appearance.ColorSchemeName())) + { + ApplyColorScheme(scheme); + } + } + else if (currentTheme.Name() == L"dark") { if (!appearance.DarkColorSchemeName().empty()) { @@ -363,6 +371,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation else { AppliedColorScheme(scheme); + ColorSchemeName(scheme.Name()); _DefaultForeground = til::color{ scheme.Foreground() }; _DefaultBackground = til::color{ scheme.Background() }; _SelectionBackground = til::color{ scheme.SelectionBackground() }; diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.h b/src/cascadia/TerminalSettingsModel/TerminalSettings.h index e92ce3aeed9..84b62177935 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.h @@ -128,6 +128,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation INHERITABLE_SETTING(Model::TerminalSettings, IFontFeatureMap, FontFeatures); INHERITABLE_SETTING(Model::TerminalSettings, Model::ColorScheme, AppliedColorScheme); + INHERITABLE_SETTING(Model::TerminalSettings, hstring, ColorSchemeName); INHERITABLE_SETTING(Model::TerminalSettings, hstring, BackgroundImage); INHERITABLE_SETTING(Model::TerminalSettings, double, BackgroundImageOpacity, 1.0); diff --git a/src/cascadia/inc/ControlProperties.h b/src/cascadia/inc/ControlProperties.h index 5911fa26183..1a5efc0e1bf 100644 --- a/src/cascadia/inc/ControlProperties.h +++ b/src/cascadia/inc/ControlProperties.h @@ -16,10 +16,11 @@ X(winrt::Microsoft::Terminal::Core::AdjustTextMode, AdjustIndistinguishableColors, winrt::Microsoft::Terminal::Core::AdjustTextMode::Never) // --------------------------- Control Appearance --------------------------- -// All of these settings are defined in IControlSettings. +// All of these settings are defined in IControlAppearance. #define CONTROL_APPEARANCE_SETTINGS(X) \ X(til::color, SelectionBackground, DEFAULT_FOREGROUND) \ X(double, Opacity, 1.0) \ + X(winrt::hstring, ColorSchemeName, L"Campbell") \ X(winrt::hstring, BackgroundImage) \ X(double, BackgroundImageOpacity, 1.0) \ X(winrt::Windows::UI::Xaml::Media::Stretch, BackgroundImageStretchMode, winrt::Windows::UI::Xaml::Media::Stretch::UniformToFill) \ From 43cc9fadd602028f47f850de62be8bf1c48fc172 Mon Sep 17 00:00:00 2001 From: Nicholas Bennett Date: Mon, 3 Oct 2022 15:07:17 -0700 Subject: [PATCH 03/20] Code cleanup --- src/cascadia/TerminalSettingsModel/TerminalSettings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 985925dc3d9..016097c501d 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -234,7 +234,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation ApplyColorScheme(scheme); } } - } + } if (appearance.Foreground()) { _DefaultForeground = til::color{ appearance.Foreground().Value() }; From e4c2d202ea29d08d6191d1d591bbc945f453a865 Mon Sep 17 00:00:00 2001 From: Nicholas Bennett Date: Mon, 3 Oct 2022 15:11:19 -0700 Subject: [PATCH 04/20] Code cleanup --- src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp | 3 +-- src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl | 6 ++---- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp index 056faede661..e9f4fcd2b6b 100644 --- a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp @@ -73,7 +73,7 @@ Json::Value AppearanceConfig::ToJson() const JsonUtils::SetValueForKey(json["colorScheme"], "dark", _ColorSchemeName); JsonUtils::SetValueForKey(json["colorScheme"], "light", _ColorSchemeName); } - + #define APPEARANCE_SETTINGS_TO_JSON(type, name, jsonKey, ...) \ JsonUtils::SetValueForKey(json, jsonKey, _##name); MTSM_APPEARANCE_SETTINGS(APPEARANCE_SETTINGS_TO_JSON) @@ -116,7 +116,6 @@ void AppearanceConfig::LayerJson(const Json::Value& json) JsonUtils::GetValueForKey(json["colorScheme"], "dark", _DarkColorSchemeName); JsonUtils::GetValueForKey(json["colorScheme"], "light", _LightColorSchemeName); } - #define APPEARANCE_SETTINGS_LAYER_JSON(type, name, jsonKey, ...) \ JsonUtils::GetValueForKey(json, jsonKey, _##name); diff --git a/src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl b/src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl index 47e3dc593a1..94fa06da0da 100644 --- a/src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl +++ b/src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl @@ -5,7 +5,7 @@ import "Profile.idl"; #include "IInheritable.idl.h" #define INHERITABLE_APPEARANCE_SETTING(Type, Name) \ - _BASE_INHERITABLE_SETTING(Type, Name); \ + _BASE_INHERITABLE_SETTING(Type, Name); \ Microsoft.Terminal.Settings.Model.IAppearanceConfig Name##OverrideSource { get; } namespace Microsoft.Terminal.Settings.Model @@ -22,9 +22,7 @@ namespace Microsoft.Terminal.Settings.Model Vertical_Bottom = 0x20 }; - [flags] - enum IntenseStyle - { + [flags] enum IntenseStyle { Bold = 0x1, Bright = 0x2, All = 0xffffffff From b1c53424e16f1db67d386599252d666c51af9c15 Mon Sep 17 00:00:00 2001 From: Nicholas Bennett Date: Mon, 10 Oct 2022 14:48:09 -0700 Subject: [PATCH 05/20] updated bug, where custom themes would not update the color scheme --- .../TerminalSettings.cpp | 24 ++----------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 016097c501d..9decece5b90 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -195,7 +195,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation ApplyColorScheme(scheme); } } - else if (currentTheme.Name() == L"dark") + else if (Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark) { if (!appearance.DarkColorSchemeName().empty()) { @@ -205,27 +205,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation } } } - else if (currentTheme.Name() == L"light") - { - if (!appearance.LightColorSchemeName().empty()) - { - if (const auto scheme = schemes.TryLookup(appearance.LightColorSchemeName())) - { - ApplyColorScheme(scheme); - } - } - } - else if (currentTheme.Name() == L"system" && Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark) - { - if (!appearance.DarkColorSchemeName().empty()) - { - if (const auto scheme = schemes.TryLookup(appearance.DarkColorSchemeName())) - { - ApplyColorScheme(scheme); - } - } - } - else if (currentTheme.Name() == L"system" && Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Light) + else if (Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Light) { if (!appearance.LightColorSchemeName().empty()) { From e4f362579e62e57beab7c75b09484da5f2b712d5 Mon Sep 17 00:00:00 2001 From: Nicholas Bennett Date: Mon, 10 Oct 2022 17:32:49 -0700 Subject: [PATCH 06/20] updated bug, where custom themes would not update the color scheme --- .../TerminalSettings.cpp | 53 +++++++++++++++---- 1 file changed, 43 insertions(+), 10 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 9decece5b90..7fd7636b096 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -183,19 +183,38 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation return settingsPair; } - void TerminalSettings::_ApplyAppearanceSettings(const IAppearanceConfig& appearance, const Windows::Foundation::Collections::IMapView& schemes, const winrt::Microsoft::Terminal::Settings::Model::Theme currentTheme) + void TerminalSettings::_ApplyAppearanceSettings(const IAppearanceConfig& appearance, + const Windows::Foundation::Collections::IMapView& schemes, + const winrt::Microsoft::Terminal::Settings::Model::Theme currentTheme) { _CursorShape = appearance.CursorShape(); _CursorHeight = appearance.CursorHeight(); - // check if this setting update is coming from the UI. DarkColorSchemeName doesn't update till the save button is hit. This means if they differ, it is just the control preview that needs the update. - if (appearance.DarkColorSchemeName() != appearance.ColorSchemeName()) + // coming from UI or there is a bad colorscheme name + if (appearance.DarkColorSchemeName() != appearance.ColorSchemeName() && currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(2)) { if (const auto scheme = schemes.TryLookup(appearance.ColorSchemeName())) { ApplyColorScheme(scheme); } + else if (const auto defaultScheme = schemes.TryLookup(appearance.DarkColorSchemeName())) + { + ApplyColorScheme(defaultScheme); + } + } + // coming from UI or there is a bad colorscheme name + else if (appearance.DarkColorSchemeName() != appearance.ColorSchemeName() && currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(1)) + { + if (const auto scheme = schemes.TryLookup(appearance.ColorSchemeName())) + { + ApplyColorScheme(scheme); + } + else if (const auto defaultScheme = schemes.TryLookup(appearance.LightColorSchemeName())) + { + ApplyColorScheme(defaultScheme); + } } - else if (Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark) + // good color schemename + else if (currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(2)) { if (!appearance.DarkColorSchemeName().empty()) { @@ -205,14 +224,28 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation } } } - else if (Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Light) + // good color schemename + else if (currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(1)) { - if (!appearance.LightColorSchemeName().empty()) + if (const auto scheme = schemes.TryLookup(appearance.LightColorSchemeName())) { - if (const auto scheme = schemes.TryLookup(appearance.LightColorSchemeName())) - { - ApplyColorScheme(scheme); - } + ApplyColorScheme(scheme); + } + } + // good color schemename, but default app theme (apps way of saying check the system theme). This diverts to checking system theme + else if (currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(0) && Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark) + { + if (const auto scheme = schemes.TryLookup(appearance.DarkColorSchemeName())) + { + ApplyColorScheme(scheme); + } + } + // good color schemename, but default app theme (apps way of saying check the system theme). This diverts to checking system theme + else if (currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(0) && Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Light) + { + if (const auto scheme = schemes.TryLookup(appearance.LightColorSchemeName())) + { + ApplyColorScheme(scheme); } } if (appearance.Foreground()) From c16b998e6f9ccbfefd7fe37ef8cd8ec3b116cf65 Mon Sep 17 00:00:00 2001 From: Nicholas Bennett Date: Thu, 13 Oct 2022 12:57:57 -0700 Subject: [PATCH 07/20] PR lhecker comments --- .../AppearanceConfig.cpp | 8 +-- .../TerminalSettings.cpp | 61 +++++++------------ 2 files changed, 26 insertions(+), 43 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp index e9f4fcd2b6b..efe585859e8 100644 --- a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp @@ -56,7 +56,7 @@ Json::Value AppearanceConfig::ToJson() const JsonUtils::SetValueForKey(json, OpacityKey, _Opacity, JsonUtils::OptionalConverter{}); if (HasDarkColorSchemeName() && HasLightColorSchemeName()) { - // check if the setting is coming from the UI, if so grab the ColorSchemeName until the settings UI is fixed.. + // check if the setting is coming from the UI, if so grab the ColorSchemeName until the settings UI is fixed. if (_ColorSchemeName != _DarkColorSchemeName) { JsonUtils::SetValueForKey(json["colorScheme"], "dark", _ColorSchemeName); @@ -106,15 +106,15 @@ void AppearanceConfig::LayerJson(const Json::Value& json) { // to make the UI happy, set ColorSchemeName. JsonUtils::GetValueForKey(json, ColorSchemeKey, _ColorSchemeName); - JsonUtils::GetValueForKey(json, ColorSchemeKey, _DarkColorSchemeName); - JsonUtils::GetValueForKey(json, ColorSchemeKey, _LightColorSchemeName); + _DarkColorSchemeName = _ColorSchemeName; + _LightColorSchemeName = _ColorSchemeName; } else if (json["colorScheme"].isObject()) { // to make the UI happy, set ColorSchemeName to whatever the dark value is. - JsonUtils::GetValueForKey(json["colorScheme"], "dark", _ColorSchemeName); JsonUtils::GetValueForKey(json["colorScheme"], "dark", _DarkColorSchemeName); JsonUtils::GetValueForKey(json["colorScheme"], "light", _LightColorSchemeName); + _ColorSchemeName = _DarkColorSchemeName; } #define APPEARANCE_SETTINGS_LAYER_JSON(type, name, jsonKey, ...) \ diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 7fd7636b096..e488eb3cc79 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -189,61 +189,44 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation { _CursorShape = appearance.CursorShape(); _CursorHeight = appearance.CursorHeight(); - // coming from UI or there is a bad colorscheme name - if (appearance.DarkColorSchemeName() != appearance.ColorSchemeName() && currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(2)) - { - if (const auto scheme = schemes.TryLookup(appearance.ColorSchemeName())) - { - ApplyColorScheme(scheme); - } - else if (const auto defaultScheme = schemes.TryLookup(appearance.DarkColorSchemeName())) - { - ApplyColorScheme(defaultScheme); - } - } - // coming from UI or there is a bad colorscheme name - else if (appearance.DarkColorSchemeName() != appearance.ColorSchemeName() && currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(1)) + + const auto requestedTheme = currentTheme.RequestedTheme(); + const auto defaultName = appearance.ColorSchemeName(); + auto darkName = appearance.DarkColorSchemeName(); + auto lightName = appearance.LightColorSchemeName(); + + // If the darkName does not equal the default name, it means the setting change came from the UI or its a bad name. Either will process the same. + if (darkName != defaultName && requestedTheme != winrt::Windows::UI::Xaml::ElementTheme::Default) { - if (const auto scheme = schemes.TryLookup(appearance.ColorSchemeName())) + // if this is a bad name, move on to checking the theme to select the proper default color scheme name. + if (const auto scheme = schemes.TryLookup(defaultName)) { ApplyColorScheme(scheme); } - else if (const auto defaultScheme = schemes.TryLookup(appearance.LightColorSchemeName())) - { - ApplyColorScheme(defaultScheme); - } - } - // good color schemename - else if (currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(2)) - { - if (!appearance.DarkColorSchemeName().empty()) + else { - if (const auto scheme = schemes.TryLookup(appearance.DarkColorSchemeName())) + const auto& schemeName = requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Dark ? darkName : lightName; + if (const auto scheme = schemes.TryLookup(schemeName)) { ApplyColorScheme(scheme); } } + } - // good color schemename - else if (currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(1)) - { - if (const auto scheme = schemes.TryLookup(appearance.LightColorSchemeName())) - { - ApplyColorScheme(scheme); - } - } - // good color schemename, but default app theme (apps way of saying check the system theme). This diverts to checking system theme - else if (currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(0) && Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark) + // system theme selected, set the color scheme based off of the system theme. + else if(requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default) { - if (const auto scheme = schemes.TryLookup(appearance.DarkColorSchemeName())) + const auto& schemeName = Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark ? darkName : lightName; + if (const auto scheme = schemes.TryLookup(schemeName)) { ApplyColorScheme(scheme); } } - // good color schemename, but default app theme (apps way of saying check the system theme). This diverts to checking system theme - else if (currentTheme.RequestedTheme() == winrt::Windows::UI::Xaml::ElementTheme(0) && Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Light) + // application theme selected, set the color scheme based off of the system theme. + else { - if (const auto scheme = schemes.TryLookup(appearance.LightColorSchemeName())) + const auto schemeName = requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Dark ? darkName : lightName; + if (const auto scheme = schemes.TryLookup(schemeName)) { ApplyColorScheme(scheme); } From 4e40eff737581ce170dec788c51be6b2ef49396a Mon Sep 17 00:00:00 2001 From: Nicholas Bennett Date: Wed, 19 Oct 2022 07:57:43 -0700 Subject: [PATCH 08/20] formatting fix --- src/cascadia/TerminalSettingsModel/TerminalSettings.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index e488eb3cc79..1fd0a2c139b 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -211,7 +211,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation ApplyColorScheme(scheme); } } - } // system theme selected, set the color scheme based off of the system theme. else if(requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default) From 367d38ce145c48b8f04348f1257f3bde4f0f39b9 Mon Sep 17 00:00:00 2001 From: Nicholas Bennett Date: Thu, 20 Oct 2022 07:46:43 -0700 Subject: [PATCH 09/20] formatting fix --- src/cascadia/TerminalSettingsModel/TerminalSettings.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 1fd0a2c139b..0b6c54a399d 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -213,7 +213,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation } } // system theme selected, set the color scheme based off of the system theme. - else if(requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default) + else if (requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default) { const auto& schemeName = Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark ? darkName : lightName; if (const auto scheme = schemes.TryLookup(schemeName)) From 8e08d759faaf37db56c0af755f49ab79a3a4d8ce Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 15 Nov 2022 06:17:27 -0600 Subject: [PATCH 10/20] I think this is going to be way easier to manage --- .../TerminalControl/IControlAppearance.idl | 1 - .../TerminalSettingsEditor/Appearances.cpp | 37 ++++---- .../TerminalSettingsEditor/Appearances.h | 3 +- .../TerminalSettingsEditor/Appearances.idl | 6 +- .../TerminalSettingsEditor/Appearances.xaml | 5 +- .../ColorSchemeViewModel.cpp | 4 +- .../ColorSchemesPageViewModel.cpp | 3 +- .../AppearanceConfig.cpp | 27 +++--- .../TerminalSettingsModel/AppearanceConfig.h | 2 +- .../AzureCloudShellGenerator.cpp | 3 +- .../CascadiaSettings.cpp | 73 ++++++--------- .../TerminalSettingsModel/CascadiaSettings.h | 1 - .../CascadiaSettings.idl | 1 - .../IAppearanceConfig.idl | 3 +- .../PowershellCoreProfileGenerator.cpp | 3 +- .../TerminalSettings.cpp | 90 ++++++++++++------- .../TerminalSettingsModel/TerminalSettings.h | 1 - .../WslDistroGenerator.cpp | 3 +- src/cascadia/WindowsTerminal/IslandWindow.cpp | 5 ++ src/cascadia/inc/ControlProperties.h | 1 - 20 files changed, 148 insertions(+), 124 deletions(-) diff --git a/src/cascadia/TerminalControl/IControlAppearance.idl b/src/cascadia/TerminalControl/IControlAppearance.idl index 8cd18b2513e..96c3db75a11 100644 --- a/src/cascadia/TerminalControl/IControlAppearance.idl +++ b/src/cascadia/TerminalControl/IControlAppearance.idl @@ -14,7 +14,6 @@ namespace Microsoft.Terminal.Control // IntenseIsBold and IntenseIsBright are in Core Appearance Double Opacity { get; }; - String ColorSchemeName { get; }; // Experimental settings Boolean RetroTerminalEffect { get; }; String PixelShaderPath { get; }; diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.cpp b/src/cascadia/TerminalSettingsEditor/Appearances.cpp index 4b4b5a5a361..36f5f6ad0f5 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.cpp +++ b/src/cascadia/TerminalSettingsEditor/Appearances.cpp @@ -243,10 +243,11 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentCursorShape" }); _PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"IsVintageCursor" }); } - else if (settingName == L"ColorSchemeName") - { - _PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentColorScheme" }); - } + // TODO! + // else if (settingName == L"ColorSchemeName") + // { + // _PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentColorScheme" }); + // } else if (settingName == L"BackgroundImageStretchMode") { _PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentBackgroundImageStretchMode" }); @@ -355,22 +356,26 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation ColorScheme Appearances::CurrentColorScheme() { - const auto schemeName{ Appearance().ColorSchemeName() }; - if (const auto scheme{ Appearance().Schemes().TryLookup(schemeName) }) - { - return scheme; - } - else - { - // This Appearance points to a color scheme that was renamed or deleted. - // Fallback to Campbell. - return Appearance().Schemes().TryLookup(L"Campbell"); - } + // TODO! + return Appearance().Schemes().TryLookup(L"Campbell"); + + // const auto schemeName{ Appearance().ColorSchemeName() }; + // if (const auto scheme{ Appearance().Schemes().TryLookup(schemeName) }) + // { + // return scheme; + // } + // else + // { + // // This Appearance points to a color scheme that was renamed or deleted. + // // Fallback to Campbell. + // return Appearance().Schemes().TryLookup(L"Campbell"); + // } } void Appearances::CurrentColorScheme(const ColorScheme& val) { - Appearance().ColorSchemeName(val.Name()); + Appearance().DarkColorSchemeName(val.Name()); + Appearance().LightColorSchemeName(val.Name()); } bool Appearances::IsVintageCursor() const diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.h b/src/cascadia/TerminalSettingsEditor/Appearances.h index 207a1f8846a..2f67b03a9b2 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.h +++ b/src/cascadia/TerminalSettingsEditor/Appearances.h @@ -87,7 +87,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation OBSERVABLE_PROJECTED_SETTING(_appearance, RetroTerminalEffect); OBSERVABLE_PROJECTED_SETTING(_appearance, CursorShape); OBSERVABLE_PROJECTED_SETTING(_appearance, CursorHeight); - OBSERVABLE_PROJECTED_SETTING(_appearance, ColorSchemeName); + OBSERVABLE_PROJECTED_SETTING(_appearance, DarkColorSchemeName); + OBSERVABLE_PROJECTED_SETTING(_appearance, LightColorSchemeName); OBSERVABLE_PROJECTED_SETTING(_appearance, BackgroundImagePath); OBSERVABLE_PROJECTED_SETTING(_appearance, BackgroundImageOpacity); OBSERVABLE_PROJECTED_SETTING(_appearance, BackgroundImageStretchMode); diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.idl b/src/cascadia/TerminalSettingsEditor/Appearances.idl index 303e94b0d4a..3859f133ee7 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.idl +++ b/src/cascadia/TerminalSettingsEditor/Appearances.idl @@ -37,7 +37,8 @@ namespace Microsoft.Terminal.Settings.Editor OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Single, FontSize); OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Windows.UI.Text.FontWeight, FontWeight); - OBSERVABLE_PROJECTED_APPEARANCE_SETTING(String, ColorSchemeName); + OBSERVABLE_PROJECTED_APPEARANCE_SETTING(String, DarkColorSchemeName); + OBSERVABLE_PROJECTED_APPEARANCE_SETTING(String, LightColorSchemeName); OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Boolean, RetroTerminalEffect); OBSERVABLE_PROJECTED_APPEARANCE_SETTING(Microsoft.Terminal.Core.CursorStyle, CursorShape); OBSERVABLE_PROJECTED_APPEARANCE_SETTING(UInt32, CursorHeight); @@ -66,7 +67,8 @@ namespace Microsoft.Terminal.Settings.Editor IInspectable CurrentAdjustIndistinguishableColors; Windows.Foundation.Collections.IObservableVector AdjustIndistinguishableColorsList { get; }; - Microsoft.Terminal.Settings.Model.ColorScheme CurrentColorScheme; + // TODO! + // Microsoft.Terminal.Settings.Model.ColorScheme CurrentColorScheme; Windows.Foundation.Collections.IObservableVector ColorSchemeList { get; }; IInspectable CurrentBackgroundImageStretchMode; diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.xaml b/src/cascadia/TerminalSettingsEditor/Appearances.xaml index 8a6a5d45aa9..30ca933e566 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.xaml +++ b/src/cascadia/TerminalSettingsEditor/Appearances.xaml @@ -39,7 +39,8 @@ Style="{StaticResource TextBlockSubHeaderStyle}" /> - + (scheme) }; diff --git a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp index efe585859e8..5bec06ff979 100644 --- a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp @@ -33,7 +33,7 @@ winrt::com_ptr AppearanceConfig::CopyAppearance(const Appearan appearance->_SelectionBackground = source->_SelectionBackground; appearance->_CursorColor = source->_CursorColor; appearance->_Opacity = source->_Opacity; - appearance->_ColorSchemeName = source->_ColorSchemeName; + appearance->_DarkColorSchemeName = source->_DarkColorSchemeName; appearance->_LightColorSchemeName = source->_LightColorSchemeName; @@ -57,22 +57,21 @@ Json::Value AppearanceConfig::ToJson() const if (HasDarkColorSchemeName() && HasLightColorSchemeName()) { // check if the setting is coming from the UI, if so grab the ColorSchemeName until the settings UI is fixed. - if (_ColorSchemeName != _DarkColorSchemeName) + if (_LightColorSchemeName != _DarkColorSchemeName) { - JsonUtils::SetValueForKey(json["colorScheme"], "dark", _ColorSchemeName); - JsonUtils::SetValueForKey(json["colorScheme"], "light", _ColorSchemeName); + JsonUtils::SetValueForKey(json["colorScheme"], "dark", _DarkColorSchemeName); + JsonUtils::SetValueForKey(json["colorScheme"], "light", _LightColorSchemeName); } else { - JsonUtils::SetValueForKey(json["colorScheme"], "dark", _DarkColorSchemeName); - JsonUtils::SetValueForKey(json["colorScheme"], "light", _LightColorSchemeName); + JsonUtils::SetValueForKey(json, "colorScheme", _DarkColorSchemeName); } } - else if (HasColorSchemeName()) - { - JsonUtils::SetValueForKey(json["colorScheme"], "dark", _ColorSchemeName); - JsonUtils::SetValueForKey(json["colorScheme"], "light", _ColorSchemeName); - } + //else if (HasColorSchemeName()) + //{ + // JsonUtils::SetValueForKey(json["colorScheme"], "dark", _ColorSchemeName); + // JsonUtils::SetValueForKey(json["colorScheme"], "light", _ColorSchemeName); + //} #define APPEARANCE_SETTINGS_TO_JSON(type, name, jsonKey, ...) \ JsonUtils::SetValueForKey(json, jsonKey, _##name); @@ -105,16 +104,14 @@ void AppearanceConfig::LayerJson(const Json::Value& json) if (json["colorScheme"].isString()) { // to make the UI happy, set ColorSchemeName. - JsonUtils::GetValueForKey(json, ColorSchemeKey, _ColorSchemeName); - _DarkColorSchemeName = _ColorSchemeName; - _LightColorSchemeName = _ColorSchemeName; + JsonUtils::GetValueForKey(json, ColorSchemeKey, _DarkColorSchemeName); + _LightColorSchemeName = _DarkColorSchemeName; } else if (json["colorScheme"].isObject()) { // to make the UI happy, set ColorSchemeName to whatever the dark value is. JsonUtils::GetValueForKey(json["colorScheme"], "dark", _DarkColorSchemeName); JsonUtils::GetValueForKey(json["colorScheme"], "light", _LightColorSchemeName); - _ColorSchemeName = _DarkColorSchemeName; } #define APPEARANCE_SETTINGS_LAYER_JSON(type, name, jsonKey, ...) \ diff --git a/src/cascadia/TerminalSettingsModel/AppearanceConfig.h b/src/cascadia/TerminalSettingsModel/AppearanceConfig.h index 9fd8d96231f..7e8f35e6633 100644 --- a/src/cascadia/TerminalSettingsModel/AppearanceConfig.h +++ b/src/cascadia/TerminalSettingsModel/AppearanceConfig.h @@ -41,7 +41,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation INHERITABLE_NULLABLE_SETTING(Model::IAppearanceConfig, Microsoft::Terminal::Core::Color, SelectionBackground, nullptr); INHERITABLE_NULLABLE_SETTING(Model::IAppearanceConfig, Microsoft::Terminal::Core::Color, CursorColor, nullptr); INHERITABLE_SETTING(Model::IAppearanceConfig, double, Opacity, 1.0); - INHERITABLE_SETTING(Model::IAppearanceConfig, hstring, ColorSchemeName, L"Campbell"); + INHERITABLE_SETTING(Model::IAppearanceConfig, hstring, DarkColorSchemeName, L"Campbell"); INHERITABLE_SETTING(Model::IAppearanceConfig, hstring, LightColorSchemeName, L"Campbell"); diff --git a/src/cascadia/TerminalSettingsModel/AzureCloudShellGenerator.cpp b/src/cascadia/TerminalSettingsModel/AzureCloudShellGenerator.cpp index a69f44eaecf..948b1822f8c 100644 --- a/src/cascadia/TerminalSettingsModel/AzureCloudShellGenerator.cpp +++ b/src/cascadia/TerminalSettingsModel/AzureCloudShellGenerator.cpp @@ -31,7 +31,8 @@ void AzureCloudShellGenerator::GenerateProfiles(std::vectorStartingDirectory(winrt::hstring{ DEFAULT_STARTING_DIRECTORY }); - azureCloudShellProfile->DefaultAppearance().ColorSchemeName(L"Vintage"); + azureCloudShellProfile->DefaultAppearance().DarkColorSchemeName(L"Vintage"); + azureCloudShellProfile->DefaultAppearance().LightColorSchemeName(L"Vintage"); azureCloudShellProfile->ConnectionType(AzureConnection::ConnectionType()); profiles.emplace_back(std::move(azureCloudShellProfile)); } diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp index 9c1e4a473a8..5bee17d3d38 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp @@ -328,7 +328,6 @@ Model::Profile CascadiaSettings::DuplicateProfile(const Model::Profile& source) DUPLICATE_SETTING_MACRO_SUB(appearance, target, Opacity); DUPLICATE_SETTING_MACRO_SUB(appearance, target, DarkColorSchemeName); DUPLICATE_SETTING_MACRO_SUB(appearance, target, LightColorSchemeName); - DUPLICATE_SETTING_MACRO_SUB(appearance, target, ColorSchemeName); } // UnfocusedAppearance is treated as a single setting, @@ -947,24 +946,6 @@ bool CascadiaSettings::_hasInvalidColorScheme(const Model::Command& command) con return invalid; } -// Method Description: -// - Lookup the color scheme for a given profile. If the profile doesn't exist, -// or the scheme name listed in the profile doesn't correspond to a scheme, -// this will return `nullptr`. -// Arguments: -// - profileGuid: the GUID of the profile to find the scheme for. -// Return Value: -// - a non-owning pointer to the scheme. -Model::ColorScheme CascadiaSettings::GetColorSchemeForProfile(const Model::Profile& profile) const -{ - if (!profile) - { - return nullptr; - } - const auto schemeName = profile.DefaultAppearance().ColorSchemeName(); - return _globals->ColorSchemes().TryLookup(schemeName); -} - // Method Description: // - updates all references to that color scheme with the new name // Arguments: @@ -972,33 +953,35 @@ Model::ColorScheme CascadiaSettings::GetColorSchemeForProfile(const Model::Profi // - newName: the new name for the color scheme // Return Value: // - -void CascadiaSettings::UpdateColorSchemeReferences(const winrt::hstring& oldName, const winrt::hstring& newName) +void CascadiaSettings::UpdateColorSchemeReferences(const winrt::hstring& /*oldName*/, const winrt::hstring& /*newName*/) { - // update profiles.defaults, if necessary - if (_baseLayerProfile && - _baseLayerProfile->DefaultAppearance().HasColorSchemeName() && - _baseLayerProfile->DefaultAppearance().ColorSchemeName() == oldName) - { - _baseLayerProfile->DefaultAppearance().ColorSchemeName(newName); - } - - // update all profiles referencing this color scheme - for (const auto& profile : _allProfiles) - { - const auto defaultAppearance = profile.DefaultAppearance(); - if (defaultAppearance.HasColorSchemeName() && defaultAppearance.ColorSchemeName() == oldName) - { - defaultAppearance.ColorSchemeName(newName); - } - - if (profile.UnfocusedAppearance()) - { - if (profile.UnfocusedAppearance().HasColorSchemeName() && profile.UnfocusedAppearance().ColorSchemeName() == oldName) - { - profile.UnfocusedAppearance().ColorSchemeName(newName); - } - } - } + // TODO! + + // // update profiles.defaults, if necessary + // if (_baseLayerProfile && + // _baseLayerProfile->DefaultAppearance().HasColorSchemeName() && + // _baseLayerProfile->DefaultAppearance().ColorSchemeName() == oldName) + // { + // _baseLayerProfile->DefaultAppearance().ColorSchemeName(newName); + // } + + // // update all profiles referencing this color scheme + // for (const auto& profile : _allProfiles) + // { + // const auto defaultAppearance = profile.DefaultAppearance(); + // if (defaultAppearance.HasColorSchemeName() && defaultAppearance.ColorSchemeName() == oldName) + // { + // defaultAppearance.ColorSchemeName(newName); + // } + + // if (profile.UnfocusedAppearance()) + // { + // if (profile.UnfocusedAppearance().HasColorSchemeName() && profile.UnfocusedAppearance().ColorSchemeName() == oldName) + // { + // profile.UnfocusedAppearance().ColorSchemeName(newName); + // } + // } + // } } winrt::hstring CascadiaSettings::ApplicationDisplayName() diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.h b/src/cascadia/TerminalSettingsModel/CascadiaSettings.h index 85e594f9656..1eb84f6c1eb 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.h +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.h @@ -124,7 +124,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation Model::Profile ProfileDefaults() const; Model::Profile CreateNewProfile(); Model::Profile FindProfile(const winrt::guid& guid) const noexcept; - Model::ColorScheme GetColorSchemeForProfile(const Model::Profile& profile) const; void UpdateColorSchemeReferences(const winrt::hstring& oldName, const winrt::hstring& newName); Model::Profile GetProfileForArgs(const Model::NewTerminalArgs& newTerminalArgs) const; Model::Profile GetProfileByName(const winrt::hstring& name) const; diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettings.idl b/src/cascadia/TerminalSettingsModel/CascadiaSettings.idl index fb69e58ffc8..5a1987dcf3e 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettings.idl +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettings.idl @@ -45,7 +45,6 @@ namespace Microsoft.Terminal.Settings.Model Profile CreateNewProfile(); Profile FindProfile(Guid profileGuid); - ColorScheme GetColorSchemeForProfile(Profile profile); void UpdateColorSchemeReferences(String oldName, String newName); Profile GetProfileForArgs(NewTerminalArgs newTerminalArgs); diff --git a/src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl b/src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl index 94fa06da0da..6352de64b08 100644 --- a/src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl +++ b/src/cascadia/TerminalSettingsModel/IAppearanceConfig.idl @@ -31,9 +31,10 @@ namespace Microsoft.Terminal.Settings.Model interface IAppearanceConfig { Microsoft.Terminal.Settings.Model.Profile SourceProfile { get; }; - INHERITABLE_APPEARANCE_SETTING(String, ColorSchemeName); + INHERITABLE_APPEARANCE_SETTING(String, DarkColorSchemeName); INHERITABLE_APPEARANCE_SETTING(String, LightColorSchemeName); + INHERITABLE_APPEARANCE_SETTING(Windows.Foundation.IReference, Foreground); INHERITABLE_APPEARANCE_SETTING(Windows.Foundation.IReference, Background); INHERITABLE_APPEARANCE_SETTING(Windows.Foundation.IReference, SelectionBackground); diff --git a/src/cascadia/TerminalSettingsModel/PowershellCoreProfileGenerator.cpp b/src/cascadia/TerminalSettingsModel/PowershellCoreProfileGenerator.cpp index 5db52c810b6..ae04753a73c 100644 --- a/src/cascadia/TerminalSettingsModel/PowershellCoreProfileGenerator.cpp +++ b/src/cascadia/TerminalSettingsModel/PowershellCoreProfileGenerator.cpp @@ -319,7 +319,8 @@ void PowershellCoreProfileGenerator::GenerateProfiles(std::vectorCommandline(winrt::hstring{ quotedCommandline }); profile->StartingDirectory(winrt::hstring{ DEFAULT_STARTING_DIRECTORY }); - profile->DefaultAppearance().ColorSchemeName(L"Campbell"); + profile->DefaultAppearance().DarkColorSchemeName(L"Campbell"); + profile->DefaultAppearance().LightColorSchemeName(L"Campbell"); profile->Icon(winrt::hstring{ WI_IsFlagSet(psI.flags, PowerShellFlags::Preview) ? POWERSHELL_PREVIEW_ICON : POWERSHELL_ICON }); if (first) diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 0b6c54a399d..48a067e5a37 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -190,46 +190,75 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation _CursorShape = appearance.CursorShape(); _CursorHeight = appearance.CursorHeight(); - const auto requestedTheme = currentTheme.RequestedTheme(); - const auto defaultName = appearance.ColorSchemeName(); - auto darkName = appearance.DarkColorSchemeName(); - auto lightName = appearance.LightColorSchemeName(); - - // If the darkName does not equal the default name, it means the setting change came from the UI or its a bad name. Either will process the same. - if (darkName != defaultName && requestedTheme != winrt::Windows::UI::Xaml::ElementTheme::Default) + // const auto requestedTheme = currentTheme.RequestedTheme(); + // const auto defaultName = appearance.ColorSchemeName(); + // auto darkName = appearance.DarkColorSchemeName(); + // auto lightName = appearance.LightColorSchemeName(); + + // // If the darkName does not equal the default name, it means the setting change came from the UI or its a bad name. Either will process the same. + // if (darkName != defaultName && requestedTheme != winrt::Windows::UI::Xaml::ElementTheme::Default) + // { + // // if this is a bad name, move on to checking the theme to select the proper default color scheme name. + // if (const auto scheme = schemes.TryLookup(defaultName)) + // { + // ApplyColorScheme(scheme); + // } + // else + // { + // const auto& schemeName = requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Dark ? darkName : lightName; + // if (const auto scheme = schemes.TryLookup(schemeName)) + // { + // ApplyColorScheme(scheme); + // } + // } + // } + // // system theme selected, set the color scheme based off of the system theme. + // else if (requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default) + // { + // const auto& schemeName = Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark ? darkName : lightName; + // if (const auto scheme = schemes.TryLookup(schemeName)) + // { + // ApplyColorScheme(scheme); + // } + // } + // // application theme selected, set the color scheme based off of the system theme. + // else + // { + // const auto schemeName = requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Dark ? darkName : lightName; + // if (const auto scheme = schemes.TryLookup(schemeName)) + // { + // ApplyColorScheme(scheme); + // } + // } + + auto requestedTheme = currentTheme.RequestedTheme(); + if (requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default) { - // if this is a bad name, move on to checking the theme to select the proper default color scheme name. - if (const auto scheme = schemes.TryLookup(defaultName)) - { - ApplyColorScheme(scheme); - } - else - { - const auto& schemeName = requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Dark ? darkName : lightName; - if (const auto scheme = schemes.TryLookup(schemeName)) - { - ApplyColorScheme(scheme); - } - } + // TODO! make sure local tests don't explode + requestedTheme = Windows::UI::Xaml::Application::Current().RequestedTheme() == winrt::Windows::UI::Xaml::ApplicationTheme::Dark ? + winrt::Windows::UI::Xaml::ElementTheme::Dark : + winrt::Windows::UI::Xaml::ElementTheme::Light; } - // system theme selected, set the color scheme based off of the system theme. - else if (requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default) + + switch (requestedTheme) { - const auto& schemeName = Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark ? darkName : lightName; - if (const auto scheme = schemes.TryLookup(schemeName)) + case winrt::Windows::UI::Xaml::ElementTheme::Light: + if (const auto scheme = schemes.TryLookup(appearance.LightColorSchemeName())) { ApplyColorScheme(scheme); } - } - // application theme selected, set the color scheme based off of the system theme. - else - { - const auto schemeName = requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Dark ? darkName : lightName; - if (const auto scheme = schemes.TryLookup(schemeName)) + break; + case winrt::Windows::UI::Xaml::ElementTheme::Dark: + if (const auto scheme = schemes.TryLookup(appearance.DarkColorSchemeName())) { ApplyColorScheme(scheme); } + break; + case winrt::Windows::UI::Xaml::ElementTheme::Default: + // This shouldn't happen! + break; } + if (appearance.Foreground()) { _DefaultForeground = til::color{ appearance.Foreground().Value() }; @@ -366,7 +395,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation else { AppliedColorScheme(scheme); - ColorSchemeName(scheme.Name()); _DefaultForeground = til::color{ scheme.Foreground() }; _DefaultBackground = til::color{ scheme.Background() }; _SelectionBackground = til::color{ scheme.SelectionBackground() }; diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.h b/src/cascadia/TerminalSettingsModel/TerminalSettings.h index 84b62177935..e92ce3aeed9 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.h +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.h @@ -128,7 +128,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation INHERITABLE_SETTING(Model::TerminalSettings, IFontFeatureMap, FontFeatures); INHERITABLE_SETTING(Model::TerminalSettings, Model::ColorScheme, AppliedColorScheme); - INHERITABLE_SETTING(Model::TerminalSettings, hstring, ColorSchemeName); INHERITABLE_SETTING(Model::TerminalSettings, hstring, BackgroundImage); INHERITABLE_SETTING(Model::TerminalSettings, double, BackgroundImageOpacity, 1.0); diff --git a/src/cascadia/TerminalSettingsModel/WslDistroGenerator.cpp b/src/cascadia/TerminalSettingsModel/WslDistroGenerator.cpp index 840835cf1f3..373282866a6 100644 --- a/src/cascadia/TerminalSettingsModel/WslDistroGenerator.cpp +++ b/src/cascadia/TerminalSettingsModel/WslDistroGenerator.cpp @@ -53,7 +53,8 @@ static winrt::com_ptr makeProfile(const std::wstring& d std::wstring command{}; THROW_IF_FAILED(wil::GetSystemDirectoryW(command)); WSLDistro->Commandline(winrt::hstring{ command + L"\\wsl.exe -d " + distName }); - WSLDistro->DefaultAppearance().ColorSchemeName(L"Campbell"); + WSLDistro->DefaultAppearance().DarkColorSchemeName(L"Campbell"); + WSLDistro->DefaultAppearance().LightColorSchemeName(L"Campbell"); if (isWslDashDashCdAvailableForLinuxPaths()) { WSLDistro->StartingDirectory(winrt::hstring{ WslHomeDirectory }); diff --git a/src/cascadia/WindowsTerminal/IslandWindow.cpp b/src/cascadia/WindowsTerminal/IslandWindow.cpp index cb3425c1eff..1bb33529e1d 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/IslandWindow.cpp @@ -658,6 +658,11 @@ long IslandWindow::_calculateTotalSize(const bool isWidth, const long clientSize } break; } + case WM_SETTINGCHANGE: + { + // TODO! + break; + } case WM_ENDSESSION: { // For WM_QUERYENDSESSION and WM_ENDSESSION, refer to: diff --git a/src/cascadia/inc/ControlProperties.h b/src/cascadia/inc/ControlProperties.h index 1a5efc0e1bf..8132d579e59 100644 --- a/src/cascadia/inc/ControlProperties.h +++ b/src/cascadia/inc/ControlProperties.h @@ -20,7 +20,6 @@ #define CONTROL_APPEARANCE_SETTINGS(X) \ X(til::color, SelectionBackground, DEFAULT_FOREGROUND) \ X(double, Opacity, 1.0) \ - X(winrt::hstring, ColorSchemeName, L"Campbell") \ X(winrt::hstring, BackgroundImage) \ X(double, BackgroundImageOpacity, 1.0) \ X(winrt::Windows::UI::Xaml::Media::Stretch, BackgroundImageStretchMode, winrt::Windows::UI::Xaml::Media::Stretch::UniformToFill) \ From a0e28f1a6aecdd4d7f5ee9af091aac31197430ce Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 15 Nov 2022 12:16:03 -0600 Subject: [PATCH 11/20] UI is better. Not good, but better --- .../TerminalSettingsEditor/Appearances.cpp | 25 ++++++++----------- .../TerminalSettingsEditor/Appearances.idl | 3 +-- .../TerminalSettingsEditor/Appearances.xaml | 10 ++++---- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.cpp b/src/cascadia/TerminalSettingsEditor/Appearances.cpp index 36f5f6ad0f5..8a953799b53 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.cpp +++ b/src/cascadia/TerminalSettingsEditor/Appearances.cpp @@ -356,20 +356,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation ColorScheme Appearances::CurrentColorScheme() { - // TODO! - return Appearance().Schemes().TryLookup(L"Campbell"); - - // const auto schemeName{ Appearance().ColorSchemeName() }; - // if (const auto scheme{ Appearance().Schemes().TryLookup(schemeName) }) - // { - // return scheme; - // } - // else - // { - // // This Appearance points to a color scheme that was renamed or deleted. - // // Fallback to Campbell. - // return Appearance().Schemes().TryLookup(L"Campbell"); - // } + const auto schemeName{ Appearance().DarkColorSchemeName() }; + if (const auto scheme{ Appearance().Schemes().TryLookup(schemeName) }) + { + return scheme; + } + else + { + // This Appearance points to a color scheme that was renamed or deleted. + // Fallback to Campbell. + return Appearance().Schemes().TryLookup(L"Campbell"); + } } void Appearances::CurrentColorScheme(const ColorScheme& val) diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.idl b/src/cascadia/TerminalSettingsEditor/Appearances.idl index 3859f133ee7..e31f7e41703 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.idl +++ b/src/cascadia/TerminalSettingsEditor/Appearances.idl @@ -67,8 +67,7 @@ namespace Microsoft.Terminal.Settings.Editor IInspectable CurrentAdjustIndistinguishableColors; Windows.Foundation.Collections.IObservableVector AdjustIndistinguishableColorsList { get; }; - // TODO! - // Microsoft.Terminal.Settings.Model.ColorScheme CurrentColorScheme; + Microsoft.Terminal.Settings.Model.ColorScheme CurrentColorScheme; Windows.Foundation.Collections.IObservableVector ColorSchemeList { get; }; IInspectable CurrentBackgroundImageStretchMode; diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.xaml b/src/cascadia/TerminalSettingsEditor/Appearances.xaml index 30ca933e566..23524b75f4b 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.xaml +++ b/src/cascadia/TerminalSettingsEditor/Appearances.xaml @@ -40,10 +40,10 @@ - + Date: Tue, 15 Nov 2022 13:23:40 -0600 Subject: [PATCH 12/20] hot reloading --- src/cascadia/TerminalApp/AppLogic.cpp | 6 +++--- src/cascadia/TerminalApp/AppLogic.h | 3 ++- src/cascadia/TerminalApp/AppLogic.idl | 1 + src/cascadia/WindowsTerminal/AppHost.cpp | 1 + src/cascadia/WindowsTerminal/IslandWindow.cpp | 9 ++++++++- src/cascadia/WindowsTerminal/IslandWindow.h | 1 + 6 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index 7062bfd73a9..e2a4e701960 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -191,7 +191,7 @@ namespace winrt::TerminalApp::implementation _reloadSettings = std::make_shared>(winrt::Windows::System::DispatcherQueue::GetForCurrentThread(), std::chrono::milliseconds(100), [weakSelf = get_weak()]() { if (auto self{ weakSelf.get() }) { - self->_ReloadSettings(); + self->ReloadSettings(); } }); @@ -920,7 +920,7 @@ namespace winrt::TerminalApp::implementation // Method Description: // - Registers for changes to the settings folder and upon a updated settings - // profile calls _ReloadSettings(). + // profile calls ReloadSettings(). // Arguments: // - // Return Value: @@ -1055,7 +1055,7 @@ namespace winrt::TerminalApp::implementation // Method Description: // - Reloads the settings from the settings.json file. - void AppLogic::_ReloadSettings() + void AppLogic::ReloadSettings() { // Attempt to load our settings. // If it fails, diff --git a/src/cascadia/TerminalApp/AppLogic.h b/src/cascadia/TerminalApp/AppLogic.h index f4abe8254f2..3a84651a48a 100644 --- a/src/cascadia/TerminalApp/AppLogic.h +++ b/src/cascadia/TerminalApp/AppLogic.h @@ -63,6 +63,8 @@ namespace winrt::TerminalApp::implementation void RunAsUwp(); bool IsElevated() const noexcept; void LoadSettings(); + void ReloadSettings(); + [[nodiscard]] Microsoft::Terminal::Settings::Model::CascadiaSettings GetSettings() const noexcept; void Quit(); @@ -195,7 +197,6 @@ namespace winrt::TerminalApp::implementation void _ProcessLazySettingsChanges(); void _RegisterSettingsChange(); fire_and_forget _DispatchReloadSettings(); - void _ReloadSettings(); void _OpenSettingsUI(); bool _hasCommandLineArguments{ false }; diff --git a/src/cascadia/TerminalApp/AppLogic.idl b/src/cascadia/TerminalApp/AppLogic.idl index 0f77af0c8cd..aebd07e1165 100644 --- a/src/cascadia/TerminalApp/AppLogic.idl +++ b/src/cascadia/TerminalApp/AppLogic.idl @@ -60,6 +60,7 @@ namespace TerminalApp void Quit(); void LoadSettings(); + void ReloadSettings(); Windows.UI.Xaml.UIElement GetRoot(); void SetInboundListener(); diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index 90524d9a148..4ab2d0031bd 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -390,6 +390,7 @@ void AppHost::Initialize() _window->DragRegionClicked([this]() { _logic.TitlebarClicked(); }); _window->WindowVisibilityChanged([this](bool showOrHide) { _logic.WindowVisibilityChanged(showOrHide); }); + _window->UpdateSettingsRequested([this]() { _logic.ReloadSettings(); }); _revokers.RequestedThemeChanged = _logic.RequestedThemeChanged(winrt::auto_revoke, { this, &AppHost::_UpdateTheme }); _revokers.FullscreenChanged = _logic.FullscreenChanged(winrt::auto_revoke, { this, &AppHost::_FullscreenChanged }); diff --git a/src/cascadia/WindowsTerminal/IslandWindow.cpp b/src/cascadia/WindowsTerminal/IslandWindow.cpp index 1bb33529e1d..7be498f7232 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/IslandWindow.cpp @@ -660,7 +660,14 @@ long IslandWindow::_calculateTotalSize(const bool isWidth, const long clientSize } case WM_SETTINGCHANGE: { - // TODO! + const std::wstring param{ (wchar_t*)lparam }; + // ImmersiveColorSet seems to be the notification that the OS theme + // changed. If that happens, let the app know, so it can hot-reload + // themes, color schemes that might depend on the OS theme + if (param == L"ImmersiveColorSet") + { + _UpdateSettingsRequestedHandlers(); + } break; } case WM_ENDSESSION: diff --git a/src/cascadia/WindowsTerminal/IslandWindow.h b/src/cascadia/WindowsTerminal/IslandWindow.h index 396bfd04b84..2f8a2dd6457 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.h +++ b/src/cascadia/WindowsTerminal/IslandWindow.h @@ -81,6 +81,7 @@ class IslandWindow : WINRT_CALLBACK(WindowMoved, winrt::delegate); WINRT_CALLBACK(WindowVisibilityChanged, winrt::delegate); + WINRT_CALLBACK(UpdateSettingsRequested, winrt::delegate); protected: void ForceResize() From 1b81da9648f903f9d2cf547f19a06904a6e480af Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 15 Nov 2022 14:15:48 -0600 Subject: [PATCH 13/20] cleanup some todos --- .../TerminalSettingsEditor/Appearances.cpp | 9 ++- .../TerminalSettingsEditor/Appearances.xaml | 2 +- .../CascadiaSettings.cpp | 69 +++++++++++-------- .../TerminalSettings.cpp | 41 ----------- 4 files changed, 46 insertions(+), 75 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.cpp b/src/cascadia/TerminalSettingsEditor/Appearances.cpp index 8a953799b53..ef77b5f6f73 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.cpp +++ b/src/cascadia/TerminalSettingsEditor/Appearances.cpp @@ -243,11 +243,10 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation _PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentCursorShape" }); _PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"IsVintageCursor" }); } - // TODO! - // else if (settingName == L"ColorSchemeName") - // { - // _PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentColorScheme" }); - // } + else if (settingName == L"DarkColorSchemeName" || settingName == L"LightColorSchemeName") + { + _PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentColorScheme" }); + } else if (settingName == L"BackgroundImageStretchMode") { _PropertyChangedHandlers(*this, PropertyChangedEventArgs{ L"CurrentBackgroundImageStretchMode" }); diff --git a/src/cascadia/TerminalSettingsEditor/Appearances.xaml b/src/cascadia/TerminalSettingsEditor/Appearances.xaml index 23524b75f4b..9bed48c7ef5 100644 --- a/src/cascadia/TerminalSettingsEditor/Appearances.xaml +++ b/src/cascadia/TerminalSettingsEditor/Appearances.xaml @@ -39,7 +39,7 @@ Style="{StaticResource TextBlockSubHeaderStyle}" /> - + -void CascadiaSettings::UpdateColorSchemeReferences(const winrt::hstring& /*oldName*/, const winrt::hstring& /*newName*/) +void CascadiaSettings::UpdateColorSchemeReferences(const winrt::hstring& oldName, const winrt::hstring& newName) { - // TODO! - - // // update profiles.defaults, if necessary - // if (_baseLayerProfile && - // _baseLayerProfile->DefaultAppearance().HasColorSchemeName() && - // _baseLayerProfile->DefaultAppearance().ColorSchemeName() == oldName) - // { - // _baseLayerProfile->DefaultAppearance().ColorSchemeName(newName); - // } - - // // update all profiles referencing this color scheme - // for (const auto& profile : _allProfiles) - // { - // const auto defaultAppearance = profile.DefaultAppearance(); - // if (defaultAppearance.HasColorSchemeName() && defaultAppearance.ColorSchemeName() == oldName) - // { - // defaultAppearance.ColorSchemeName(newName); - // } - - // if (profile.UnfocusedAppearance()) - // { - // if (profile.UnfocusedAppearance().HasColorSchemeName() && profile.UnfocusedAppearance().ColorSchemeName() == oldName) - // { - // profile.UnfocusedAppearance().ColorSchemeName(newName); - // } - // } - // } + // update profiles.defaults, if necessary + if (_baseLayerProfile && + _baseLayerProfile->DefaultAppearance().HasDarkColorSchemeName() && + _baseLayerProfile->DefaultAppearance().DarkColorSchemeName() == oldName) + { + _baseLayerProfile->DefaultAppearance().DarkColorSchemeName(newName); + } + // NOT else-if, because both could match + if (_baseLayerProfile && + _baseLayerProfile->DefaultAppearance().HasLightColorSchemeName() && + _baseLayerProfile->DefaultAppearance().LightColorSchemeName() == oldName) + { + _baseLayerProfile->DefaultAppearance().LightColorSchemeName(newName); + } + + // update all profiles referencing this color scheme + for (const auto& profile : _allProfiles) + { + const auto defaultAppearance = profile.DefaultAppearance(); + if (defaultAppearance.HasLightColorSchemeName() && defaultAppearance.LightColorSchemeName() == oldName) + { + defaultAppearance.LightColorSchemeName(newName); + } + if (defaultAppearance.HasDarkColorSchemeName() && defaultAppearance.DarkColorSchemeName() == oldName) + { + defaultAppearance.DarkColorSchemeName(newName); + } + + if (auto unfocused{ profile.UnfocusedAppearance() }) + { + if (unfocused.HasLightColorSchemeName() && unfocused.LightColorSchemeName() == oldName) + { + unfocused.LightColorSchemeName(newName); + } + if (unfocused.HasDarkColorSchemeName() && unfocused.DarkColorSchemeName() == oldName) + { + unfocused.DarkColorSchemeName(newName); + } + } + } } winrt::hstring CascadiaSettings::ApplicationDisplayName() diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index 48a067e5a37..db3b7159764 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -190,47 +190,6 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation _CursorShape = appearance.CursorShape(); _CursorHeight = appearance.CursorHeight(); - // const auto requestedTheme = currentTheme.RequestedTheme(); - // const auto defaultName = appearance.ColorSchemeName(); - // auto darkName = appearance.DarkColorSchemeName(); - // auto lightName = appearance.LightColorSchemeName(); - - // // If the darkName does not equal the default name, it means the setting change came from the UI or its a bad name. Either will process the same. - // if (darkName != defaultName && requestedTheme != winrt::Windows::UI::Xaml::ElementTheme::Default) - // { - // // if this is a bad name, move on to checking the theme to select the proper default color scheme name. - // if (const auto scheme = schemes.TryLookup(defaultName)) - // { - // ApplyColorScheme(scheme); - // } - // else - // { - // const auto& schemeName = requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Dark ? darkName : lightName; - // if (const auto scheme = schemes.TryLookup(schemeName)) - // { - // ApplyColorScheme(scheme); - // } - // } - // } - // // system theme selected, set the color scheme based off of the system theme. - // else if (requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default) - // { - // const auto& schemeName = Windows::UI::Xaml::Application::Current().RequestedTheme() == Windows::UI::Xaml::ApplicationTheme::Dark ? darkName : lightName; - // if (const auto scheme = schemes.TryLookup(schemeName)) - // { - // ApplyColorScheme(scheme); - // } - // } - // // application theme selected, set the color scheme based off of the system theme. - // else - // { - // const auto schemeName = requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Dark ? darkName : lightName; - // if (const auto scheme = schemes.TryLookup(schemeName)) - // { - // ApplyColorScheme(scheme); - // } - // } - auto requestedTheme = currentTheme.RequestedTheme(); if (requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default) { From d71c56e3f170b67d672600dcaf2d8c452d46b2be Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 15 Nov 2022 14:34:02 -0600 Subject: [PATCH 14/20] schema too folks --- doc/cascadia/profiles.schema.json | 33 +++++++++++++++++-- .../AppearanceConfig.cpp | 5 --- .../TerminalSettingsModel/defaults.json | 22 +++++++++++++ 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/doc/cascadia/profiles.schema.json b/doc/cascadia/profiles.schema.json index 6366468e689..ea990d17f6f 100644 --- a/doc/cascadia/profiles.schema.json +++ b/doc/cascadia/profiles.schema.json @@ -82,7 +82,14 @@ "properties": { "colorScheme": { "description": "The name of a color scheme to use when unfocused.", - "type": "string" + "oneOf": [ + { + "$ref": "#/$defs/SchemePair" + }, + { + "type": "string" + } + ] }, "foreground": { "$ref": "#/$defs/Color", @@ -233,6 +240,21 @@ }, "type": "object" }, + "SchemePair": { + "description": "Contains both a light and dark color scheme for the Terminal to use, depending on the theme of the application.", + "properties": { + "light": { + "default": "Campbell", + "description": "Name of the scheme to use when the app is using light theme", + "type": "string" + }, + "dark": { + "default": "Campbell", + "description": "Name of the scheme to use when the app is using dark theme", + "type": "string" + }, + } + }, "FontConfig": { "properties": { "face": { @@ -2170,7 +2192,14 @@ "colorScheme": { "default": "Campbell", "description": "Name of the terminal color scheme to use. Color schemes are defined under \"schemes\".", - "type": "string" + "oneOf": [ + { + "$ref": "#/$defs/SchemePair" + }, + { + "type": "string" + } + ] }, "commandline": { "description": "Executable used in the profile.", diff --git a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp index 5bec06ff979..4aecd33be14 100644 --- a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp @@ -67,11 +67,6 @@ Json::Value AppearanceConfig::ToJson() const JsonUtils::SetValueForKey(json, "colorScheme", _DarkColorSchemeName); } } - //else if (HasColorSchemeName()) - //{ - // JsonUtils::SetValueForKey(json["colorScheme"], "dark", _ColorSchemeName); - // JsonUtils::SetValueForKey(json["colorScheme"], "light", _ColorSchemeName); - //} #define APPEARANCE_SETTINGS_TO_JSON(type, name, jsonKey, ...) \ JsonUtils::SetValueForKey(json, jsonKey, _##name); diff --git a/src/cascadia/TerminalSettingsModel/defaults.json b/src/cascadia/TerminalSettingsModel/defaults.json index 59a7f231c81..efe709a42ab 100644 --- a/src/cascadia/TerminalSettingsModel/defaults.json +++ b/src/cascadia/TerminalSettingsModel/defaults.json @@ -103,6 +103,28 @@ "brightCyan": "#61D6D6", "brightWhite": "#F2F2F2" }, + { + "name": "Campbell Light", + "foreground": "#0C0C0C", + "background": "#CCCCCC", + "cursorColor": "#000000", + "black": "#0C0C0C", + "red": "#C50F1F", + "green": "#13A10E", + "yellow": "#C19C00", + "blue": "#0037DA", + "purple": "#881798", + "cyan": "#3A96DD", + "white": "#CCCCCC", + "brightBlack": "#767676", + "brightRed": "#E74856", + "brightGreen": "#16C60C", + "brightYellow": "#F9F1A5", + "brightBlue": "#3B78FF", + "brightPurple": "#B4009E", + "brightCyan": "#61D6D6", + "brightWhite": "#F2F2F2" + }, { "name": "Campbell Powershell", "foreground": "#CCCCCC", From e70ac1899e16644cd1d9da2018556c0faf484225 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 15 Nov 2022 16:30:55 -0600 Subject: [PATCH 15/20] goodbye LoadSettings, ReloadSettings is my best friend now --- src/cascadia/TerminalApp/App.cpp | 2 +- src/cascadia/TerminalApp/AppLogic.cpp | 84 +++++++++++++-------------- src/cascadia/TerminalApp/AppLogic.h | 1 - src/cascadia/TerminalApp/AppLogic.idl | 1 - 4 files changed, 40 insertions(+), 48 deletions(-) diff --git a/src/cascadia/TerminalApp/App.cpp b/src/cascadia/TerminalApp/App.cpp index c143f2eceda..4d7e5f93763 100644 --- a/src/cascadia/TerminalApp/App.cpp +++ b/src/cascadia/TerminalApp/App.cpp @@ -54,7 +54,7 @@ namespace winrt::TerminalApp::implementation { auto logic = Logic(); logic.RunAsUwp(); // Must set UWP status first, settings might change based on it. - logic.LoadSettings(); + logic.ReloadSettings(); logic.Create(); auto page = logic.GetRoot().as(); diff --git a/src/cascadia/TerminalApp/AppLogic.cpp b/src/cascadia/TerminalApp/AppLogic.cpp index e2a4e701960..040c39d29d1 100644 --- a/src/cascadia/TerminalApp/AppLogic.cpp +++ b/src/cascadia/TerminalApp/AppLogic.cpp @@ -615,7 +615,7 @@ namespace winrt::TerminalApp::implementation if (!_loadedInitialSettings) { // Load settings if we haven't already - LoadSettings(); + ReloadSettings(); } winrt::Windows::Foundation::Size proposedSize{}; @@ -696,7 +696,7 @@ namespace winrt::TerminalApp::implementation if (!_loadedInitialSettings) { // Load settings if we haven't already - LoadSettings(); + ReloadSettings(); } // GH#4620/#5801 - If the user passed --maximized or --fullscreen on the @@ -730,7 +730,7 @@ namespace winrt::TerminalApp::implementation if (!_loadedInitialSettings) { // Load settings if we haven't already - LoadSettings(); + ReloadSettings(); } auto initialPosition{ _settings.GlobalSettings().InitialPosition() }; @@ -760,7 +760,7 @@ namespace winrt::TerminalApp::implementation if (!_loadedInitialSettings) { // Load settings if we haven't already - LoadSettings(); + ReloadSettings(); } // If the position has been specified on the commandline, don't center on launch return _settings.GlobalSettings().CenterOnLaunch() && !_appArgs.GetPosition().has_value(); @@ -776,7 +776,7 @@ namespace winrt::TerminalApp::implementation if (!_loadedInitialSettings) { // Load settings if we haven't already - LoadSettings(); + ReloadSettings(); } return _settings.GlobalSettings().ShowTabsInTitlebar(); @@ -787,7 +787,7 @@ namespace winrt::TerminalApp::implementation if (!_loadedInitialSettings) { // Load settings if we haven't already - LoadSettings(); + ReloadSettings(); } return _settings.GlobalSettings().AlwaysOnTop(); @@ -867,36 +867,6 @@ namespace winrt::TerminalApp::implementation return hr; } - // Method Description: - // - Initialized our settings. See CascadiaSettings for more details. - // Additionally hooks up our callbacks for keybinding events to the - // keybindings object. - // NOTE: This must be called from a MTA if we're running as a packaged - // application. The Windows.Storage APIs require a MTA. If this isn't - // happening during startup, it'll need to happen on a background thread. - void AppLogic::LoadSettings() - { - // Attempt to load the settings. - // If it fails, - // - use Default settings, - // - don't persist them (LoadAll won't save them in this case). - // - _settingsLoadedResult will be set to an error, indicating that - // we should display the loading error. - // * We can't display the error now, because we might not have a - // UI yet. We'll display the error in _OnLoaded. - _settingsLoadedResult = _TryLoadSettings(); - - if (FAILED(_settingsLoadedResult)) - { - _settings = CascadiaSettings::LoadDefaults(); - } - - _loadedInitialSettings = true; - - // Register for directory change notification. - _RegisterSettingsChange(); - } - // Call this function after loading your _settings. // It handles any CPU intensive settings updates (like updating the Jumplist) // which should thus only occur if the settings file actually changed. @@ -1055,6 +1025,13 @@ namespace winrt::TerminalApp::implementation // Method Description: // - Reloads the settings from the settings.json file. + // - When this is called the first time, this initializes our settings. See + // CascadiaSettings for more details. Additionally hooks up our callbacks + // for keybinding events to the keybindings object. + // - NOTE: when called initially, this must be called from a MTA if we're + // running as a packaged application. The Windows.Storage APIs require a + // MTA. If this isn't happening during startup, it'll need to happen on + // a background thread. void AppLogic::ReloadSettings() { // Attempt to load our settings. @@ -1064,11 +1041,28 @@ namespace winrt::TerminalApp::implementation // - display a loading error _settingsLoadedResult = _TryLoadSettings(); + const auto initialLoad = !_loadedInitialSettings; + _loadedInitialSettings = true; + if (FAILED(_settingsLoadedResult)) { - const winrt::hstring titleKey = USES_RESOURCE(L"ReloadJsonParseErrorTitle"); - const winrt::hstring textKey = USES_RESOURCE(L"ReloadJsonParseErrorText"); - _ShowLoadErrorsDialog(titleKey, textKey, _settingsLoadedResult); + if (initialLoad) + { + _settings = CascadiaSettings::LoadDefaults(); + } + else + { + const winrt::hstring titleKey = USES_RESOURCE(L"ReloadJsonParseErrorTitle"); + const winrt::hstring textKey = USES_RESOURCE(L"ReloadJsonParseErrorText"); + _ShowLoadErrorsDialog(titleKey, textKey, _settingsLoadedResult); + return; + } + } + + if (initialLoad) + { + // Register for directory change notification. + _RegisterSettingsChange(); return; } @@ -1375,7 +1369,7 @@ namespace winrt::TerminalApp::implementation if (!_loadedInitialSettings) { // Load settings if we haven't already - LoadSettings(); + ReloadSettings(); } return AppLogic::_doFindTargetWindow(args, _settings.GlobalSettings().WindowingBehavior()); @@ -1532,7 +1526,7 @@ namespace winrt::TerminalApp::implementation if (!_loadedInitialSettings) { // Load settings if we haven't already - LoadSettings(); + ReloadSettings(); } return _settings.GlobalSettings().AutoHideWindow(); @@ -1553,7 +1547,7 @@ namespace winrt::TerminalApp::implementation if (!_loadedInitialSettings) { // Load settings if we haven't already - LoadSettings(); + ReloadSettings(); } return _root != nullptr ? _root->ShouldImmediatelyHandoffToElevated(_settings) : false; @@ -1666,7 +1660,7 @@ namespace winrt::TerminalApp::implementation if (!_loadedInitialSettings) { // Load settings if we haven't already - LoadSettings(); + ReloadSettings(); } return _settings.GlobalSettings().MinimizeToNotificationArea(); @@ -1677,7 +1671,7 @@ namespace winrt::TerminalApp::implementation if (!_loadedInitialSettings) { // Load settings if we haven't already - LoadSettings(); + ReloadSettings(); } return _settings.GlobalSettings().AlwaysShowNotificationIcon(); @@ -1693,7 +1687,7 @@ namespace winrt::TerminalApp::implementation if (!_loadedInitialSettings) { // Load settings if we haven't already - LoadSettings(); + ReloadSettings(); } return _settings.GlobalSettings().CurrentTheme(); } diff --git a/src/cascadia/TerminalApp/AppLogic.h b/src/cascadia/TerminalApp/AppLogic.h index 3a84651a48a..5534979b973 100644 --- a/src/cascadia/TerminalApp/AppLogic.h +++ b/src/cascadia/TerminalApp/AppLogic.h @@ -62,7 +62,6 @@ namespace winrt::TerminalApp::implementation bool IsUwp() const noexcept; void RunAsUwp(); bool IsElevated() const noexcept; - void LoadSettings(); void ReloadSettings(); [[nodiscard]] Microsoft::Terminal::Settings::Model::CascadiaSettings GetSettings() const noexcept; diff --git a/src/cascadia/TerminalApp/AppLogic.idl b/src/cascadia/TerminalApp/AppLogic.idl index aebd07e1165..b7a92ea1103 100644 --- a/src/cascadia/TerminalApp/AppLogic.idl +++ b/src/cascadia/TerminalApp/AppLogic.idl @@ -59,7 +59,6 @@ namespace TerminalApp void Quit(); - void LoadSettings(); void ReloadSettings(); Windows.UI.Xaml.UIElement GetRoot(); From 11460d6470a9e91915acfa7a8db8c79b2f11520a Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 16 Nov 2022 15:09:39 -0600 Subject: [PATCH 16/20] yep. This is just as dumb as it seems --- .../ColorSchemeTests.cpp | 32 ++++++++++++------- .../DeserializationTests.cpp | 3 +- src/cascadia/LocalTests_SettingsModel/pch.h | 1 + .../TerminalSettings.cpp | 13 ++++++-- src/cascadia/TerminalSettingsModel/pch.h | 1 + 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp b/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp index fb84a1db5df..ee3e0412ab9 100644 --- a/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp @@ -306,36 +306,44 @@ namespace SettingsModelLocalTests const auto newName{ L"Campbell (renamed)" }; settings->UpdateColorSchemeReferences(L"Campbell", newName); - VERIFY_ARE_EQUAL(newName, settings->ProfileDefaults().DefaultAppearance().ColorSchemeName()); - VERIFY_IS_TRUE(settings->ProfileDefaults().DefaultAppearance().HasColorSchemeName()); + VERIFY_ARE_EQUAL(newName, settings->ProfileDefaults().DefaultAppearance().DarkColorSchemeName()); + VERIFY_ARE_EQUAL(newName, settings->ProfileDefaults().DefaultAppearance().LightColorSchemeName()); + VERIFY_IS_TRUE(settings->ProfileDefaults().DefaultAppearance().HasDarkColorSchemeName()); + VERIFY_IS_TRUE(settings->ProfileDefaults().DefaultAppearance().HasLightColorSchemeName()); const auto& profiles{ settings->AllProfiles() }; { const auto& prof{ profiles.GetAt(0) }; - VERIFY_ARE_EQUAL(newName, prof.DefaultAppearance().ColorSchemeName()); - VERIFY_IS_TRUE(prof.DefaultAppearance().HasColorSchemeName()); + VERIFY_ARE_EQUAL(newName, prof.DefaultAppearance().DarkColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasDarkColorSchemeName()); + VERIFY_ARE_EQUAL(newName, prof.DefaultAppearance().LightColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasLightColorSchemeName()); } { const auto& prof{ profiles.GetAt(1) }; - VERIFY_ARE_EQUAL(newName, prof.DefaultAppearance().ColorSchemeName()); - VERIFY_IS_TRUE(prof.DefaultAppearance().HasColorSchemeName()); + VERIFY_ARE_EQUAL(newName, prof.DefaultAppearance().DarkColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasDarkColorSchemeName()); + VERIFY_ARE_EQUAL(newName, prof.DefaultAppearance().LightColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasLightColorSchemeName()); } { const auto& prof{ profiles.GetAt(2) }; - VERIFY_ARE_EQUAL(newName, prof.DefaultAppearance().ColorSchemeName()); - VERIFY_IS_FALSE(prof.DefaultAppearance().HasColorSchemeName()); + VERIFY_ARE_EQUAL(newName, prof.DefaultAppearance().DarkColorSchemeName()); + VERIFY_IS_FALSE(prof.DefaultAppearance().HasDarkColorSchemeName()); + VERIFY_ARE_EQUAL(newName, prof.DefaultAppearance().LightColorSchemeName()); + VERIFY_IS_FALSE(prof.DefaultAppearance().HasLightColorSchemeName()); } { const auto& prof{ profiles.GetAt(3) }; - VERIFY_ARE_EQUAL(L"One Half Dark", prof.DefaultAppearance().ColorSchemeName()); - VERIFY_IS_TRUE(prof.DefaultAppearance().HasColorSchemeName()); + VERIFY_ARE_EQUAL(L"One Half Dark", prof.DefaultAppearance().DarkColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasDarkColorSchemeName()); + VERIFY_ARE_EQUAL(L"One Half Dark", prof.DefaultAppearance().LightColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasLightColorSchemeName()); } { const auto& prof{ profiles.GetAt(4) }; VERIFY_ARE_EQUAL(L"One Half Dark", prof.DefaultAppearance().DarkColorSchemeName()); VERIFY_ARE_EQUAL(L"One Half Light", prof.DefaultAppearance().LightColorSchemeName()); - VERIFY_ARE_EQUAL(L"One Half Dark", prof.DefaultAppearance().ColorSchemeName()); - VERIFY_IS_TRUE(prof.DefaultAppearance().HasColorSchemeName()); VERIFY_IS_TRUE(prof.DefaultAppearance().HasDarkColorSchemeName()); VERIFY_IS_TRUE(prof.DefaultAppearance().HasLightColorSchemeName()); } diff --git a/src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp b/src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp index 7008feed586..58b9a8dad29 100644 --- a/src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp @@ -744,7 +744,8 @@ namespace SettingsModelLocalTests VERIFY_ARE_EQUAL(3u, settings->AllProfiles().Size()); for (const auto& profile : settings->AllProfiles()) { - VERIFY_ARE_EQUAL(L"Campbell", profile.DefaultAppearance().ColorSchemeName()); + VERIFY_ARE_EQUAL(L"Campbell", profile.DefaultAppearance().DarkColorSchemeName()); + VERIFY_ARE_EQUAL(L"Campbell", profile.DefaultAppearance().LightColorSchemeName()); } } diff --git a/src/cascadia/LocalTests_SettingsModel/pch.h b/src/cascadia/LocalTests_SettingsModel/pch.h index b018bdaa4a6..b2e15b5a7b1 100644 --- a/src/cascadia/LocalTests_SettingsModel/pch.h +++ b/src/cascadia/LocalTests_SettingsModel/pch.h @@ -44,6 +44,7 @@ Author(s): #include #include #include +#include #include #include #include diff --git a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp index db3b7159764..39510e1b951 100644 --- a/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/TerminalSettings.cpp @@ -183,6 +183,16 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation return settingsPair; } + // I'm not even joking, this is the recommended way to do this: + // https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/apply-windows-themes#know-when-dark-mode-is-enabled + bool _isSystemInDarkTheme() + { + static auto isColorLight = [](const Windows::UI::Color& clr) -> bool { + return (((5 * clr.G) + (2 * clr.R) + clr.B) > (8 * 128)); + }; + return isColorLight(Windows::UI::ViewManagement::UISettings().GetColorValue(Windows::UI::ViewManagement::UIColorType::Foreground)); + } + void TerminalSettings::_ApplyAppearanceSettings(const IAppearanceConfig& appearance, const Windows::Foundation::Collections::IMapView& schemes, const winrt::Microsoft::Terminal::Settings::Model::Theme currentTheme) @@ -193,8 +203,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation auto requestedTheme = currentTheme.RequestedTheme(); if (requestedTheme == winrt::Windows::UI::Xaml::ElementTheme::Default) { - // TODO! make sure local tests don't explode - requestedTheme = Windows::UI::Xaml::Application::Current().RequestedTheme() == winrt::Windows::UI::Xaml::ApplicationTheme::Dark ? + requestedTheme = _isSystemInDarkTheme() ? winrt::Windows::UI::Xaml::ElementTheme::Dark : winrt::Windows::UI::Xaml::ElementTheme::Light; } diff --git a/src/cascadia/TerminalSettingsModel/pch.h b/src/cascadia/TerminalSettingsModel/pch.h index f8266b66fd1..75b789ed581 100644 --- a/src/cascadia/TerminalSettingsModel/pch.h +++ b/src/cascadia/TerminalSettingsModel/pch.h @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include From b969353882aec8eada066e400a37f29b5ab8dfc8 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 16 Nov 2022 15:26:06 -0600 Subject: [PATCH 17/20] tests man, tests (thread) --- .../ColorSchemeTests.cpp | 57 ++++++++++++++++++- 1 file changed, 55 insertions(+), 2 deletions(-) diff --git a/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp b/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp index ee3e0412ab9..b266064977a 100644 --- a/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/ColorSchemeTests.cpp @@ -219,12 +219,28 @@ namespace SettingsModelLocalTests "colorScheme": "One Half Dark" }, { - "name": "Different reference / Light and Dark", - "colorScheme": + "name": "rename neither", + "colorScheme": { "dark": "One Half Dark", "light": "One Half Light" } + }, + { + "name": "rename only light", + "colorScheme": + { + "dark": "One Half Dark", + "light": "Campbell" + } + }, + { + "name": "rename only dark", + "colorScheme": + { + "dark": "Campbell", + "light": "One Half Light" + } } ] }, @@ -297,6 +313,28 @@ namespace SettingsModelLocalTests "selectionBackground": "#FFFFFF", "white": "#DCDFE4", "yellow": "#E5C07B" + }, + { + "name": "One Half Light", + "foreground": "#383A42", + "background": "#FAFAFA", + "cursorColor": "#4F525D", + "black": "#383A42", + "red": "#E45649", + "green": "#50A14F", + "yellow": "#C18301", + "blue": "#0184BC", + "purple": "#A626A4", + "cyan": "#0997B3", + "white": "#FAFAFA", + "brightBlack": "#4F525D", + "brightRed": "#DF6C75", + "brightGreen": "#98C379", + "brightYellow": "#E4C07A", + "brightBlue": "#61AFEF", + "brightPurple": "#C577DD", + "brightCyan": "#56B5C1", + "brightWhite": "#FFFFFF" } ] })json" }; @@ -304,6 +342,7 @@ namespace SettingsModelLocalTests const auto settings{ winrt::make_self(settingsString) }; const auto newName{ L"Campbell (renamed)" }; + settings->UpdateColorSchemeReferences(L"Campbell", newName); VERIFY_ARE_EQUAL(newName, settings->ProfileDefaults().DefaultAppearance().DarkColorSchemeName()); @@ -347,5 +386,19 @@ namespace SettingsModelLocalTests VERIFY_IS_TRUE(prof.DefaultAppearance().HasDarkColorSchemeName()); VERIFY_IS_TRUE(prof.DefaultAppearance().HasLightColorSchemeName()); } + { + const auto& prof{ profiles.GetAt(5) }; + VERIFY_ARE_EQUAL(L"One Half Dark", prof.DefaultAppearance().DarkColorSchemeName()); + VERIFY_ARE_EQUAL(newName, prof.DefaultAppearance().LightColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasDarkColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasLightColorSchemeName()); + } + { + const auto& prof{ profiles.GetAt(6) }; + VERIFY_ARE_EQUAL(newName, prof.DefaultAppearance().DarkColorSchemeName()); + VERIFY_ARE_EQUAL(L"One Half Light", prof.DefaultAppearance().LightColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasDarkColorSchemeName()); + VERIFY_IS_TRUE(prof.DefaultAppearance().HasLightColorSchemeName()); + } } } From c823fe6d3179d11f763c9b8ca561df668270927e Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 16 Nov 2022 15:33:24 -0600 Subject: [PATCH 18/20] these weren't me! --- .../DeserializationTests.cpp | 9 +++++++-- .../SerializationTests.cpp | 16 ++++++++-------- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp b/src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp index 58b9a8dad29..b2eaed29014 100644 --- a/src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/DeserializationTests.cpp @@ -960,6 +960,10 @@ namespace SettingsModelLocalTests }, { "name": "profile3", + "closeOnExit": "automatic" + }, + { + "name": "profile4", "closeOnExit": null } ] @@ -969,9 +973,10 @@ namespace SettingsModelLocalTests VERIFY_ARE_EQUAL(CloseOnExitMode::Graceful, settings->AllProfiles().GetAt(0).CloseOnExit()); VERIFY_ARE_EQUAL(CloseOnExitMode::Always, settings->AllProfiles().GetAt(1).CloseOnExit()); VERIFY_ARE_EQUAL(CloseOnExitMode::Never, settings->AllProfiles().GetAt(2).CloseOnExit()); + VERIFY_ARE_EQUAL(CloseOnExitMode::Automatic, settings->AllProfiles().GetAt(3).CloseOnExit()); - // Unknown modes parse as "Graceful" - VERIFY_ARE_EQUAL(CloseOnExitMode::Graceful, settings->AllProfiles().GetAt(3).CloseOnExit()); + // Unknown modes parse as "Automatic" + VERIFY_ARE_EQUAL(CloseOnExitMode::Automatic, settings->AllProfiles().GetAt(4).CloseOnExit()); } void DeserializationTests::TestCloseOnExitCompatibilityShim() diff --git a/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp b/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp index f0a3ed3d02a..4f9fb528f99 100644 --- a/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp +++ b/src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp @@ -134,7 +134,7 @@ namespace SettingsModelLocalTests "font": { "face": "Cascadia Mono", - "size": 12, + "size": 12.0, "weight": "normal" }, "padding": "8, 8, 8, 8", @@ -250,8 +250,8 @@ namespace SettingsModelLocalTests // complex command with key chords static constexpr std::string_view actionsString4A{ R"([ - { "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+c" }, - { "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+d" } + { "command": { "action": "adjustFontSize", "delta": 1.0 }, "keys": "ctrl+c" }, + { "command": { "action": "adjustFontSize", "delta": 1.0 }, "keys": "ctrl+d" } ])" }; // GH#13323 - these can be fragile. In the past, the order these get // re-serialized as has been not entirely stable. We don't really care @@ -260,7 +260,7 @@ namespace SettingsModelLocalTests // itself. Feel free to change as needed. static constexpr std::string_view actionsString4B{ R"([ { "command": { "action": "findMatch", "direction": "prev" }, "keys": "ctrl+shift+r" }, - { "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+d" } + { "command": { "action": "adjustFontSize", "delta": 1.0 }, "keys": "ctrl+d" } ])" }; // command with name and icon and multiple key chords @@ -284,8 +284,8 @@ namespace SettingsModelLocalTests { "name": "Change font size...", "commands": [ - { "command": { "action": "adjustFontSize", "delta": 1 } }, - { "command": { "action": "adjustFontSize", "delta": -1 } }, + { "command": { "action": "adjustFontSize", "delta": 1.0 } }, + { "command": { "action": "adjustFontSize", "delta": -1.0 } }, { "command": "resetFontSize" }, ] } @@ -478,7 +478,7 @@ namespace SettingsModelLocalTests "name": "Profile with legacy font settings", "fontFace": "Cascadia Mono", - "fontSize": 12, + "fontSize": 12.0, "fontWeight": "normal" })" }; @@ -488,7 +488,7 @@ namespace SettingsModelLocalTests "font": { "face": "Cascadia Mono", - "size": 12, + "size": 12.0, "weight": "normal" } })" }; From 126070559eefbb3410b1d39f4592f74572bcf23c Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Thu, 1 Dec 2022 12:51:18 -0600 Subject: [PATCH 19/20] remove this scheme --- .../TerminalSettingsModel/defaults.json | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/src/cascadia/TerminalSettingsModel/defaults.json b/src/cascadia/TerminalSettingsModel/defaults.json index efe709a42ab..59a7f231c81 100644 --- a/src/cascadia/TerminalSettingsModel/defaults.json +++ b/src/cascadia/TerminalSettingsModel/defaults.json @@ -103,28 +103,6 @@ "brightCyan": "#61D6D6", "brightWhite": "#F2F2F2" }, - { - "name": "Campbell Light", - "foreground": "#0C0C0C", - "background": "#CCCCCC", - "cursorColor": "#000000", - "black": "#0C0C0C", - "red": "#C50F1F", - "green": "#13A10E", - "yellow": "#C19C00", - "blue": "#0037DA", - "purple": "#881798", - "cyan": "#3A96DD", - "white": "#CCCCCC", - "brightBlack": "#767676", - "brightRed": "#E74856", - "brightGreen": "#16C60C", - "brightYellow": "#F9F1A5", - "brightBlue": "#3B78FF", - "brightPurple": "#B4009E", - "brightCyan": "#61D6D6", - "brightWhite": "#F2F2F2" - }, { "name": "Campbell Powershell", "foreground": "#CCCCCC", From c56a424c9e465a3eee58494346bc76a6f9a430fe Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Tue, 6 Dec 2022 09:03:30 -0600 Subject: [PATCH 20/20] yea I dig it --- src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp | 2 +- src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp index ab36934b574..160f5a3839b 100644 --- a/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ColorSchemeViewModel.cpp @@ -52,7 +52,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation bool ColorSchemeViewModel::IsDefaultScheme() { - auto defaultAppearance = _settings.ProfileDefaults().DefaultAppearance(); + const auto defaultAppearance = _settings.ProfileDefaults().DefaultAppearance(); return defaultAppearance.LightColorSchemeName() == defaultAppearance.DarkColorSchemeName() && _Name == defaultAppearance.LightColorSchemeName(); } diff --git a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp index 4aecd33be14..90513b146ca 100644 --- a/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp +++ b/src/cascadia/TerminalSettingsModel/AppearanceConfig.cpp @@ -54,7 +54,7 @@ Json::Value AppearanceConfig::ToJson() const JsonUtils::SetValueForKey(json, SelectionBackgroundKey, _SelectionBackground); JsonUtils::SetValueForKey(json, CursorColorKey, _CursorColor); JsonUtils::SetValueForKey(json, OpacityKey, _Opacity, JsonUtils::OptionalConverter{}); - if (HasDarkColorSchemeName() && HasLightColorSchemeName()) + if (HasDarkColorSchemeName() || HasLightColorSchemeName()) { // check if the setting is coming from the UI, if so grab the ColorSchemeName until the settings UI is fixed. if (_LightColorSchemeName != _DarkColorSchemeName)