Add titlebar acrylic (#10864)
Add support for acrylic in the titlebar ## PR Checklist * [x] CLA signed ## Detailed Description of the Pull Request / Additional comments This seems to be a highly requested feature and seeing as #5772 was closed I thought it made sense to make a PR for this. ![image](https://user-images.githubusercontent.com/40522069/128095309-f9073a9d-274c-44a1-be5b-34ea58d5a5a9.png) ## Validation Steps Performed Checked that acrylic works in both dark and light modes and switching between them still works. Also checked that acrylic in the tab row still works when tabs in titlebar is disabled.
This commit is contained in:
parent
0c901edd81
commit
ed7c716978
|
@ -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>
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -142,6 +142,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<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);
|
||||
|
|
|
@ -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}" />
|
||||
|
|
File diff suppressed because it is too large
Load diff
|
@ -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" };
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
if (!_backgroundBrush || backgroundColor != _backgroundBrushColor)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue