Skip to content

Commit

Permalink
Add a setting for the unfocused tabRow background color (#13049)
Browse files Browse the repository at this point in the history
Adds `tabRow.unfocusedBackground` to the theme properties.

When provided, the window will use this ThemeColor as the color of the tab row when the window is inactive. 

When omitted, the window will fall back to the default tab row color, `{"key": "TabViewBackground"}` from our App.xaml.

* [ ] tests added.
* [x] Closes #4862
* [ ] Needs a whole pile of docs updates, which we'll do at the end here.


This actually helped validate #12992 quite a bit. I found a bunch of bugs concerning null colors, null objects. Json parsing is hard 😛
  • Loading branch information
zadjii-msft authored Jul 7, 2022
1 parent aa4e9f5 commit 024b9fc
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
35 changes: 19 additions & 16 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4101,24 +4101,27 @@ namespace winrt::TerminalApp::implementation

TitlebarBrush(acrylicBrush);
}
else if (theme.TabRow() && theme.TabRow().Background())
else if (theme.TabRow())
{
const auto tabRowBg = theme.TabRow().Background();
const auto terminalBrush = [this]() -> Media::Brush {
if (const auto& control{ _GetActiveControl() })
{
return control.BackgroundBrush();
}
else if (auto settingsTab = _GetFocusedTab().try_as<TerminalApp::SettingsTab>())
{
return settingsTab.Content().try_as<Settings::Editor::MainPage>().BackgroundBrush();
}
return nullptr;
}();
if (const auto tabRowBg{ _activated ? theme.TabRow().Background() :
theme.TabRow().UnfocusedBackground() })
{
const auto terminalBrush = [this]() -> Media::Brush {
if (const auto& control{ _GetActiveControl() })
{
return control.BackgroundBrush();
}
else if (auto settingsTab = _GetFocusedTab().try_as<TerminalApp::SettingsTab>())
{
return settingsTab.Content().try_as<Settings::Editor::MainPage>().BackgroundBrush();
}
return nullptr;
}();

const auto themeBrush{ tabRowBg.Evaluate(res, terminalBrush, true) };
bgColor = ThemeColor::ColorFromBrush(themeBrush);
TitlebarBrush(themeBrush);
const auto themeBrush{ tabRowBg.Evaluate(res, terminalBrush, true) };
bgColor = ThemeColor::ColorFromBrush(themeBrush);
TitlebarBrush(themeBrush);
}
}
else
{
Expand Down
5 changes: 3 additions & 2 deletions src/cascadia/TerminalSettingsModel/MTSMSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,9 @@ Author(s):
X(winrt::Windows::UI::Xaml::ElementTheme, RequestedTheme, "applicationTheme", winrt::Windows::UI::Xaml::ElementTheme::Default) \
X(bool, UseMica, "useMica", false)

#define MTSM_THEME_TABROW_SETTINGS(X) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr)
#define MTSM_THEME_TABROW_SETTINGS(X) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, UnfocusedBackground, "unfocusedBackground", nullptr)

#define MTSM_THEME_TAB_SETTINGS(X) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr)
4 changes: 4 additions & 0 deletions src/cascadia/TerminalSettingsModel/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,10 @@ winrt::WUX::Media::Brush ThemeColor::Evaluate(const winrt::WUX::ResourceDictiona
{
case ThemeColorType::Accent:
{
// NOTE: There is no canonical way to get the unfocused ACCENT titlebar
// color in Windows. Edge uses it's own heuristic, and in Windows 11,
// much of this logic is rapidly changing. We're not gonna mess with
// that, since it seems there's no good way to reverse engineer that.
til::color accentColor = forTitlebar ?
_getAccentColorForTitlebar() :
til::color{ winrt::unbox_value<winrt::Windows::UI::Color>(res.Lookup(accentColorKey)) };
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/Theme.idl
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ namespace Microsoft.Terminal.Settings.Model

runtimeclass TabRowTheme {
ThemeColor Background { get; };
ThemeColor UnfocusedBackground { get; };
}

runtimeclass TabTheme {
Expand Down

0 comments on commit 024b9fc

Please sign in to comment.