From 7f09333a547115277e17fc3ff7dae7b7088d57f7 Mon Sep 17 00:00:00 2001 From: Matthew <40522069+matthew4850@users.noreply.github.com> Date: Tue, 3 Aug 2021 23:36:07 +0100 Subject: [PATCH 1/2] Add titlebar acrylic. --- src/cascadia/TerminalApp/App.xaml | 6 +++ src/cascadia/TerminalApp/Pane.cpp | 6 +-- src/cascadia/TerminalApp/TerminalPage.cpp | 38 +++++++++++++++++++ .../GlobalAppearance.xaml | 5 +++ .../Resources/en-US/Resources.resw | 10 ++++- .../GlobalAppSettings.cpp | 5 +++ .../TerminalSettingsModel/GlobalAppSettings.h | 1 + .../GlobalAppSettings.idl | 1 + .../WindowsTerminal/NonClientIslandWindow.cpp | 16 +++++++- 9 files changed, 82 insertions(+), 6 deletions(-) diff --git a/src/cascadia/TerminalApp/App.xaml b/src/cascadia/TerminalApp/App.xaml index a0678e05ecd..7bb8fe9ce95 100644 --- a/src/cascadia/TerminalApp/App.xaml +++ b/src/cascadia/TerminalApp/App.xaml @@ -55,12 +55,18 @@ + + + + diff --git a/src/cascadia/TerminalApp/Pane.cpp b/src/cascadia/TerminalApp/Pane.cpp index 59dacf6b904..984b6590ad9 100644 --- a/src/cascadia/TerminalApp/Pane.cpp +++ b/src/cascadia/TerminalApp/Pane.cpp @@ -2456,10 +2456,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(); } else diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 28118992033..13340f6a7f9 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -140,6 +140,44 @@ namespace winrt::TerminalApp::implementation } CATCH_LOG(); + if (_settings.GlobalSettings().UseAcrylicInTabRow()) + { + 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(); + + if (themeDictionary.HasKey(tabViewBackgroundKey)) + { + const auto backgroundSolidBrush = themeDictionary.Lookup(tabViewBackgroundKey).as(); + + 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); diff --git a/src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml b/src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml index c4f4bf2b4bb..3799a833fdd 100644 --- a/src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml +++ b/src/cascadia/TerminalSettingsEditor/GlobalAppearance.xaml @@ -57,6 +57,11 @@ + + + + + diff --git a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw index 2dec26d0e2c..36358f79b64 100644 --- a/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw +++ b/src/cascadia/TerminalSettingsEditor/Resources/en-US/Resources.resw @@ -343,6 +343,14 @@ When unchecked, the title bar will appear above the tabs. A description for what the "show titlebar" setting does. Presented near "Globals_ShowTitlebar.Header". + + Show acrylic in tab row (requires relaunch) + Header for a control to toggle whether acrylic shows in the tab row. Changing this setting requires the user to relaunch the app. + + + When checked, the tab row will have the acrylic material. + A description for what the "use acrylic in tab row" setting does. Presented near "Globals_AcrylicTabRow.Header". + Use active terminal title as application title Header for a control to toggle whether the terminal's title is shown as the application title, or not. @@ -1186,4 +1194,4 @@ Shortcut The label for a "key chord listener" control that sets the keys a key binding is bound to. - \ No newline at end of file + diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp index 466031b051b..9f3c700af44 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp @@ -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" }; @@ -105,6 +106,7 @@ winrt::com_ptr GlobalAppSettings::Copy() const globals->_Language = _Language; globals->_Theme = _Theme; globals->_TabWidthMode = _TabWidthMode; + globals->_UseAcrylicInTabRow = _UseAcrylicInTabRow; globals->_ShowTabsInTitlebar = _ShowTabsInTitlebar; globals->_WordDelimiters = _WordDelimiters; globals->_InputServiceWarning = _InputServiceWarning; @@ -287,6 +289,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 @@ -400,6 +404,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); diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h index 7fa8c78784d..d3e1e41423f 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.h @@ -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); diff --git a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl index 1fac7f66b1e..1e56e95ac55 100644 --- a/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl +++ b/src/cascadia/TerminalSettingsModel/GlobalAppSettings.idl @@ -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); diff --git a/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp b/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp index a1f5e68017f..85d4a1b145f 100644 --- a/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp @@ -782,8 +782,20 @@ void NonClientIslandWindow::_UpdateFrameMargins() const noexcept rcRest.top = topBorderHeight; const auto backgroundBrush = _titlebar.Background(); - const auto backgroundSolidBrush = backgroundBrush.as(); - const til::color backgroundColor = backgroundSolidBrush.Color(); + const auto backgroundSolidBrush = backgroundBrush.try_as(); + const auto backgroundAcrylicBrush = backgroundBrush.try_as(); + + til::color backgroundColor = Colors::Black(); + + if (backgroundSolidBrush) + { + backgroundColor = backgroundSolidBrush.Color(); + } + else if (backgroundAcrylicBrush) + { + backgroundColor = backgroundAcrylicBrush.FallbackColor(); + } + if (!_backgroundBrush || backgroundColor != _backgroundBrushColor) { From 91389797e2a73ee4880ab0866189f33bc3bb8eb1 Mon Sep 17 00:00:00 2001 From: Matthew <40522069+matthew4850@users.noreply.github.com> Date: Wed, 4 Aug 2021 10:47:08 +0100 Subject: [PATCH 2/2] Fix formatting --- src/cascadia/TerminalApp/App.xaml | 4 ++-- src/cascadia/TerminalApp/TerminalPage.cpp | 2 +- src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp | 2 -- 3 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/cascadia/TerminalApp/App.xaml b/src/cascadia/TerminalApp/App.xaml index 7bb8fe9ce95..46ee22eba0d 100644 --- a/src/cascadia/TerminalApp/App.xaml +++ b/src/cascadia/TerminalApp/App.xaml @@ -55,7 +55,7 @@ - + @@ -64,7 +64,7 @@ - + diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index 13340f6a7f9..2e2eab544f5 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -174,7 +174,7 @@ namespace winrt::TerminalApp::implementation themeDictionary.Insert(tabViewBackgroundKey, acrylicBrush); } - } + } } } diff --git a/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp b/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp index 85d4a1b145f..b480a7efcd3 100644 --- a/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/NonClientIslandWindow.cpp @@ -786,7 +786,6 @@ void NonClientIslandWindow::_UpdateFrameMargins() const noexcept const auto backgroundAcrylicBrush = backgroundBrush.try_as(); til::color backgroundColor = Colors::Black(); - if (backgroundSolidBrush) { backgroundColor = backgroundSolidBrush.Color(); @@ -796,7 +795,6 @@ void NonClientIslandWindow::_UpdateFrameMargins() const noexcept backgroundColor = backgroundAcrylicBrush.FallbackColor(); } - if (!_backgroundBrush || backgroundColor != _backgroundBrushColor) { // Create brush for titlebar color.