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 titlebar acrylic #10864

Merged
3 commits merged into from
Aug 23, 2021
Merged
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
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,18 @@
<!-- Define resources for Dark mode here -->
<SolidColorBrush x:Key="TabViewBackground"
Color="#FF333333" />

<SolidColorBrush x:Key="UnfocusedBorderBrush"
Color="#FF333333" />
</ResourceDictionary>

<ResourceDictionary x:Key="Light">
<!-- Define resources for Light mode here -->
<SolidColorBrush x:Key="TabViewBackground"
Color="#FFCCCCCC" />

<SolidColorBrush x:Key="UnfocusedBorderBrush"
Color="#FFCCCCCC" />
</ResourceDictionary>

</ResourceDictionary.ThemeDictionaries>
Expand Down
6 changes: 3 additions & 3 deletions src/cascadia/TerminalApp/Pane.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2628,10 +2628,10 @@ void Pane::_SetupResources()
s_focusedBorderBrush = SolidColorBrush{ Colors::Black() };
}

const auto tabViewBackgroundKey = winrt::box_value(L"TabViewBackground");
if (res.HasKey(tabViewBackgroundKey))
const auto unfocusedBorderBrushKey = winrt::box_value(L"UnfocusedBorderBrush");
if (res.HasKey(unfocusedBorderBrushKey))
{
winrt::Windows::Foundation::IInspectable obj = res.Lookup(tabViewBackgroundKey);
winrt::Windows::Foundation::IInspectable obj = res.Lookup(unfocusedBorderBrushKey);
s_unfocusedBorderBrush = obj.try_as<winrt::Windows::UI::Xaml::Media::SolidColorBrush>();
}
else
Expand Down
38 changes: 38 additions & 0 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,44 @@ namespace winrt::TerminalApp::implementation
}
CATCH_LOG();

if (_settings.GlobalSettings().UseAcrylicInTabRow())
matthew4850 marked this conversation as resolved.
Show resolved Hide resolved
{
const auto res = Application::Current().Resources();

const auto lightKey = winrt::box_value(L"Light");
const auto darkKey = winrt::box_value(L"Dark");
const auto tabViewBackgroundKey = winrt::box_value(L"TabViewBackground");

for (auto const& dictionary : res.MergedDictionaries())
{
// Don't change MUX resources
if (dictionary.Source())
{
continue;
}

for (auto const& kvPair : dictionary.ThemeDictionaries())
{
const auto themeDictionary = kvPair.Value().as<winrt::Windows::UI::Xaml::ResourceDictionary>();

if (themeDictionary.HasKey(tabViewBackgroundKey))
{
const auto backgroundSolidBrush = themeDictionary.Lookup(tabViewBackgroundKey).as<Media::SolidColorBrush>();

const til::color backgroundColor = backgroundSolidBrush.Color();

const auto acrylicBrush = Media::AcrylicBrush();
acrylicBrush.BackgroundSource(Media::AcrylicBackgroundSource::HostBackdrop);
acrylicBrush.FallbackColor(backgroundColor);
acrylicBrush.TintColor(backgroundColor);
acrylicBrush.TintOpacity(0.5);

themeDictionary.Insert(tabViewBackgroundKey, acrylicBrush);
}
}
}
}

_tabRow.PointerMoved({ get_weak(), &TerminalPage::_RestorePointerCursorHandler });
_tabView.CanReorderTabs(!isElevated);
_tabView.CanDragTabs(!isElevated);
Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,11 @@
<ToggleSwitch IsOn="{x:Bind State.Globals.ShowTabsInTitlebar, Mode=TwoWay}" />
</local:SettingContainer>

<!-- Show Acrylic in Tab Row -->
<local:SettingContainer x:Uid="Globals_AcrylicTabRow">
<ToggleSwitch IsOn="{x:Bind State.Globals.UseAcrylicInTabRow, Mode=TwoWay}" />
</local:SettingContainer>

<!-- Show Title in Titlebar -->
<local:SettingContainer x:Uid="Globals_ShowTitleInTitlebar">
<ToggleSwitch IsOn="{x:Bind State.Globals.ShowTitleInTitlebar, Mode=TwoWay}" />
Expand Down
2,434 changes: 1,221 additions & 1,213 deletions src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ static constexpr std::string_view ShowTitleInTitlebarKey{ "showTerminalTitleInTi
static constexpr std::string_view LanguageKey{ "language" };
static constexpr std::string_view ThemeKey{ "theme" };
static constexpr std::string_view TabWidthModeKey{ "tabWidthMode" };
static constexpr std::string_view UseAcrylicInTabRowKey{ "useAcrylicInTabRow" };
static constexpr std::string_view ShowTabsInTitlebarKey{ "showTabsInTitlebar" };
static constexpr std::string_view WordDelimitersKey{ "wordDelimiters" };
static constexpr std::string_view InputServiceWarningKey{ "inputServiceWarning" };
Expand Down Expand Up @@ -107,6 +108,7 @@ winrt::com_ptr<GlobalAppSettings> GlobalAppSettings::Copy() const
globals->_Language = _Language;
globals->_Theme = _Theme;
globals->_TabWidthMode = _TabWidthMode;
globals->_UseAcrylicInTabRow = _UseAcrylicInTabRow;
globals->_ShowTabsInTitlebar = _ShowTabsInTitlebar;
globals->_WordDelimiters = _WordDelimiters;
globals->_InputServiceWarning = _InputServiceWarning;
Expand Down Expand Up @@ -291,6 +293,8 @@ void GlobalAppSettings::LayerJson(const Json::Value& json)

JsonUtils::GetValueForKey(json, TabWidthModeKey, _TabWidthMode);

JsonUtils::GetValueForKey(json, UseAcrylicInTabRowKey, _UseAcrylicInTabRow);

JsonUtils::GetValueForKey(json, SnapToGridOnResizeKey, _SnapToGridOnResize);

// GetValueForKey will only override the current value if the key exists
Expand Down Expand Up @@ -408,6 +412,7 @@ Json::Value GlobalAppSettings::ToJson() const
JsonUtils::SetValueForKey(json, LanguageKey, _Language);
JsonUtils::SetValueForKey(json, ThemeKey, _Theme);
JsonUtils::SetValueForKey(json, TabWidthModeKey, _TabWidthMode);
JsonUtils::SetValueForKey(json, UseAcrylicInTabRowKey, _UseAcrylicInTabRow);
JsonUtils::SetValueForKey(json, SnapToGridOnResizeKey, _SnapToGridOnResize);
JsonUtils::SetValueForKey(json, DebugFeaturesKey, _DebugFeaturesEnabled);
JsonUtils::SetValueForKey(json, ForceFullRepaintRenderingKey, _ForceFullRepaintRendering);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
INHERITABLE_SETTING(Model::GlobalAppSettings, hstring, Language);
INHERITABLE_SETTING(Model::GlobalAppSettings, winrt::Windows::UI::Xaml::ElementTheme, Theme, winrt::Windows::UI::Xaml::ElementTheme::Default);
INHERITABLE_SETTING(Model::GlobalAppSettings, winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode, TabWidthMode, winrt::Microsoft::UI::Xaml::Controls::TabViewWidthMode::Equal);
INHERITABLE_SETTING(Model::GlobalAppSettings, bool, UseAcrylicInTabRow, false);
INHERITABLE_SETTING(Model::GlobalAppSettings, bool, ShowTabsInTitlebar, true);
INHERITABLE_SETTING(Model::GlobalAppSettings, hstring, WordDelimiters, DEFAULT_WORD_DELIMITERS);
INHERITABLE_SETTING(Model::GlobalAppSettings, bool, CopyOnSelect, false);
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace Microsoft.Terminal.Settings.Model
INHERITABLE_SETTING(String, Language);
INHERITABLE_SETTING(Windows.UI.Xaml.ElementTheme, Theme);
INHERITABLE_SETTING(Microsoft.UI.Xaml.Controls.TabViewWidthMode, TabWidthMode);
INHERITABLE_SETTING(Boolean, UseAcrylicInTabRow);
INHERITABLE_SETTING(Boolean, ShowTabsInTitlebar);
INHERITABLE_SETTING(String, WordDelimiters);
INHERITABLE_SETTING(Boolean, CopyOnSelect);
Expand Down
14 changes: 12 additions & 2 deletions src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -801,8 +801,18 @@ void NonClientIslandWindow::_UpdateFrameMargins() const noexcept
rcRest.top = topBorderHeight;

const auto backgroundBrush = _titlebar.Background();
const auto backgroundSolidBrush = backgroundBrush.as<Media::SolidColorBrush>();
const til::color backgroundColor = backgroundSolidBrush.Color();
const auto backgroundSolidBrush = backgroundBrush.try_as<Media::SolidColorBrush>();
const auto backgroundAcrylicBrush = backgroundBrush.try_as<Media::AcrylicBrush>();

til::color backgroundColor = Colors::Black();
if (backgroundSolidBrush)
{
backgroundColor = backgroundSolidBrush.Color();
}
else if (backgroundAcrylicBrush)
{
backgroundColor = backgroundAcrylicBrush.FallbackColor();
}
Comment on lines +804 to +815
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const auto backgroundSolidBrush = backgroundBrush.try_as<Media::SolidColorBrush>();
const auto backgroundAcrylicBrush = backgroundBrush.try_as<Media::AcrylicBrush>();
til::color backgroundColor = Colors::Black();
if (backgroundSolidBrush)
{
backgroundColor = backgroundSolidBrush.Color();
}
else if (backgroundAcrylicBrush)
{
backgroundColor = backgroundAcrylicBrush.FallbackColor();
}
til::color backgroundColor = Colors::Black();
if (const auto backgroundSolidBrush = backgroundBrush.try_as<Media::SolidColorBrush>())
{
backgroundColor = backgroundSolidBrush.Color();
}
else if (const auto backgroundAcrylicBrush = backgroundBrush.try_as<Media::AcrylicBrush>())
{
backgroundColor = backgroundAcrylicBrush.FallbackColor();
}

Totally optional. This'll make it so that the brushes are available in a smaller scope.


if (!_backgroundBrush || backgroundColor != _backgroundBrushColor)
{
Expand Down