From 17cf44fa71defcdf8f7a03cce0a8d848c8cd8aa3 Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Mon, 3 Apr 2023 17:40:46 -0500 Subject: [PATCH] Upgrade to MUX 2.8 (#15078) Updates the Terminal to Microsoft.UI.Xaml v2.8. * MUX 2.8 adds a dependency on WebView2, so we need to include parts of it too. * See https://github.com/microsoft/microsoft-ui-xaml/pull/7574 for why we're adding the `.props` * The TabView thing: > tl;dr: In >=MUX 2.7, we were updating our tab colors by doing a "Visual State Dance", as I called it. We'd manually change the `TabViewItem`'s VisualState to one that it wasn't in, then change it back to the one it should be in. This seemingly re-applied the new values of the brushes. However in 2.8, this seemingly didn't work anymore! > > So instead, we do a "Theme Dance", like so: > ```c++ > const auto& reqTheme = TabViewItem().RequestedTheme(); > TabViewItem().RequestedTheme(ElementTheme::Light); > TabViewItem().RequestedTheme(ElementTheme::Dark); > TabViewItem().RequestedTheme(reqTheme); > ``` > This causes the `ThemeResource`s to be re-evaluated to the new values. > We never got to the root cause of why this seems different in 2.8. It literally makes no sense. Closes #13495 Co-authored-by: Dustin L. Howett --- .../Microsoft.UI.Xaml.Additional.targets | 16 +++++ dep/nuget/packages.config | 3 +- src/cascadia/TerminalApp/TabBase.cpp | 67 ++++++++++--------- src/common.nugetversions.props | 3 + src/common.nugetversions.targets | 13 +++- 5 files changed, 66 insertions(+), 36 deletions(-) create mode 100644 build/rules/Microsoft.UI.Xaml.Additional.targets diff --git a/build/rules/Microsoft.UI.Xaml.Additional.targets b/build/rules/Microsoft.UI.Xaml.Additional.targets new file mode 100644 index 0000000000..dbd6eb3f35 --- /dev/null +++ b/build/rules/Microsoft.UI.Xaml.Additional.targets @@ -0,0 +1,16 @@ + + + + + + + diff --git a/dep/nuget/packages.config b/dep/nuget/packages.config index 5015d1ee97..09a9c4935d 100644 --- a/dep/nuget/packages.config +++ b/dep/nuget/packages.config @@ -8,7 +8,8 @@ - + + diff --git a/src/cascadia/TerminalApp/TabBase.cpp b/src/cascadia/TerminalApp/TabBase.cpp index 54b25c48b0..6761ab3dac 100644 --- a/src/cascadia/TerminalApp/TabBase.cpp +++ b/src/cascadia/TerminalApp/TabBase.cpp @@ -475,33 +475,36 @@ namespace winrt::TerminalApp::implementation // In GH#11294 we thought we'd still need to set // TabViewItemHeaderBackground manually, but GH#11382 discovered that // Background() was actually okay after all. + + const auto& tabItemResources{ TabViewItem().Resources() }; + TabViewItem().Background(deselectedTabBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderBackgroundSelected"), selectedTabBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderBackgroundPointerOver"), hoverTabBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderBackgroundPressed"), selectedTabBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderBackgroundSelected"), selectedTabBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderBackgroundPointerOver"), hoverTabBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderBackgroundPressed"), selectedTabBrush); // Similarly, TabViewItem().Foreground() sets the color for the text // when the TabViewItem isn't selected, but not when it is hovered, // pressed, dragged, or selected, so we'll need to just set them all // anyways. TabViewItem().Foreground(deselectedFontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderForeground"), deselectedFontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderForegroundSelected"), fontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderForegroundPointerOver"), fontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderForegroundPressed"), fontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderForeground"), deselectedFontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderForegroundSelected"), fontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderForegroundPointerOver"), fontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderForegroundPressed"), fontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderCloseButtonForeground"), deselectedFontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderCloseButtonForegroundPressed"), secondaryFontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderCloseButtonForegroundPointerOver"), fontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderPressedCloseButtonForeground"), fontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderPointerOverCloseButtonForeground"), fontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderSelectedCloseButtonForeground"), fontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderCloseButtonBackgroundPressed"), subtleFillColorTertiaryBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewItemHeaderCloseButtonBackgroundPointerOver"), subtleFillColorSecondaryBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderCloseButtonForeground"), deselectedFontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderCloseButtonForegroundPressed"), secondaryFontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderCloseButtonForegroundPointerOver"), fontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderPressedCloseButtonForeground"), fontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderPointerOverCloseButtonForeground"), fontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderSelectedCloseButtonForeground"), fontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderCloseButtonBackgroundPressed"), subtleFillColorTertiaryBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewItemHeaderCloseButtonBackgroundPointerOver"), subtleFillColorSecondaryBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewButtonForegroundActiveTab"), fontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewButtonForegroundPressed"), fontBrush); - TabViewItem().Resources().Insert(winrt::box_value(L"TabViewButtonForegroundPointerOver"), fontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewButtonForegroundActiveTab"), fontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewButtonForegroundPressed"), fontBrush); + tabItemResources.Insert(winrt::box_value(L"TabViewButtonForegroundPointerOver"), fontBrush); _RefreshVisualState(); } @@ -537,13 +540,15 @@ namespace winrt::TerminalApp::implementation L"TabViewButtonForegroundPointerOver" }; + const auto& tabItemResources{ TabViewItem().Resources() }; + // simply clear any of the colors in the tab's dict for (const auto& keyString : keys) { auto key = winrt::box_value(keyString); - if (TabViewItem().Resources().HasKey(key)) + if (tabItemResources.HasKey(key)) { - TabViewItem().Resources().Remove(key); + tabItemResources.Remove(key); } } @@ -556,24 +561,20 @@ namespace winrt::TerminalApp::implementation } // Method Description: - // Toggles the visual state of the tab view item, - // so that changes to the tab color are reflected immediately + // BODGY + // - Toggles the requested theme of the tab view item, + // so that changes to the tab color are reflected immediately + // - Prior to MUX 2.8, we toggled the visual state here, but that seemingly + // doesn't work in 2.8. // Arguments: // - // Return Value: // - void TabBase::_RefreshVisualState() { - if (TabViewItem().IsSelected()) - { - VisualStateManager::GoToState(TabViewItem(), L"Normal", true); - VisualStateManager::GoToState(TabViewItem(), L"Selected", true); - } - else - { - VisualStateManager::GoToState(TabViewItem(), L"Selected", true); - VisualStateManager::GoToState(TabViewItem(), L"Normal", true); - } + const auto& reqTheme = TabViewItem().RequestedTheme(); + TabViewItem().RequestedTheme(ElementTheme::Light); + TabViewItem().RequestedTheme(ElementTheme::Dark); + TabViewItem().RequestedTheme(reqTheme); } - } diff --git a/src/common.nugetversions.props b/src/common.nugetversions.props index 19147f5e97..a3ac0f8ec9 100644 --- a/src/common.nugetversions.props +++ b/src/common.nugetversions.props @@ -36,4 +36,7 @@ $(MSBuildThisFileDirectory)..\packages\Selenium.Support.3.5.0 + + + diff --git a/src/common.nugetversions.targets b/src/common.nugetversions.targets index 91a26fdf59..e047b9931d 100644 --- a/src/common.nugetversions.targets +++ b/src/common.nugetversions.targets @@ -16,6 +16,8 @@ "$(SolutionDir)dep\nuget\nuget.exe" $(SolutionDir)dep\nuget\packages.config + + $(MSBuildThisFileDirectory)..\packages\Microsoft.Web.WebView2.1.0.1661.34 - + + + @@ -86,7 +94,8 @@ - + +