Skip to content
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

Add support for tab.background to themes #13178

Merged
merged 79 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
15e4fd9
Settings project builds at least
zadjii-msft Mar 24, 2022
7e0ae35
this fixes the App bits as well
zadjii-msft Mar 24, 2022
00c135b
on reload, this changes the BG of the titlebar, but not the tab view
zadjii-msft Mar 24, 2022
b4cd7b3
this is better. Apphost is gonna need to be involved anyways so fuck it
zadjii-msft Mar 24, 2022
9627483
okay so i bet that resource changed. Whatever, we'll work with it.
zadjii-msft Mar 24, 2022
84805f5
dumbly accept alpha channel in colors
zadjii-msft Mar 24, 2022
9670d13
mica works, but the titlebar looks DUMB
zadjii-msft Mar 24, 2022
c555e6e
this did seem to work, but will it work for acrylic?
zadjii-msft Mar 25, 2022
01f07be
okay so you can't change a solid brush to an acylic one at runtime
zadjii-msft Mar 25, 2022
ee9333a
A pile of dead ends.
zadjii-msft Mar 25, 2022
9eff0a2
i feel like I'm getting closer
zadjii-msft Mar 25, 2022
44112fc
really, no good progress here. It's rough
zadjii-msft Mar 28, 2022
f92724d
We can't be clever here. Just make an observable property and slam th…
zadjii-msft Apr 25, 2022
cd0012a
guess what, it works
zadjii-msft Apr 25, 2022
ac49459
change color based on if the window is activated or now
zadjii-msft Apr 26, 2022
03211c8
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft Apr 26, 2022
1d0a5d7
Merge remote-tracking branch 'origin/dev/migrie/titebar-colors' into …
zadjii-msft Apr 26, 2022
e22046f
accept accent color as a ThemeColor
zadjii-msft Apr 26, 2022
99dc75d
this actually works now. Remember kids, break statements in switch/ca…
zadjii-msft Apr 26, 2022
a7ce860
cleanup, works on start and when unset
zadjii-msft Apr 26, 2022
4f42661
Lookup themes from a list of themes, use that one to style the window
zadjii-msft Apr 26, 2022
5081118
This is horrifying and yet I'm totally shipping it. Move the objects …
zadjii-msft Apr 26, 2022
fe26114
better, better,
zadjii-msft Apr 26, 2022
7fcfda3
wow
zadjii-msft Apr 26, 2022
df0efff
stragglers
zadjii-msft Apr 26, 2022
7243603
hey this is easier
zadjii-msft Apr 26, 2022
606db76
this is like 99% of the work here
zadjii-msft Apr 26, 2022
de22df0
switches when a tab does, not the pane
zadjii-msft Apr 26, 2022
01d6907
I think that's everything
zadjii-msft Apr 26, 2022
39b6fdd
Some minor todos
zadjii-msft Apr 26, 2022
9bebb74
Some settings saving roundtripping bugs
zadjii-msft Apr 27, 2022
cfb99d9
Change theme with the SUI and actually have it persist
zadjii-msft Apr 27, 2022
a57187b
include the themes
zadjii-msft Apr 27, 2022
b6b9aea
Use better display names
zadjii-msft Apr 27, 2022
e2318b4
This is horrifying
zadjii-msft Apr 27, 2022
bc8bb8e
more comments
zadjii-msft Apr 27, 2022
446e17b
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft Apr 27, 2022
fd2dd3a
cleanup for the review
zadjii-msft Apr 27, 2022
a1ea0fd
forgot you
zadjii-msft Apr 28, 2022
9b9a644
spell
zadjii-msft Apr 28, 2022
03da3b7
runformat
zadjii-msft Apr 28, 2022
24f945a
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft Apr 29, 2022
49c580c
well, this is like all of it
zadjii-msft Apr 29, 2022
3281a3a
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft May 3, 2022
476c5bb
Merge branch 'dev/migrie/fhl/theming-2022-prototype' into dev/migrie/…
zadjii-msft May 3, 2022
68d70a0
this is REALLY janky but seems to work
zadjii-msft May 3, 2022
99bc963
this is simpler
zadjii-msft May 3, 2022
6c28ba6
make the code a lot cleaner
zadjii-msft May 3, 2022
342eb2b
Removes the ability to add Mica in the titlebar, but good enough for v0
zadjii-msft May 4, 2022
cd2fd43
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft May 5, 2022
44319a1
Fixes the Settings UI terminalBackground settings
zadjii-msft May 5, 2022
d73e450
this fixes the terminalBG + runtime change
zadjii-msft May 5, 2022
e52b7a9
well, this was part of it...
zadjii-msft May 5, 2022
3af471a
derp
zadjii-msft May 5, 2022
b2abca6
Add comments
zadjii-msft May 6, 2022
cae5218
Start by just adding a test file
zadjii-msft May 6, 2022
45fb4b1
Fill in more tests
zadjii-msft May 6, 2022
28119c7
This is what I was looking for
zadjii-msft May 6, 2022
2712e46
Fix having a null window, cause that was actually very possible
zadjii-msft May 6, 2022
331b98f
sensible defaults
zadjii-msft May 6, 2022
f38dc5c
typos
zadjii-msft May 6, 2022
cb788b0
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft May 6, 2022
4f55646
Merge branch 'dev/migrie/fhl/theming-2022-prototype' into dev/migrie/…
zadjii-msft May 9, 2022
f5007fa
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft May 25, 2022
87a9222
Merge branch 'dev/migrie/fhl/theming-2022-prototype' into dev/migrie/…
zadjii-msft May 25, 2022
9c3b861
cleanup for review
zadjii-msft May 25, 2022
d9b383f
that's not even that bad
zadjii-msft May 25, 2022
861cd2a
the more important color thing
zadjii-msft May 26, 2022
c07b01e
more nits and such
zadjii-msft May 26, 2022
72904b9
typo
zadjii-msft May 26, 2022
c8254b2
this wouldn't happen if there was just an operator?.()
zadjii-msft May 26, 2022
8d86538
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft Jun 16, 2022
0e13b7b
Merge branch 'dev/migrie/fhl/theming-2022-prototype' into dev/migrie/…
zadjii-msft Jun 16, 2022
ee4ae62
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft Jul 6, 2022
9806d64
just disable mica for now
zadjii-msft Jul 6, 2022
4245964
This is what happens when a PR has been open for ages
zadjii-msft Jul 6, 2022
9ab99b3
nits across the board
zadjii-msft Jul 6, 2022
a80dc6a
Merge branch 'dev/migrie/fhl/theming-2022-prototype' into dev/migrie/…
zadjii-msft Jul 6, 2022
2428693
Merge remote-tracking branch 'origin/main' into dev/migrie/f/702-link…
zadjii-msft Jul 7, 2022
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
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/TabManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ namespace winrt::TerminalApp::implementation
// Possibly update the icon of the tab.
page->_UpdateTabIcon(*tab);

page->_updateTabRowColors();
page->_updateThemeColors();

// Update the taskbar progress as well. We'll raise our own
// SetTaskbarProgress event here, to get tell the hosting
Expand Down Expand Up @@ -927,7 +927,7 @@ namespace winrt::TerminalApp::implementation
_TitleChangedHandlers(*this, tab.Title());
}

_updateTabRowColors();
_updateThemeColors();

auto tab_impl = _GetTerminalTabImpl(tab);
if (tab_impl)
Expand Down
24 changes: 18 additions & 6 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ namespace winrt::TerminalApp::implementation
transparent.Color(Windows::UI::Colors::Transparent());
_tabRow.Background(transparent);
}
_updateTabRowColors();
_updateThemeColors();

// Hookup our event handlers to the ShortcutActionDispatch
_RegisterActionCallbacks();
Expand Down Expand Up @@ -1440,7 +1440,7 @@ namespace winrt::TerminalApp::implementation
{
if (e.PropertyName() == L"BackgroundBrush")
{
page->_updateTabRowColors();
page->_updateThemeColors();
}
}
});
Expand Down Expand Up @@ -2702,7 +2702,7 @@ namespace winrt::TerminalApp::implementation

////////////////////////////////////////////////////////////////////////
// Begin Theme handling
_updateTabRowColors();
_updateThemeColors();
}

// This is a helper to aid in sorting commands by their `Name`s, alphabetically.
Expand Down Expand Up @@ -4004,15 +4004,27 @@ namespace winrt::TerminalApp::implementation
applicationState.DismissedMessages(std::move(messages));
}

void TerminalPage::_updateTabRowColors()
void TerminalPage::_updateThemeColors()
{
if (_settings == nullptr)
{
return;
}

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

// First: Update the colors of our individual TabViewItems. This applies tab.background to the tabs via TerminalTab::ThemeColor
{
auto tabBackground = theme.Tab() ? theme.Tab().Background() : nullptr;
for (const auto& tab : _tabs)
{
if (const auto& terminalTabImpl{ _GetTerminalTabImpl(tab) })
{
terminalTabImpl->ThemeColor(tabBackground);
}
}
}

const auto res = Application::Current().Resources();

Expand Down Expand Up @@ -4130,6 +4142,6 @@ namespace winrt::TerminalApp::implementation
// Stash if we're activated. Use that when we reload
// the settings, change active panes, etc.
_activated = activated;
_updateTabRowColors();
_updateThemeColors();
}
}
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ namespace winrt::TerminalApp::implementation
static bool _IsMessageDismissed(const winrt::Microsoft::Terminal::Settings::Model::InfoBarMessage& message);
static void _DismissMessage(const winrt::Microsoft::Terminal::Settings::Model::InfoBarMessage& message);

void _updateTabRowColors();
void _updateThemeColors();

winrt::fire_and_forget _ShowWindowChangedHandler(const IInspectable sender, const winrt::Microsoft::Terminal::Control::ShowWindowArgs args);

Expand Down
35 changes: 33 additions & 2 deletions src/cascadia/TerminalApp/TerminalTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1343,7 +1343,7 @@ namespace winrt::TerminalApp::implementation
// -------------------- | -- | --
// Runtime Color | _optional_ | Color Picker / `setTabColor` action
// Control Tab Color | _optional_ | Profile's `tabColor`, or a color set by VT
// Theme Tab Background | _optional_ | `tab.backgroundColor` in the theme
// Theme Tab Background | _optional_ | `tab.backgroundColor` in the theme (handled in _RecalculateAndApplyTabColor)
// Tab Default Color | **default** | TabView in XAML
//
// coalesce will get us the first of these values that's
Expand All @@ -1352,7 +1352,6 @@ namespace winrt::TerminalApp::implementation

return til::coalesce(_runtimeTabColor,
controlTabColor,
_themeTabColor,
std::optional<Windows::UI::Color>(std::nullopt));
}

Expand All @@ -1370,6 +1369,12 @@ namespace winrt::TerminalApp::implementation
_RecalculateAndApplyTabColor();
}

void TerminalTab::ThemeColor(const winrt::Microsoft::Terminal::Settings::Model::ThemeColor& color)
{
_themeColor = color;
_RecalculateAndApplyTabColor();
}

// Method Description:
// - This function dispatches a function to the UI thread to recalculate
// what this tab's current background color should be. If a color is set,
Expand All @@ -1390,11 +1395,37 @@ namespace winrt::TerminalApp::implementation

auto tab{ ptrTab };

// GetTabColor will return the color set by the color picker, or the
// color specified in the profile. If neither of those were set,
// then look to _themeColor to see if there's a value there.
// Otherwise, clear our color, falling back to the TabView defaults.
auto currentColor = tab->GetTabColor();
if (currentColor.has_value())
{
tab->_ApplyTabColor(currentColor.value());
}
else if (tab->_themeColor != nullptr)
{
// One-liner to safely get the active control's brush.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"one-liner" is a stretch of the definition of both "one" and "line" here

Media::Brush terminalBrush{ nullptr };
if (const auto& c{ tab->GetActiveTerminalControl() })
{
terminalBrush = c.BackgroundBrush();
}

if (const auto themeBrush{ tab->_themeColor.Evaluate(Application::Current().Resources(), terminalBrush, false) })
{
// ThemeColor.Evaluate will get us a Brush (because the
// TermControl could have an acrylic BG, for example). Take
// that brush, and get the color out of it. We don't really
// want to have the tab items themselves be acrylic.
tab->_ApplyTabColor(til::color{ ThemeColor::ColorFromBrush(themeBrush) });
}
else
{
tab->_ClearTabBackgroundColor();
}
}
else
{
tab->_ClearTabBackgroundColor();
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/TerminalTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ namespace winrt::TerminalApp::implementation

std::optional<winrt::Windows::UI::Color> GetTabColor();

void ThemeColor(const winrt::Microsoft::Terminal::Settings::Model::ThemeColor& color);
void SetRuntimeTabColor(const winrt::Windows::UI::Color& color);
void ResetRuntimeTabColor();
void ActivateColorPicker();
Expand Down Expand Up @@ -113,10 +114,10 @@ namespace winrt::TerminalApp::implementation

winrt::hstring _lastIconPath{};
winrt::TerminalApp::ColorPickupFlyout _tabColorPickup{};
std::optional<winrt::Windows::UI::Color> _themeTabColor{};
std::optional<winrt::Windows::UI::Color> _runtimeTabColor{};
winrt::TerminalApp::TabHeaderControl _headerControl{};
winrt::TerminalApp::TerminalTabStatus _tabStatus{};
winrt::Microsoft::Terminal::Settings::Model::ThemeColor _themeColor{ nullptr };

struct ControlEventTokens
{
Expand Down
6 changes: 5 additions & 1 deletion src/cascadia/TerminalSettingsModel/MTSMSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,15 @@ Author(s):

#define MTSM_THEME_SETTINGS(X) \
X(winrt::Microsoft::Terminal::Settings::Model::WindowTheme, Window, "window", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::TabRowTheme, TabRow, "tabRow", nullptr)
X(winrt::Microsoft::Terminal::Settings::Model::TabRowTheme, TabRow, "tabRow", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::TabTheme, Tab, "tab", nullptr)

#define MTSM_THEME_WINDOW_SETTINGS(X) \
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_TAB_SETTINGS(X) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr)
6 changes: 6 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 "ThemeColor.g.cpp"
#include "WindowTheme.g.cpp"
#include "TabRowTheme.g.cpp"
#include "TabTheme.g.cpp"
#include "Theme.g.cpp"

using namespace ::Microsoft::Console;
Expand Down Expand Up @@ -211,6 +212,7 @@ winrt::WUX::Media::Brush ThemeColor::Evaluate(const winrt::WUX::ResourceDictiona

THEME_OBJECT_CONVERTER(winrt::Microsoft::Terminal::Settings::Model, WindowTheme, MTSM_THEME_WINDOW_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);

#undef THEME_SETTINGS_FROM_JSON
#undef THEME_SETTINGS_TO_JSON
Expand Down Expand Up @@ -242,6 +244,10 @@ winrt::com_ptr<Theme> Theme::Copy() const
{
theme->_TabRow = *winrt::get_self<implementation::TabRowTheme>(_TabRow)->Copy();
}
if (_Tab)
{
theme->_Tab = *winrt::get_self<implementation::TabTheme>(_Tab)->Copy();
}

return theme;
}
Expand Down
25 changes: 12 additions & 13 deletions src/cascadia/TerminalSettingsModel/Theme.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ Author(s):
#include "ThemeColor.g.h"
#include "WindowTheme.g.h"
#include "TabRowTheme.g.h"
#include "TabTheme.g.h"
#include "Theme.g.h"

namespace winrt::Microsoft::Terminal::Settings::Model::implementation
Expand Down Expand Up @@ -57,21 +58,18 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
return result; \
}

struct WindowTheme : WindowThemeT<WindowTheme>
{
MTSM_THEME_WINDOW_SETTINGS(THEME_SETTINGS_INITIALIZE);

public:
COPY_THEME_OBJECT(WindowTheme, MTSM_THEME_WINDOW_SETTINGS);
#define THEME_OBJECT(className, macro) \
struct className : className##T<className> \
{ \
macro(THEME_SETTINGS_INITIALIZE); \
\
public: \
COPY_THEME_OBJECT(className, macro); \
};

struct TabRowTheme : TabRowThemeT<TabRowTheme>
{
MTSM_THEME_TABROW_SETTINGS(THEME_SETTINGS_INITIALIZE);

public:
COPY_THEME_OBJECT(TabRowTheme, MTSM_THEME_TABROW_SETTINGS);
};
THEME_OBJECT(WindowTheme, MTSM_THEME_WINDOW_SETTINGS);
THEME_OBJECT(TabRowTheme, MTSM_THEME_TABROW_SETTINGS);
THEME_OBJECT(TabTheme, MTSM_THEME_TAB_SETTINGS);

struct Theme : ThemeT<Theme>
{
Expand All @@ -98,6 +96,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation

#undef THEME_SETTINGS_INITIALIZE
#undef THEME_SETTINGS_COPY
#undef THEME_OBJECT
}

namespace winrt::Microsoft::Terminal::Settings::Model::factory_implementation
Expand Down
7 changes: 7 additions & 0 deletions src/cascadia/TerminalSettingsModel/Theme.idl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ namespace Microsoft.Terminal.Settings.Model
ThemeColor Background { get; };
}

runtimeclass TabTheme {
ThemeColor Background { get; };
}

[default_interface] runtimeclass Theme : Windows.Foundation.IStringable {
Theme();
Theme(Windows.UI.Xaml.ElementTheme requestedTheme);
Expand All @@ -48,6 +52,9 @@ namespace Microsoft.Terminal.Settings.Model
// tabRow.* Namespace
TabRowTheme TabRow { get; };

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

// A helper for retrieving the RequestedTheme out of the window property
Windows.UI.Xaml.ElementTheme RequestedTheme { get; };

Expand Down