@@ -4689,11 +4689,21 @@ namespace winrt::TerminalApp::implementation
4689
4689
}
4690
4690
4691
4691
const auto theme = _settings.GlobalSettings ().CurrentTheme ();
4692
- auto requestedTheme{ theme.RequestedTheme () };
4693
-
4692
+ const auto requestedTheme{ theme.RequestedTheme () };
4693
+ Media::Brush terminalBrush{ nullptr };
4694
+ if (const auto tab{ _GetFocusedTabImpl () })
4694
4695
{
4695
- _updatePaneResources (requestedTheme);
4696
+ if (const auto & pane{ tab->GetActivePane () })
4697
+ {
4698
+ if (const auto & lastContent{ pane->GetLastFocusedContent () })
4699
+ {
4700
+ terminalBrush = lastContent.BackgroundBrush ();
4701
+ }
4702
+ }
4703
+ }
4696
4704
4705
+ {
4706
+ _updatePaneResources (requestedTheme, theme.Pane (), terminalBrush);
4697
4707
for (const auto & tab : _tabs)
4698
4708
{
4699
4709
if (auto terminalTab{ _GetTerminalTabImpl (tab) })
@@ -4715,18 +4725,6 @@ namespace winrt::TerminalApp::implementation
4715
4725
4716
4726
til::color bgColor = backgroundSolidBrush.Color ();
4717
4727
4718
- Media::Brush terminalBrush{ nullptr };
4719
- if (const auto tab{ _GetFocusedTabImpl () })
4720
- {
4721
- if (const auto & pane{ tab->GetActivePane () })
4722
- {
4723
- if (const auto & lastContent{ pane->GetLastFocusedContent () })
4724
- {
4725
- terminalBrush = lastContent.BackgroundBrush ();
4726
- }
4727
- }
4728
- }
4729
-
4730
4728
if (_settings.GlobalSettings ().UseAcrylicInTabRow ())
4731
4729
{
4732
4730
const auto acrylicBrush = Media::AcrylicBrush ();
@@ -4796,67 +4794,92 @@ namespace winrt::TerminalApp::implementation
4796
4794
}
4797
4795
}
4798
4796
4797
+
4798
+ Color TerminalPage::_colorFromKey (const ResourceDictionary& resourceDictionary, const ElementTheme& requestedTheme, const IInspectable& colorKey)
4799
+ {
4800
+ const auto defaultColor = Colors::Black ();
4801
+ if (!resourceDictionary.HasKey (colorKey))
4802
+ {
4803
+ return defaultColor;
4804
+ }
4805
+ return winrt::unbox_value_or<Color>(
4806
+ ThemeLookup (resourceDictionary, requestedTheme, colorKey),
4807
+ defaultColor
4808
+ );
4809
+ }
4810
+
4811
+ Color TerminalPage::_parseThemeColorToColor (
4812
+ const ThemeColor& colorToCopy,
4813
+ const ResourceDictionary& resourceDictionary,
4814
+ const ElementTheme& requestedTheme,
4815
+ const IInspectable& accentKey,
4816
+ const Media::Brush& backgroundBrush
4817
+ )
4818
+ {
4819
+ switch (colorToCopy.ColorType ())
4820
+ {
4821
+ case ThemeColorType::Accent:
4822
+ {
4823
+ return _colorFromKey (resourceDictionary, requestedTheme, accentKey);
4824
+ }
4825
+ case ThemeColorType::Color:
4826
+ const auto rawColor = colorToCopy.Color ();
4827
+ return Color{
4828
+ rawColor.A ,
4829
+ rawColor.R ,
4830
+ rawColor.G ,
4831
+ rawColor.B
4832
+ };
4833
+ case ThemeColorType::TerminalBackground:
4834
+ {
4835
+ const auto themeBrush{ colorToCopy.Evaluate (resourceDictionary, backgroundBrush, false ) };
4836
+ auto terminalBg = ThemeColor::ColorFromBrush (themeBrush);
4837
+ return Color{
4838
+ terminalBg.A ,
4839
+ terminalBg.R ,
4840
+ terminalBg.G ,
4841
+ terminalBg.B
4842
+ };
4843
+ }
4844
+ default :
4845
+ assert (false && " unknown type for color type in theme color" ); // should never be reached
4846
+ return winrt::Windows::UI::Color{};
4847
+ }
4848
+ }
4849
+
4799
4850
// Function Description:
4800
4851
// - Attempts to load some XAML resources that Panes will need. This includes:
4801
4852
// * The Color they'll use for active Panes's borders - SystemAccentColor
4802
4853
// * The Brush they'll use for inactive Panes - TabViewBackground (to match the
4803
4854
// color of the titlebar)
4804
4855
// Arguments:
4805
4856
// - requestedTheme: this should be the currently active Theme for the app
4857
+ // - activeBorderColor: the pane's border color for the application when it is active
4858
+ // - inactiveBorderColor: the pane's border color for the application when it is inactive
4859
+ // - broadcastBorderColor: the pane's border color for the application when it is broadcast
4806
4860
// Return Value:
4807
4861
// - <none>
4808
- void TerminalPage::_updatePaneResources (const winrt::Windows::UI::Xaml:: ElementTheme& requestedTheme)
4862
+ void TerminalPage::_updatePaneResources (const ElementTheme& requestedTheme, const PaneTheme& paneTheme, const Media::Brush& backgroundBrush )
4809
4863
{
4864
+ const auto paneActiveBorderColor = paneTheme ? paneTheme.ActiveBorderColor () : nullptr ;
4865
+ const auto paneInactiveBorderColor = paneTheme ? paneTheme.InactiveBorderColor () : nullptr ;
4866
+ const auto broadcastBorderColor = paneTheme ? paneTheme.BroadcastBorderColor () : nullptr ;
4810
4867
const auto res = Application::Current ().Resources ();
4811
- const auto accentColorKey = winrt::box_value (L" SystemAccentColor" );
4812
- if (res.HasKey (accentColorKey))
4813
- {
4814
- const auto colorFromResources = ThemeLookup (res, requestedTheme, accentColorKey);
4815
- // If SystemAccentColor is _not_ a Color for some reason, use
4816
- // Transparent as the color, so we don't do this process again on
4817
- // the next pane (by leaving s_focusedBorderBrush nullptr)
4818
- auto actualColor = winrt::unbox_value_or<Color>(colorFromResources, Colors::Black ());
4819
- _paneResources.focusedBorderBrush = SolidColorBrush (actualColor);
4820
- }
4821
- else
4822
- {
4823
- // DON'T use Transparent here - if it's "Transparent", then it won't
4824
- // be able to hittest for clicks, and then clicking on the border
4825
- // will eat focus.
4826
- _paneResources.focusedBorderBrush = SolidColorBrush{ Colors::Black () };
4827
- }
4828
-
4829
- const auto unfocusedBorderBrushKey = winrt::box_value (L" UnfocusedBorderBrush" );
4830
- if (res.HasKey (unfocusedBorderBrushKey))
4831
- {
4832
- // MAKE SURE TO USE ThemeLookup, so that we get the correct resource for
4833
- // the requestedTheme, not just the value from the resources (which
4834
- // might not respect the settings' requested theme)
4835
- auto obj = ThemeLookup (res, requestedTheme, unfocusedBorderBrushKey);
4836
- _paneResources.unfocusedBorderBrush = obj.try_as <winrt::Windows::UI::Xaml::Media::SolidColorBrush>();
4837
- }
4838
- else
4839
- {
4840
- // DON'T use Transparent here - if it's "Transparent", then it won't
4841
- // be able to hittest for clicks, and then clicking on the border
4842
- // will eat focus.
4843
- _paneResources.unfocusedBorderBrush = SolidColorBrush{ Colors::Black () };
4844
- }
4845
-
4846
- const auto broadcastColorKey = winrt::box_value (L" BroadcastPaneBorderColor" );
4847
- if (res.HasKey (broadcastColorKey))
4848
- {
4849
- // MAKE SURE TO USE ThemeLookup
4850
- auto obj = ThemeLookup (res, requestedTheme, broadcastColorKey);
4851
- _paneResources.broadcastBorderBrush = obj.try_as <winrt::Windows::UI::Xaml::Media::SolidColorBrush>();
4852
- }
4853
- else
4854
- {
4855
- // DON'T use Transparent here - if it's "Transparent", then it won't
4856
- // be able to hittest for clicks, and then clicking on the border
4857
- // will eat focus.
4858
- _paneResources.broadcastBorderBrush = SolidColorBrush{ Colors::Black () };
4859
- }
4868
+ const IInspectable accentKey = winrt::box_value (L" SystemAccentColor" );
4869
+ const auto parseRelevantColorForKeyAndTheme = [this , res, requestedTheme, backgroundBrush, accentKey](const winrt::param::hstring& keyString, ThemeColor paneTheme) {
4870
+ const IInspectable key = winrt::box_value (keyString);
4871
+ return paneTheme ? _parseThemeColorToColor (paneTheme, res, requestedTheme, accentKey, backgroundBrush) : _colorFromKey (res, requestedTheme, key);
4872
+ };
4873
+ const auto activeBrushColor = parseRelevantColorForKeyAndTheme (L" SystemAccentColor" , paneActiveBorderColor);
4874
+ const auto inactiveBrushColor = parseRelevantColorForKeyAndTheme (L" UnfocusedBorderBrush" , paneInactiveBorderColor);
4875
+ const auto broadcastBrushColor = parseRelevantColorForKeyAndTheme (L" BroadcastPaneBorderColor" , broadcastBorderColor);
4876
+ // For the following brushes:
4877
+ // DON'T use Transparent here - if it's "Transparent", then it won't
4878
+ // be able to hittest for clicks, and then clicking on the border
4879
+ // will eat focus.
4880
+ _paneResources.focusedBorderBrush = SolidColorBrush (activeBrushColor);
4881
+ _paneResources.unfocusedBorderBrush = SolidColorBrush (inactiveBrushColor);
4882
+ _paneResources.broadcastBorderBrush = SolidColorBrush (broadcastBrushColor);
4860
4883
}
4861
4884
4862
4885
void TerminalPage::WindowActivated (const bool activated)
0 commit comments