Skip to content

Setting to set pane highlight active, inactive and broadcast color #18953

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions doc/cascadia/profiles.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -2000,6 +2000,24 @@
}
}
},
"PaneTheme": {
"additionalProperties": false,
"description": "A set of properties for customizing the appearance of the panes",
"properties": {
"activeBorderColor": {
"description": "The color of the pane border when the pane is active",
"$ref": "#/$defs/ThemeColor"
},
"inactiveBorderColor": {
"description": "The color of the pane border when the pane is inactive",
"$ref": "#/$defs/ThemeColor"
},
"broadcastBorderColor": {
"description": "The color of the pane border when broadcasted",
"$ref": "#/$defs/ThemeColor"
}
}
},
"WindowTheme": {
"additionalProperties": false,
"description": "A set of properties for customizing the appearance of the window itself",
Expand Down Expand Up @@ -2056,6 +2074,9 @@
},
"window": {
"$ref": "#/$defs/WindowTheme"
},
"pane": {
"$ref": "#/$defs/PaneTheme"
}
}
},
Expand Down
153 changes: 88 additions & 65 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4689,11 +4689,21 @@ namespace winrt::TerminalApp::implementation
}

const auto theme = _settings.GlobalSettings().CurrentTheme();
auto requestedTheme{ theme.RequestedTheme() };

const auto requestedTheme{ theme.RequestedTheme() };
Media::Brush terminalBrush{ nullptr };
if (const auto tab{ _GetFocusedTabImpl() })
{
_updatePaneResources(requestedTheme);
if (const auto& pane{ tab->GetActivePane() })
{
if (const auto& lastContent{ pane->GetLastFocusedContent() })
{
terminalBrush = lastContent.BackgroundBrush();
}
}
}

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

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

Media::Brush terminalBrush{ nullptr };
if (const auto tab{ _GetFocusedTabImpl() })
{
if (const auto& pane{ tab->GetActivePane() })
{
if (const auto& lastContent{ pane->GetLastFocusedContent() })
{
terminalBrush = lastContent.BackgroundBrush();
}
}
}

if (_settings.GlobalSettings().UseAcrylicInTabRow())
{
const auto acrylicBrush = Media::AcrylicBrush();
Expand Down Expand Up @@ -4796,67 +4794,92 @@ namespace winrt::TerminalApp::implementation
}
}


Color TerminalPage::_colorFromKey(const ResourceDictionary& resourceDictionary, const ElementTheme& requestedTheme, const IInspectable& colorKey)
{
const auto defaultColor = Colors::Black();
if (!resourceDictionary.HasKey(colorKey))
{
return defaultColor;
}
return winrt::unbox_value_or<Color>(
ThemeLookup(resourceDictionary, requestedTheme, colorKey),
defaultColor
);
}

Color TerminalPage::_parseThemeColorToColor(
const ThemeColor& colorToCopy,
const ResourceDictionary& resourceDictionary,
const ElementTheme& requestedTheme,
const IInspectable& accentKey,
const Media::Brush& backgroundBrush
)
{
switch (colorToCopy.ColorType())
{
case ThemeColorType::Accent:
{
return _colorFromKey(resourceDictionary, requestedTheme, accentKey);
}
case ThemeColorType::Color:
const auto rawColor = colorToCopy.Color();
return Color{
rawColor.A,
rawColor.R,
rawColor.G,
rawColor.B
};
case ThemeColorType::TerminalBackground:
{
const auto themeBrush{ colorToCopy.Evaluate(resourceDictionary, backgroundBrush, false) };
auto terminalBg = ThemeColor::ColorFromBrush(themeBrush);
return Color{
terminalBg.A,
terminalBg.R,
terminalBg.G,
terminalBg.B
};
}
default:
assert(false && "unknown type for color type in theme color"); // should never be reached
return winrt::Windows::UI::Color{};
}
}

// Function Description:
// - Attempts to load some XAML resources that Panes will need. This includes:
// * The Color they'll use for active Panes's borders - SystemAccentColor
// * The Brush they'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
// - activeBorderColor: the pane's border color for the application when it is active
// - inactiveBorderColor: the pane's border color for the application when it is inactive
// - broadcastBorderColor: the pane's border color for the application when it is broadcast
// Return Value:
// - <none>
void TerminalPage::_updatePaneResources(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme)
void TerminalPage::_updatePaneResources(const ElementTheme& requestedTheme, const PaneTheme& paneTheme, const Media::Brush& backgroundBrush)
{
const auto paneActiveBorderColor = paneTheme ? paneTheme.ActiveBorderColor() : nullptr;
const auto paneInactiveBorderColor = paneTheme ? paneTheme.InactiveBorderColor() : nullptr;
const auto broadcastBorderColor = paneTheme ? paneTheme.BroadcastBorderColor() : nullptr;
const auto res = Application::Current().Resources();
const auto accentColorKey = winrt::box_value(L"SystemAccentColor");
if (res.HasKey(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)
auto actualColor = winrt::unbox_value_or<Color>(colorFromResources, Colors::Black());
_paneResources.focusedBorderBrush = SolidColorBrush(actualColor);
}
else
{
// DON'T use Transparent here - if it's "Transparent", then it won't
// be able to hittest for clicks, and then clicking on the border
// will eat focus.
_paneResources.focusedBorderBrush = SolidColorBrush{ Colors::Black() };
}

const auto unfocusedBorderBrushKey = winrt::box_value(L"UnfocusedBorderBrush");
if (res.HasKey(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);
_paneResources.unfocusedBorderBrush = obj.try_as<winrt::Windows::UI::Xaml::Media::SolidColorBrush>();
}
else
{
// DON'T use Transparent here - if it's "Transparent", then it won't
// be able to hittest for clicks, and then clicking on the border
// will eat focus.
_paneResources.unfocusedBorderBrush = SolidColorBrush{ Colors::Black() };
}

const auto broadcastColorKey = winrt::box_value(L"BroadcastPaneBorderColor");
if (res.HasKey(broadcastColorKey))
{
// MAKE SURE TO USE ThemeLookup
auto obj = ThemeLookup(res, requestedTheme, broadcastColorKey);
_paneResources.broadcastBorderBrush = obj.try_as<winrt::Windows::UI::Xaml::Media::SolidColorBrush>();
}
else
{
// DON'T use Transparent here - if it's "Transparent", then it won't
// be able to hittest for clicks, and then clicking on the border
// will eat focus.
_paneResources.broadcastBorderBrush = SolidColorBrush{ Colors::Black() };
}
const IInspectable accentKey = winrt::box_value(L"SystemAccentColor");
const auto parseRelevantColorForKeyAndTheme = [this, res, requestedTheme, backgroundBrush, accentKey](const winrt::param::hstring& keyString, ThemeColor paneTheme) {
const IInspectable key = winrt::box_value(keyString);
return paneTheme ? _parseThemeColorToColor(paneTheme, res, requestedTheme, accentKey, backgroundBrush) : _colorFromKey(res, requestedTheme, key);
};
const auto activeBrushColor = parseRelevantColorForKeyAndTheme(L"SystemAccentColor", paneActiveBorderColor);
const auto inactiveBrushColor = parseRelevantColorForKeyAndTheme(L"UnfocusedBorderBrush", paneInactiveBorderColor);
const auto broadcastBrushColor = parseRelevantColorForKeyAndTheme(L"BroadcastPaneBorderColor", broadcastBorderColor);
// For the following brushes:
// DON'T use Transparent here - if it's "Transparent", then it won't
// be able to hittest for clicks, and then clicking on the border
// will eat focus.
_paneResources.focusedBorderBrush = SolidColorBrush(activeBrushColor);
_paneResources.unfocusedBorderBrush = SolidColorBrush(inactiveBrushColor);
_paneResources.broadcastBorderBrush = SolidColorBrush(broadcastBrushColor);
}

void TerminalPage::WindowActivated(const bool activated)
Expand Down
4 changes: 3 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,9 @@ namespace winrt::TerminalApp::implementation

void _updateThemeColors();
void _updateAllTabCloseButtons();
void _updatePaneResources(const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme);
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);
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);
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);

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

Expand Down
8 changes: 7 additions & 1 deletion src/cascadia/TerminalSettingsModel/MTSMSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,8 @@ Author(s):
X(winrt::Microsoft::Terminal::Settings::Model::WindowTheme, Window, "window", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::SettingsTheme, Settings, "settings", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::TabRowTheme, TabRow, "tabRow", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::TabTheme, Tab, "tab", nullptr)
X(winrt::Microsoft::Terminal::Settings::Model::TabTheme, Tab, "tab", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::PaneTheme, Pane, "pane", nullptr)

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

#define MTSM_THEME_PANE_SETTINGS(X) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, ActiveBorderColor, "activeBorderColor", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, InactiveBorderColor, "inactiveBorderColor", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, BroadcastBorderColor, "broadcastBorderColor", nullptr)

#define MTSM_THEME_TAB_SETTINGS(X) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, UnfocusedBackground, "unfocusedBackground", nullptr) \
Expand Down
14 changes: 14 additions & 0 deletions src/cascadia/TerminalSettingsModel/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "SettingsTheme.g.h"
#include "ThemeColor.g.cpp"
#include "WindowTheme.g.cpp"
#include "PaneTheme.g.cpp"
#include "TabRowTheme.g.cpp"
#include "TabTheme.g.cpp"
#include "ThemePair.g.cpp"
Expand Down Expand Up @@ -60,6 +61,7 @@ THEME_OBJECT(WindowTheme, MTSM_THEME_WINDOW_SETTINGS);
THEME_OBJECT(SettingsTheme, MTSM_THEME_SETTINGS_SETTINGS);
THEME_OBJECT(TabRowTheme, MTSM_THEME_TABROW_SETTINGS);
THEME_OBJECT(TabTheme, MTSM_THEME_TAB_SETTINGS);
THEME_OBJECT(PaneTheme, MTSM_THEME_PANE_SETTINGS);

#undef THEME_SETTINGS_COPY
#undef THEME_SETTINGS_TO_JSON
Expand Down Expand Up @@ -224,6 +226,7 @@ THEME_OBJECT_CONVERTER(winrt::Microsoft::Terminal::Settings::Model, WindowTheme,
THEME_OBJECT_CONVERTER(winrt::Microsoft::Terminal::Settings::Model, SettingsTheme, MTSM_THEME_SETTINGS_SETTINGS);
THEME_OBJECT_CONVERTER(winrt::Microsoft::Terminal::Settings::Model, TabRowTheme, MTSM_THEME_TABROW_SETTINGS);
THEME_OBJECT_CONVERTER(winrt::Microsoft::Terminal::Settings::Model, TabTheme, MTSM_THEME_TAB_SETTINGS);
THEME_OBJECT_CONVERTER(winrt::Microsoft::Terminal::Settings::Model, PaneTheme, MTSM_THEME_PANE_SETTINGS);

#undef THEME_SETTINGS_FROM_JSON
#undef THEME_SETTINGS_TO_JSON
Expand Down Expand Up @@ -254,6 +257,10 @@ winrt::com_ptr<Theme> Theme::Copy() const
{
theme->_Tab = *winrt::get_self<implementation::TabTheme>(_Tab)->Copy();
}
if (_Pane)
{
theme->_Pane = *winrt::get_self<implementation::PaneTheme>(_Pane)->Copy();
}
if (_Settings)
{
theme->_Settings = *winrt::get_self<implementation::SettingsTheme>(_Settings)->Copy();
Expand Down Expand Up @@ -334,6 +341,13 @@ void Theme::LogSettingChanges(std::set<std::string>& changes, const std::string_
const auto outerJsonKey = outerTabJsonKey;
MTSM_THEME_TAB_SETTINGS(LOG_IF_SET)
}

if (isPaneSet)
{
const auto obj = _Pane;
const auto outerJsonKey = outerPaneJsonKey;
MTSM_THEME_PANE_SETTINGS(LOG_IF_SET);
}
#undef LOG_IF_SET
#undef GENERATE_SET_CHECK_AND_JSON_KEYS
#pragma warning(pop)
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/Theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ Author(s):
#include "WindowTheme.g.h"
#include "TabRowTheme.g.h"
#include "TabTheme.g.h"
#include "PaneTheme.g.h"
#include "ThemePair.g.h"
#include "Theme.g.h"

Expand Down Expand Up @@ -85,6 +86,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
THEME_OBJECT(SettingsTheme, MTSM_THEME_SETTINGS_SETTINGS);
THEME_OBJECT(TabRowTheme, MTSM_THEME_TABROW_SETTINGS);
THEME_OBJECT(TabTheme, MTSM_THEME_TAB_SETTINGS);
THEME_OBJECT(PaneTheme, MTSM_THEME_PANE_SETTINGS);

struct Theme : ThemeT<Theme>
{
Expand Down
9 changes: 9 additions & 0 deletions src/cascadia/TerminalSettingsModel/Theme.idl
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ namespace Microsoft.Terminal.Settings.Model
ThemeColor UnfocusedBackground { get; };
}

runtimeclass PaneTheme {
ThemeColor ActiveBorderColor { get; };
ThemeColor InactiveBorderColor { get; };
ThemeColor BroadcastBorderColor { get; };
}

runtimeclass TabTheme {
ThemeColor Background { get; };
ThemeColor UnfocusedBackground { get; };
Expand All @@ -93,6 +99,9 @@ namespace Microsoft.Terminal.Settings.Model
// tabRow.* Namespace
TabRowTheme TabRow { get; };

// pane.* Namespace
PaneTheme Pane { get; };

// tab.* Namespace
TabTheme Tab { get; };

Expand Down
Loading