Skip to content

Commit 320267c

Browse files
committed
Setting to set pane highlight active, inactive and broadcast color
This commit adds a new setting in which you can configure the active highlight color of panes aswell as inactive and broadcast.
1 parent e332c67 commit 320267c

File tree

7 files changed

+144
-67
lines changed

7 files changed

+144
-67
lines changed

doc/cascadia/profiles.schema.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,24 @@
20002000
}
20012001
}
20022002
},
2003+
"PaneTheme": {
2004+
"additionalProperties": false,
2005+
"description": "A set of properties for customizing the appearance of the panes",
2006+
"properties": {
2007+
"activeBorderColor": {
2008+
"description": "The color of the pane border when the pane is active",
2009+
"$ref": "#/$defs/ThemeColor"
2010+
},
2011+
"inactiveBorderColor": {
2012+
"description": "The color of the pane border when the pane is inactive",
2013+
"$ref": "#/$defs/ThemeColor"
2014+
},
2015+
"broadcastBorderColor": {
2016+
"description": "The color of the pane border when broadcasted",
2017+
"$ref": "#/$defs/ThemeColor"
2018+
}
2019+
}
2020+
},
20032021
"WindowTheme": {
20042022
"additionalProperties": false,
20052023
"description": "A set of properties for customizing the appearance of the window itself",
@@ -2056,6 +2074,9 @@
20562074
},
20572075
"window": {
20582076
"$ref": "#/$defs/WindowTheme"
2077+
},
2078+
"pane": {
2079+
"$ref": "#/$defs/PaneTheme"
20592080
}
20602081
}
20612082
},

src/cascadia/TerminalApp/TerminalPage.cpp

Lines changed: 88 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -4689,11 +4689,21 @@ namespace winrt::TerminalApp::implementation
46894689
}
46904690

46914691
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() })
46944695
{
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+
}
46964704

4705+
{
4706+
_updatePaneResources(requestedTheme, theme.Pane(), terminalBrush);
46974707
for (const auto& tab : _tabs)
46984708
{
46994709
if (auto terminalTab{ _GetTerminalTabImpl(tab) })
@@ -4715,18 +4725,6 @@ namespace winrt::TerminalApp::implementation
47154725

47164726
til::color bgColor = backgroundSolidBrush.Color();
47174727

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-
47304728
if (_settings.GlobalSettings().UseAcrylicInTabRow())
47314729
{
47324730
const auto acrylicBrush = Media::AcrylicBrush();
@@ -4796,67 +4794,92 @@ namespace winrt::TerminalApp::implementation
47964794
}
47974795
}
47984796

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+
47994850
// Function Description:
48004851
// - Attempts to load some XAML resources that Panes will need. This includes:
48014852
// * The Color they'll use for active Panes's borders - SystemAccentColor
48024853
// * The Brush they'll use for inactive Panes - TabViewBackground (to match the
48034854
// color of the titlebar)
48044855
// Arguments:
48054856
// - 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
48064860
// Return Value:
48074861
// - <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)
48094863
{
4864+
const auto paneActiveBorderColor = paneTheme ? paneTheme.ActiveBorderColor() : nullptr;
4865+
const auto paneInactiveBorderColor = paneTheme ? paneTheme.InactiveBorderColor() : nullptr;
4866+
const auto broadcastBorderColor = paneTheme ? paneTheme.BroadcastBorderColor() : nullptr;
48104867
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);
48604883
}
48614884

48624885
void TerminalPage::WindowActivated(const bool activated)

src/cascadia/TerminalApp/TerminalPage.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,9 @@ namespace winrt::TerminalApp::implementation
519519

520520
void _updateThemeColors();
521521
void _updateAllTabCloseButtons();
522-
void _updatePaneResources(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme);
522+
winrt::Windows::UI::Color _colorFromKey(const winrt::Windows::UI::Xaml::ResourceDictionary& resourceDictionary, const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme, const winrt::Windows::Foundation::IInspectable& colorKey);
523+
winrt::Windows::UI::Color _parseThemeColorToColor(const winrt::Microsoft::Terminal::Settings::Model::ThemeColor& colorToCopy, const winrt::Windows::UI::Xaml::ResourceDictionary& resourceDictionary, const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme, const winrt::Windows::Foundation::IInspectable& accentKey, const winrt::Windows::UI::Xaml::Media::Brush& backgroundBrush);
524+
void _updatePaneResources(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme, const winrt::Microsoft::Terminal::Settings::Model::PaneTheme& paneTheme, const winrt::Windows::UI::Xaml::Media::Brush& backgroundBrush);
523525

524526
safe_void_coroutine _ControlCompletionsChangedHandler(const winrt::Windows::Foundation::IInspectable sender, const winrt::Microsoft::Terminal::Control::CompletionsChangedEventArgs args);
525527

src/cascadia/TerminalSettingsModel/MTSMSettings.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,8 @@ Author(s):
147147
X(winrt::Microsoft::Terminal::Settings::Model::WindowTheme, Window, "window", nullptr) \
148148
X(winrt::Microsoft::Terminal::Settings::Model::SettingsTheme, Settings, "settings", nullptr) \
149149
X(winrt::Microsoft::Terminal::Settings::Model::TabRowTheme, TabRow, "tabRow", nullptr) \
150-
X(winrt::Microsoft::Terminal::Settings::Model::TabTheme, Tab, "tab", nullptr)
150+
X(winrt::Microsoft::Terminal::Settings::Model::TabTheme, Tab, "tab", nullptr) \
151+
X(winrt::Microsoft::Terminal::Settings::Model::PaneTheme, Pane, "pane", nullptr)
151152

152153
#define MTSM_THEME_WINDOW_SETTINGS(X) \
153154
X(winrt::Windows::UI::Xaml::ElementTheme, RequestedTheme, "applicationTheme", winrt::Windows::UI::Xaml::ElementTheme::Default) \
@@ -163,6 +164,11 @@ Author(s):
163164
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr) \
164165
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, UnfocusedBackground, "unfocusedBackground", nullptr)
165166

167+
#define MTSM_THEME_PANE_SETTINGS(X) \
168+
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, ActiveBorderColor, "activeBorderColor", nullptr) \
169+
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, InactiveBorderColor, "inactiveBorderColor", nullptr) \
170+
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, BroadcastBorderColor, "broadcastBorderColor", nullptr)
171+
166172
#define MTSM_THEME_TAB_SETTINGS(X) \
167173
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr) \
168174
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, UnfocusedBackground, "unfocusedBackground", nullptr) \

src/cascadia/TerminalSettingsModel/Theme.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "SettingsTheme.g.h"
1313
#include "ThemeColor.g.cpp"
1414
#include "WindowTheme.g.cpp"
15+
#include "PaneTheme.g.cpp"
1516
#include "TabRowTheme.g.cpp"
1617
#include "TabTheme.g.cpp"
1718
#include "ThemePair.g.cpp"
@@ -60,6 +61,7 @@ THEME_OBJECT(WindowTheme, MTSM_THEME_WINDOW_SETTINGS);
6061
THEME_OBJECT(SettingsTheme, MTSM_THEME_SETTINGS_SETTINGS);
6162
THEME_OBJECT(TabRowTheme, MTSM_THEME_TABROW_SETTINGS);
6263
THEME_OBJECT(TabTheme, MTSM_THEME_TAB_SETTINGS);
64+
THEME_OBJECT(PaneTheme, MTSM_THEME_PANE_SETTINGS);
6365

6466
#undef THEME_SETTINGS_COPY
6567
#undef THEME_SETTINGS_TO_JSON
@@ -224,6 +226,7 @@ THEME_OBJECT_CONVERTER(winrt::Microsoft::Terminal::Settings::Model, WindowTheme,
224226
THEME_OBJECT_CONVERTER(winrt::Microsoft::Terminal::Settings::Model, SettingsTheme, MTSM_THEME_SETTINGS_SETTINGS);
225227
THEME_OBJECT_CONVERTER(winrt::Microsoft::Terminal::Settings::Model, TabRowTheme, MTSM_THEME_TABROW_SETTINGS);
226228
THEME_OBJECT_CONVERTER(winrt::Microsoft::Terminal::Settings::Model, TabTheme, MTSM_THEME_TAB_SETTINGS);
229+
THEME_OBJECT_CONVERTER(winrt::Microsoft::Terminal::Settings::Model, PaneTheme, MTSM_THEME_PANE_SETTINGS);
227230

228231
#undef THEME_SETTINGS_FROM_JSON
229232
#undef THEME_SETTINGS_TO_JSON
@@ -254,6 +257,10 @@ winrt::com_ptr<Theme> Theme::Copy() const
254257
{
255258
theme->_Tab = *winrt::get_self<implementation::TabTheme>(_Tab)->Copy();
256259
}
260+
if (_Pane)
261+
{
262+
theme->_Pane = *winrt::get_self<implementation::PaneTheme>(_Pane)->Copy();
263+
}
257264
if (_Settings)
258265
{
259266
theme->_Settings = *winrt::get_self<implementation::SettingsTheme>(_Settings)->Copy();
@@ -334,6 +341,13 @@ void Theme::LogSettingChanges(std::set<std::string>& changes, const std::string_
334341
const auto outerJsonKey = outerTabJsonKey;
335342
MTSM_THEME_TAB_SETTINGS(LOG_IF_SET)
336343
}
344+
345+
if (isPaneSet)
346+
{
347+
const auto obj = _Pane;
348+
const auto outerJsonKey = outerPaneJsonKey;
349+
MTSM_THEME_PANE_SETTINGS(LOG_IF_SET);
350+
}
337351
#undef LOG_IF_SET
338352
#undef GENERATE_SET_CHECK_AND_JSON_KEYS
339353
#pragma warning(pop)

src/cascadia/TerminalSettingsModel/Theme.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Author(s):
2323
#include "WindowTheme.g.h"
2424
#include "TabRowTheme.g.h"
2525
#include "TabTheme.g.h"
26+
#include "PaneTheme.g.h"
2627
#include "ThemePair.g.h"
2728
#include "Theme.g.h"
2829

@@ -85,6 +86,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
8586
THEME_OBJECT(SettingsTheme, MTSM_THEME_SETTINGS_SETTINGS);
8687
THEME_OBJECT(TabRowTheme, MTSM_THEME_TABROW_SETTINGS);
8788
THEME_OBJECT(TabTheme, MTSM_THEME_TAB_SETTINGS);
89+
THEME_OBJECT(PaneTheme, MTSM_THEME_PANE_SETTINGS);
8890

8991
struct Theme : ThemeT<Theme>
9092
{

src/cascadia/TerminalSettingsModel/Theme.idl

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ namespace Microsoft.Terminal.Settings.Model
7171
ThemeColor UnfocusedBackground { get; };
7272
}
7373

74+
runtimeclass PaneTheme {
75+
ThemeColor ActiveBorderColor { get; };
76+
ThemeColor InactiveBorderColor { get; };
77+
ThemeColor BroadcastBorderColor { get; };
78+
}
79+
7480
runtimeclass TabTheme {
7581
ThemeColor Background { get; };
7682
ThemeColor UnfocusedBackground { get; };
@@ -93,6 +99,9 @@ namespace Microsoft.Terminal.Settings.Model
9399
// tabRow.* Namespace
94100
TabRowTheme TabRow { get; };
95101

102+
// pane.* Namespace
103+
PaneTheme Pane { get; };
104+
96105
// tab.* Namespace
97106
TabTheme Tab { get; };
98107

0 commit comments

Comments
 (0)