@@ -4689,11 +4689,10 @@ namespace winrt::TerminalApp::implementation
46894689        }
46904690
46914691        const  auto  theme = _settings.GlobalSettings ().CurrentTheme ();
4692-         auto  requestedTheme{ theme.RequestedTheme () };
4692+         const   auto  requestedTheme{ theme.RequestedTheme () };
46934693
46944694        {
4695-             _updatePaneResources (requestedTheme);
4696- 
4695+             _updatePaneResources (requestedTheme, theme.Pane ());
46974696            for  (const  auto & tab : _tabs)
46984697            {
46994698                if  (auto  terminalTab{ _GetTerminalTabImpl (tab) })
@@ -4796,67 +4795,94 @@ namespace winrt::TerminalApp::implementation
47964795        }
47974796    }
47984797
4798+ 
4799+ 	Color TerminalPage::_colorFromKey (const  ResourceDictionary& resourceDictionary, const  ElementTheme& requestedTheme, const  IInspectable& colorKey)
4800+ 	{
4801+         const  auto  defaultColor = Colors::Black ();
4802+         if  (!resourceDictionary.HasKey (colorKey))
4803+         {
4804+             return  defaultColor;
4805+         }
4806+         return  winrt::unbox_value_or<Color>(
4807+             ThemeLookup (resourceDictionary, requestedTheme, colorKey),
4808+             defaultColor
4809+         );
4810+ 	}
4811+ 
4812+ 	Color TerminalPage::_parseThemeColorToColor (
4813+ 		const  ThemeColor& colorToCopy,
4814+         const  ResourceDictionary& resourceDictionary,
4815+         const  ElementTheme& requestedTheme,
4816+         const  IInspectable& colorKey
4817+ 	)
4818+     {
4819+         switch  (colorToCopy.ColorType ())
4820+         {
4821+         case  ThemeColorType::Accent:
4822+             return  _colorFromKey (resourceDictionary, requestedTheme, colorKey);
4823+         case  ThemeColorType::Color:
4824+             const  auto  rawColor = colorToCopy.Color ();
4825+             return  Color{
4826+                 rawColor.A ,
4827+                 rawColor.R ,
4828+                 rawColor.G ,
4829+                 rawColor.B 
4830+             };
4831+         case  ThemeColorType::TerminalBackground:
4832+             //  does not work
4833+             const  auto  terminalBg = ThemeColor::FromTerminalBackground ().Color ();
4834+             return  Color{
4835+                 terminalBg.A ,
4836+                 terminalBg.R ,
4837+                 terminalBg.G ,
4838+                 terminalBg.B 
4839+             };
4840+         default :
4841+             assert (false  && " unknown type for color type in theme color" //  should never be reached
4842+             return  winrt::Windows::UI::Color{};
4843+         }
4844+ 	}
4845+ 
47994846    //  Function Description:
48004847    //  - Attempts to load some XAML resources that Panes will need. This includes:
48014848    //    * The Color they'll use for active Panes's borders - SystemAccentColor
48024849    //    * The Brush they'll use for inactive Panes - TabViewBackground (to match the
48034850    //      color of the titlebar)
48044851    //  Arguments:
48054852    //  - requestedTheme: this should be the currently active Theme for the app
4853+     //  - activeBorderColor: the pane's border color for the application when it is active
4854+     //  - inactiveBorderColor: the pane's border color for the application when it is inactive
4855+     //  - broadcastBorderColor: the pane's border color for the application when it is broadcast
48064856    //  Return Value:
48074857    //  - <none>
4808-     void  TerminalPage::_updatePaneResources (const  winrt::Windows::UI::Xaml:: ElementTheme& requestedTheme)
4858+     void  TerminalPage::_updatePaneResources (const  ElementTheme& requestedTheme,  const  PaneTheme& paneTheme )
48094859    {
4860+         const  auto  paneActiveBorderColor = paneTheme ? paneTheme.ActiveBorderColor () : nullptr ;
4861+         const  auto  paneInactiveBorderColor = paneTheme ? paneTheme.InactiveBorderColor () : nullptr ;
4862+         const  auto  broadcastBorderColor = paneTheme ? paneTheme.BroadcastBorderColor () : nullptr ;
48104863        const  auto  res = Application::Current ().Resources ();
4811-         const  auto  accentColorKey = winrt::box_value (L" SystemAccentColor" 
4812-         if  (res.HasKey (accentColorKey))
4864+         const  auto  tmp = ThemeColor::FromTerminalBackground ();
4865+         const  auto  color = tmp.Color ();
4866+         if  (tmp)
48134867        {
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);
48204868        }
4821-         else 
4869+         if  (color. A ) 
48224870        {
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 () };
48594871        }
4872+         const  auto  parseRelevantColorForKeyAndTheme = [this , res, requestedTheme] (const  winrt::param::hstring& keyString, ThemeColor paneTheme) {
4873+             const  IInspectable key = winrt::box_value (keyString);
4874+             return  paneTheme ? _parseThemeColorToColor (paneTheme, res, requestedTheme, key) : _colorFromKey (res, requestedTheme, key);
4875+         };
4876+         const  auto  activeBrushColor = parseRelevantColorForKeyAndTheme (L" SystemAccentColor" 
4877+         const  auto  inactiveBrushColor = parseRelevantColorForKeyAndTheme (L" UnfocusedBorderBrush" 
4878+         const  auto  broadcastBrushColor = parseRelevantColorForKeyAndTheme (L" BroadcastPaneBorderColor" 
4879+         //  For the following brushes:
4880+         //  DON'T use Transparent here - if it's "Transparent", then it won't
4881+         //  be able to hittest for clicks, and then clicking on the border
4882+         //  will eat focus.
4883+         _paneResources.focusedBorderBrush  = SolidColorBrush (activeBrushColor);
4884+         _paneResources.unfocusedBorderBrush  = SolidColorBrush (inactiveBrushColor);
4885+         _paneResources.broadcastBorderBrush  = SolidColorBrush (broadcastBrushColor);
48604886    }
48614887
48624888    void  TerminalPage::WindowActivated (const  bool  activated)
0 commit comments