diff --git a/src/cascadia/TerminalApp/SettingsPaneContent.cpp b/src/cascadia/TerminalApp/SettingsPaneContent.cpp index 9d514e1600..22918b2692 100644 --- a/src/cascadia/TerminalApp/SettingsPaneContent.cpp +++ b/src/cascadia/TerminalApp/SettingsPaneContent.cpp @@ -19,7 +19,7 @@ namespace winrt::TerminalApp::implementation // Stash away the current requested theme of the app. We'll need that in // _BackgroundBrush() to do a theme-aware resource lookup - _requestedTheme = settings.GlobalSettings().CurrentTheme().RequestedTheme(); + _requestedTheme = settings.GlobalSettings().CurrentTheme(settings.WindowSettingsDefaults()).RequestedTheme(); } void SettingsPaneContent::UpdateSettings(const CascadiaSettings& settings) @@ -27,7 +27,7 @@ namespace winrt::TerminalApp::implementation ASSERT_UI_THREAD(); _sui.UpdateSettings(settings); - _requestedTheme = settings.GlobalSettings().CurrentTheme().RequestedTheme(); + _requestedTheme = settings.GlobalSettings().CurrentTheme(settings.WindowSettingsDefaults()).RequestedTheme(); } winrt::Windows::UI::Xaml::FrameworkElement SettingsPaneContent::GetRoot() diff --git a/src/cascadia/TerminalApp/SnippetsPaneContent.cpp b/src/cascadia/TerminalApp/SnippetsPaneContent.cpp index f7b8885015..f78ad9d808 100644 --- a/src/cascadia/TerminalApp/SnippetsPaneContent.cpp +++ b/src/cascadia/TerminalApp/SnippetsPaneContent.cpp @@ -121,7 +121,7 @@ namespace winrt::TerminalApp::implementation { static const auto key = winrt::box_value(L"SettingsUiTabBrush"); return ThemeLookup(WUX::Application::Current().Resources(), - _settings.GlobalSettings().CurrentTheme().RequestedTheme(), + _settings.GlobalSettings().CurrentTheme(_settings.WindowSettingsDefaults()).RequestedTheme(), key) .try_as(); } diff --git a/src/cascadia/TerminalApp/Tab.cpp b/src/cascadia/TerminalApp/Tab.cpp index 5cc1087935..eccb199202 100644 --- a/src/cascadia/TerminalApp/Tab.cpp +++ b/src/cascadia/TerminalApp/Tab.cpp @@ -9,6 +9,8 @@ #include "Utils.h" #include "../../types/inc/ColorFix.hpp" +#include + using namespace winrt; using namespace winrt::Windows::UI::Xaml; using namespace winrt::Windows::UI::Core; diff --git a/src/cascadia/TerminalApp/TabManagement.cpp b/src/cascadia/TerminalApp/TabManagement.cpp index bb6e7d6abd..829f33f86c 100644 --- a/src/cascadia/TerminalApp/TabManagement.cpp +++ b/src/cascadia/TerminalApp/TabManagement.cpp @@ -239,7 +239,7 @@ namespace winrt::TerminalApp::implementation if (const auto content{ tab.GetActiveContent() }) { const auto& icon{ content.Icon() }; - const auto theme = _settings.GlobalSettings().CurrentTheme(); + const auto theme = _settings.GlobalSettings().CurrentTheme(_currentWindowSettings()); const auto iconStyle = (theme && theme.Tab()) ? theme.Tab().IconStyle() : IconStyle::Default; tab.UpdateIcon(icon, iconStyle); diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 29b07216f6..54bf652ab6 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -375,7 +375,7 @@ namespace winrt::TerminalApp::implementation // Initialize the state of the CloseButtonOverlayMode property of // our TabView, to match the tab.showCloseButton property in the theme. - if (const auto theme = _settings.GlobalSettings().CurrentTheme()) + if (const auto theme = _settings.GlobalSettings().CurrentTheme(_currentWindowSettings())) { const auto visibility = theme.Tab() ? theme.Tab().ShowCloseButton() : Settings::Model::TabCloseButtonVisibility::Always; @@ -4082,7 +4082,7 @@ namespace winrt::TerminalApp::implementation // our TabView, to match the tab.showCloseButton property in the theme. // // Also update every tab's individual IsClosable to match the same property. - const auto theme = _settings.GlobalSettings().CurrentTheme(); + const auto theme = _settings.GlobalSettings().CurrentTheme(_currentWindowSettings()); const auto visibility = (theme && theme.Tab()) ? theme.Tab().ShowCloseButton() : Settings::Model::TabCloseButtonVisibility::Always; @@ -4696,7 +4696,7 @@ namespace winrt::TerminalApp::implementation // - void TerminalPage::_UpdateTeachingTipTheme(winrt::Windows::UI::Xaml::FrameworkElement element) { - auto theme{ _settings.GlobalSettings().CurrentTheme() }; + auto theme{ _settings.GlobalSettings().CurrentTheme(_currentWindowSettings()) }; auto requestedTheme{ theme.RequestedTheme() }; while (element) { @@ -5070,7 +5070,7 @@ namespace winrt::TerminalApp::implementation return; } - const auto theme = _settings.GlobalSettings().CurrentTheme(); + const auto theme = _settings.GlobalSettings().CurrentTheme(_currentWindowSettings()); auto requestedTheme{ theme.RequestedTheme() }; { diff --git a/src/cascadia/TerminalApp/TerminalWindow.cpp b/src/cascadia/TerminalApp/TerminalWindow.cpp index 1e0588d33b..7e1bc2cfae 100644 --- a/src/cascadia/TerminalApp/TerminalWindow.cpp +++ b/src/cascadia/TerminalApp/TerminalWindow.cpp @@ -303,7 +303,7 @@ namespace winrt::TerminalApp::implementation Microsoft::Terminal::Settings::Model::Theme TerminalWindow::Theme() { - return _settings.GlobalSettings().CurrentTheme(); + return _settings.GlobalSettings().CurrentTheme(_currentWindowSettings()); } // WinUI can't show 2 dialogs simultaneously. Yes, really. If you do, you get an exception. @@ -380,7 +380,7 @@ namespace winrt::TerminalApp::implementation auto themingLambda{ [weak](const Windows::Foundation::IInspectable& sender, const RoutedEventArgs&) { if (const auto strong = weak.get()) { - auto theme{ strong->_settings.GlobalSettings().CurrentTheme() }; + auto theme{ strong->_settings.GlobalSettings().CurrentTheme(strong->_currentWindowSettings()) }; auto requestedTheme{ theme.RequestedTheme() }; auto element{ sender.try_as() }; while (element) diff --git a/src/cascadia/TerminalApp/TerminalWindow.idl b/src/cascadia/TerminalApp/TerminalWindow.idl index c12f73e137..dee3957469 100644 --- a/src/cascadia/TerminalApp/TerminalWindow.idl +++ b/src/cascadia/TerminalApp/TerminalWindow.idl @@ -96,6 +96,7 @@ namespace TerminalApp TaskbarState TaskbarState{ get; }; Windows.UI.Xaml.Media.Brush TitlebarBrush { get; }; Windows.UI.Xaml.Media.Brush FrameBrush { get; }; + Microsoft.Terminal.Settings.Model.Theme Theme { get; }; void WindowActivated(Boolean activated); Boolean GetMinimizeToNotificationArea(); diff --git a/src/cascadia/TerminalSettingsAppAdapterLib/TerminalSettings.cpp b/src/cascadia/TerminalSettingsAppAdapterLib/TerminalSettings.cpp index 04dd4fa076..1f6c0180ac 100644 --- a/src/cascadia/TerminalSettingsAppAdapterLib/TerminalSettings.cpp +++ b/src/cascadia/TerminalSettingsAppAdapterLib/TerminalSettings.cpp @@ -58,7 +58,7 @@ namespace winrt::Microsoft::Terminal::Settings const auto windowSettings = appSettings.WindowSettingsDefaults(); settings->_ApplyProfileSettings(profile); settings->_ApplyGlobalSettings(windowSettings); - settings->_ApplyAppearanceSettings(profile.DefaultAppearance(), globals.ColorSchemes(), globals.CurrentTheme()); + settings->_ApplyAppearanceSettings(profile.DefaultAppearance(), globals.ColorSchemes(), globals.CurrentTheme(windowSettings)); return settings; } @@ -91,7 +91,7 @@ namespace winrt::Microsoft::Terminal::Settings const auto globals = appSettings.GlobalSettings(); child = winrt::make_self(); child->_parent = settings->get_strong(); - child->_ApplyAppearanceSettings(unfocusedAppearance, globals.ColorSchemes(), globals.CurrentTheme()); + child->_ApplyAppearanceSettings(unfocusedAppearance, globals.ColorSchemes(), globals.CurrentTheme(appSettings.WindowSettingsDefaults())); } return TerminalSettingsCreateResult{ settings.get(), child.get() }; diff --git a/src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.cpp b/src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.cpp index 4ada213ad2..a4970c547e 100644 --- a/src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/GlobalAppearanceViewModel.cpp @@ -47,7 +47,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation winrt::Windows::Foundation::IInspectable GlobalAppearanceViewModel::CurrentTheme() { - return _GlobalSettings.CurrentTheme(); + return _GlobalSettings.CurrentTheme(_WindowSettings); } // Get the name out of the newly selected item, stash that as the Theme name diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp index f157f2879a..e92a7e2bdf 100644 --- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp +++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp @@ -375,7 +375,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation // GH#19927 - Theme the search box's internal popup now that the // visual tree is ready and control templates are applied - const auto theme = _settingsSource.GlobalSettings().CurrentTheme(); + const auto theme = _settingsSource.GlobalSettings().CurrentTheme(_settingsSource.WindowSettingsDefaults()); const auto hasThemeForSettings{ theme.Settings() != nullptr }; const auto requestedTheme = hasThemeForSettings ? theme.Settings().RequestedTheme() : theme.RequestedTheme(); _setThemeOnPopups(SettingsSearchBox(), requestedTheme); @@ -1149,7 +1149,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation } } - const auto theme = _settingsSource.GlobalSettings().CurrentTheme(); + const auto theme = _settingsSource.GlobalSettings().CurrentTheme(_settingsSource.WindowSettingsDefaults()); const auto hasThemeForSettings{ theme.Settings() != nullptr }; const auto appTheme = theme.RequestedTheme(); const auto requestedTheme = (hasThemeForSettings) ? theme.Settings().RequestedTheme() : appTheme; diff --git a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp index d7e1df4a83..91d10c96ff 100644 --- a/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp +++ b/src/cascadia/TerminalSettingsEditor/ProfileViewModel.cpp @@ -385,7 +385,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation Windows::UI::Color ProfileViewModel::TabThemeColorPreview() const { - const auto currentTheme = _appSettings.GlobalSettings().CurrentTheme(); + const auto currentTheme = _appSettings.GlobalSettings().CurrentTheme(_appSettings.WindowSettingsDefaults()); if (const auto tabTheme = currentTheme.Tab()) { // theme.tab.background: theme color must be evaluated diff --git a/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp b/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp index 0a42b2802a..22ec4a4fe6 100644 --- a/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp +++ b/src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp @@ -1316,7 +1316,7 @@ void CascadiaSettings::_researchOnLoad() { // ----------------------------- RE: Themes ---------------------------- const auto numThemes = GlobalSettings().Themes().Size(); - const auto themeInUse = GlobalSettings().CurrentTheme().Name(); + const auto themeInUse = GlobalSettings().CurrentTheme(WindowSettingsDefaults()).Name(); const auto changedTheme = _globals->HasTheme(); // system: 0 diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp index acbd84411f..799809550e 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp @@ -367,19 +367,25 @@ bool GlobalAppSettings::FixupsAppliedDuringLoad() return _fixupsAppliedDuringLoad || _actionMap->FixupsAppliedDuringLoad(); } -winrt::Microsoft::Terminal::Settings::Model::Theme GlobalAppSettings::CurrentTheme() noexcept +winrt::Microsoft::Terminal::Settings::Model::Theme GlobalAppSettings::CurrentTheme(const Model::WindowSettings& window) noexcept { auto requestedTheme = Model::Theme::IsSystemInDarkTheme() ? winrt::Windows::UI::Xaml::ElementTheme::Dark : winrt::Windows::UI::Xaml::ElementTheme::Light; + const auto themePair = window ? window.Theme() : nullptr; + if (!themePair) + { + return nullptr; + } + switch (requestedTheme) { case winrt::Windows::UI::Xaml::ElementTheme::Light: - return _themes.TryLookup(Theme().LightName()); + return _themes.TryLookup(themePair.LightName()); case winrt::Windows::UI::Xaml::ElementTheme::Dark: - return _themes.TryLookup(Theme().DarkName()); + return _themes.TryLookup(themePair.DarkName()); case winrt::Windows::UI::Xaml::ElementTheme::Default: default: diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h index 58147fac44..7d89f09754 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h @@ -65,7 +65,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation Windows::Foundation::Collections::IMapView Themes() noexcept; void AddTheme(const Model::Theme& theme); - Model::Theme CurrentTheme() noexcept; + Model::Theme CurrentTheme(const Model::WindowSettings& window) noexcept; bool ShouldUsePersistedLayout() const; void ExpandCommands(const Windows::Foundation::Collections::IVectorView& profiles, diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl index 7755297dbe..3c02fa38a8 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl @@ -81,7 +81,7 @@ namespace Microsoft.Terminal.Settings.Model // ---- Themes ---- Windows.Foundation.Collections.IMapView Themes(); void AddTheme(Theme theme); - Theme CurrentTheme { get; }; + Theme CurrentTheme(WindowSettings window); Boolean ShouldUsePersistedLayout(); } diff --git a/src/cascadia/UnitTests_SettingsModel/TerminalSettingsTests.cpp b/src/cascadia/UnitTests_SettingsModel/TerminalSettingsTests.cpp index e26e111828..6eb758c5bc 100644 --- a/src/cascadia/UnitTests_SettingsModel/TerminalSettingsTests.cpp +++ b/src/cascadia/UnitTests_SettingsModel/TerminalSettingsTests.cpp @@ -799,7 +799,7 @@ namespace SettingsModelUnitTests const auto activeProfiles = settings->ActiveProfiles(); const auto colorSchemes = settings->GlobalSettings().ColorSchemes(); - const auto currentTheme = settings->GlobalSettings().CurrentTheme(); + const auto currentTheme = settings->GlobalSettings().CurrentTheme(settings->WindowSettingsDefaults()); 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); diff --git a/src/cascadia/UnitTests_SettingsModel/ThemeTests.cpp b/src/cascadia/UnitTests_SettingsModel/ThemeTests.cpp index 34b4e5eb73..2097b34d98 100644 --- a/src/cascadia/UnitTests_SettingsModel/ThemeTests.cpp +++ b/src/cascadia/UnitTests_SettingsModel/ThemeTests.cpp @@ -248,7 +248,7 @@ namespace SettingsModelUnitTests VERIFY_IS_NULL(bar.TabRow().Background()); } - const auto currentTheme{ settings->GlobalSettings().CurrentTheme() }; + const auto currentTheme{ settings->GlobalSettings().CurrentTheme(settings->WindowSettingsDefaults()) }; VERIFY_IS_NOT_NULL(currentTheme); VERIFY_ARE_EQUAL(L"system", currentTheme.Name()); } diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index 93889a9023..9cc302a131 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -934,7 +934,7 @@ void _frameColorHelper(const HWND h, const COLORREF color) void AppHost::_updateTheme() { - auto theme = _appLogic.Settings().GlobalSettings().CurrentTheme(); + auto theme = _windowLogic.Theme(); _window->OnApplicationThemeChanged(theme.RequestedTheme());