From b1017b95e6f0b8652baa93a982c0d32252804b3b Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 2 Dec 2022 15:40:57 -0600 Subject: [PATCH 1/2] fixes #3917 --- src/cascadia/TerminalApp/App.xaml | 4 ++-- src/cascadia/TerminalApp/Pane.cpp | 21 +++++++++------------ src/cascadia/TerminalApp/Pane.h | 4 ++-- src/cascadia/TerminalApp/TerminalPage.cpp | 16 ++++++++++++++++ 4 files changed, 29 insertions(+), 16 deletions(-) diff --git a/src/cascadia/TerminalApp/App.xaml b/src/cascadia/TerminalApp/App.xaml index 24573ba6198..3da02dff31a 100644 --- a/src/cascadia/TerminalApp/App.xaml +++ b/src/cascadia/TerminalApp/App.xaml @@ -153,7 +153,7 @@ Color="#2e2e2e" /> + ResourceKey="TabViewBackground" /> @@ -169,7 +169,7 @@ Color="#e8e8e8" /> + ResourceKey="TabViewBackground" /> diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index b1060590d4e..0f1b115bb07 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -5,6 +5,8 @@ #include "Pane.h" #include "AppLogic.h" +#include "Utils.h" + #include using namespace winrt::Windows::Foundation; @@ -45,14 +47,6 @@ Pane::Pane(const Profile& profile, const TermControl& control, const bool lastFo _connectionStateChangedToken = _control.ConnectionStateChanged({ this, &Pane::_ControlConnectionStateChangedHandler }); _warningBellToken = _control.WarningBell({ this, &Pane::_ControlWarningBellHandler }); - // On the first Pane's creation, lookup resources we'll use to theme the - // Pane, including the brushed to use for the focused/unfocused border - // color. - if (s_focusedBorderBrush == nullptr || s_unfocusedBorderBrush == nullptr) - { - _SetupResources(); - } - // Register an event with the control to have it inform us when it gains focus. _gotFocusRevoker = _control.GotFocus(winrt::auto_revoke, { this, &Pane::_ControlGotFocusHandler }); _lostFocusRevoker = _control.LostFocus(winrt::auto_revoke, { this, &Pane::_ControlLostFocusHandler }); @@ -3077,16 +3071,16 @@ float Pane::_ClampSplitPosition(const bool widthOrHeight, const float requestedV // * The Brush we'll use for inactive Panes - TabViewBackground (to match the // color of the titlebar) // Arguments: -// - +// - requestedTheme: this should be the currently active Theme for the app // Return Value: // - -void Pane::_SetupResources() +void Pane::SetupResources(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme) { const auto res = Application::Current().Resources(); const auto accentColorKey = winrt::box_value(L"SystemAccentColor"); if (res.HasKey(accentColorKey)) { - const auto colorFromResources = res.Lookup(accentColorKey); + const auto colorFromResources = ThemeLookup(res, requestedTheme, accentColorKey); // If SystemAccentColor is _not_ a Color for some reason, use // Transparent as the color, so we don't do this process again on // the next pane (by leaving s_focusedBorderBrush nullptr) @@ -3104,7 +3098,10 @@ void Pane::_SetupResources() const auto unfocusedBorderBrushKey = winrt::box_value(L"UnfocusedBorderBrush"); if (res.HasKey(unfocusedBorderBrushKey)) { - auto obj = res.Lookup(unfocusedBorderBrushKey); + // MAKE SURE TO USE ThemeLookup, so that we get the correct resource for + // the requestedTheme, not just the value from the resources (which + // might not respect the settings' requested theme) + auto obj = ThemeLookup(res, requestedTheme, unfocusedBorderBrushKey); s_unfocusedBorderBrush = obj.try_as(); } else diff --git a/src/cascadia/TerminalApp/Pane.h b/src/cascadia/TerminalApp/Pane.h index c81bd3fd096..3f72d13e49b 100644 --- a/src/cascadia/TerminalApp/Pane.h +++ b/src/cascadia/TerminalApp/Pane.h @@ -136,6 +136,8 @@ class Pane : public std::enable_shared_from_this bool ContainsReadOnly() const; + static void SetupResources(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme); + // Method Description: // - A helper method for ad-hoc recursion on a pane tree. Walks the pane // tree, calling a function on each pane in a depth-first pattern. @@ -337,8 +339,6 @@ class Pane : public std::enable_shared_from_this return false; } - static void _SetupResources(); - struct PanePoint { float x; diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 327347f5caf..74fb754b8fc 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -4175,6 +4175,22 @@ namespace winrt::TerminalApp::implementation const auto theme = _settings.GlobalSettings().CurrentTheme(); auto requestedTheme{ theme.RequestedTheme() }; + { + // Update the brushes that Pane's use... + Pane::SetupResources(requestedTheme); + // ... then trigger a visual update for all the bane borders to + // apply the new ones. + for (const auto& tab : _tabs) + { + if (auto terminalTab{ _GetTerminalTabImpl(tab) }) + { + terminalTab->GetRootPane()->WalkTree([&](auto&& pane) { + pane->UpdateVisuals(); + }); + } + } + } + const auto res = Application::Current().Resources(); // Use our helper to lookup the theme-aware version of the resource. From 4f2a3a7fbce9993d79f680f0c2940aeaeb7beabd Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Fri, 9 Dec 2022 14:49:34 -0600 Subject: [PATCH 2/2] Update src/cascadia/TerminalApp/TerminalPage.cpp Co-authored-by: Carlos Zamora --- src/cascadia/TerminalApp/TerminalPage.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 74fb754b8fc..564f99379df 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -4178,7 +4178,7 @@ namespace winrt::TerminalApp::implementation { // Update the brushes that Pane's use... Pane::SetupResources(requestedTheme); - // ... then trigger a visual update for all the bane borders to + // ... then trigger a visual update for all the pane borders to // apply the new ones. for (const auto& tab : _tabs) {