diff --git a/src/cascadia/TerminalApp/SettingsTab.cpp b/src/cascadia/TerminalApp/SettingsTab.cpp index c56464a341..33050a4eac 100644 --- a/src/cascadia/TerminalApp/SettingsTab.cpp +++ b/src/cascadia/TerminalApp/SettingsTab.cpp @@ -37,6 +37,8 @@ namespace winrt::TerminalApp::implementation auto settingsUI{ Content().as() }; settingsUI.UpdateSettings(settings); + // Stash away the current requested theme of the app. We'll need that in + // _BackgroundBrush() to do a theme-aware resource lookup _requestedTheme = settings.GlobalSettings().CurrentTheme().RequestedTheme(); } @@ -110,12 +112,13 @@ namespace winrt::TerminalApp::implementation winrt::Windows::UI::Xaml::Media::Brush SettingsTab::_BackgroundBrush() { - // // TODO! convert to a resource lookup - // static Media::SolidColorBrush campbellBg{ winrt::Windows::UI::Color{ 0xff, 0x0c, 0x0c, 0x0c } }; - // return campbellBg; - + // Look up the color we should use for the settings tab item from our + // resources. This should only be used for when "terminalBackground" is + // requested. static const auto key = winrt::box_value(L"SettingsUiTabBrush"); - // return Application::Current().Resources().TryLookup(key).try_as(); + // You can't just do a Application::Current().Resources().TryLookup + // lookup, cause the app theme never changes! Do the hacky version + // instead. return ThemeLookup(Application::Current().Resources(), _requestedTheme, key).try_as(); } } diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp index f167cbc40e..0e34dd75b3 100644 --- a/src/cascadia/TerminalApp/TerminalPage.cpp +++ b/src/cascadia/TerminalApp/TerminalPage.cpp @@ -4105,62 +4105,6 @@ namespace winrt::TerminalApp::implementation const auto res = Application::Current().Resources(); - // XAML Hacks: - // - // the App is always in the OS theme, so the - // App::Current().Resources() lookup will always get the value for the - // OS theme, not the requested theme. - // - // This helper allows us to instead lookup the value of a resource - // specified by `key` for the given `requestedTheme`, from the - // dictionaries in App.xaml. Make sure the value is actually there! - // Otherwise this'll throw like any other Lookup for a resource that - // isn't there. - // static const auto lookup = [](auto& res, auto& requestedTheme, auto& key) { - // // You want the Default version of the resource? Great, the App is - // // always in the OS theme. Just look it up and be done. - // if (requestedTheme == ElementTheme::Default) - // { - // return res.Lookup(key); - // } - // static const auto lightKey = winrt::box_value(L"Light"); - // static const auto darkKey = winrt::box_value(L"Dark"); - // // There isn't an ElementTheme::HighContrast. - - // auto requestedThemeKey = requestedTheme == ElementTheme::Dark ? darkKey : lightKey; - // for (const auto& dictionary : res.MergedDictionaries()) - // { - // // Don't look in the MUX resources. They come first. A person - // // with more patience than me may find a way to look through our - // // dictionaries first, then the MUX ones, but that's not needed - // // currently - // if (dictionary.Source()) - // { - // continue; - // } - // // Look through the theme dictionaries we defined: - // for (const auto& [dictionaryKey, dict] : dictionary.ThemeDictionaries()) - // { - // // Does the key for this dict match the theme we're looking for? - // if (winrt::unbox_value(dictionaryKey) != - // winrt::unbox_value(requestedThemeKey)) - // { - // // No? skip it. - // continue; - // } - // // Look for the requested resource in this dict. - // const auto themeDictionary = dict.as(); - // if (themeDictionary.HasKey(key)) - // { - // return themeDictionary.Lookup(key); - // } - // } - // } - - // // We didn't find it in the requested dict, fall back to the default dictionary. - // return res.Lookup(key); - // }; - // Use our helper to lookup the theme-aware version of the resource. const auto tabViewBackgroundKey = winrt::box_value(L"TabViewBackground"); const auto backgroundSolidBrush = ThemeLookup(res, requestedTheme, tabViewBackgroundKey).as(); @@ -4210,7 +4154,10 @@ namespace winrt::TerminalApp::implementation _tabRow.Background(TitlebarBrush()); } - // Second: Update the colors of our individual TabViewItems. This applies tab.background to the tabs via TerminalTab::ThemeColor + // Second: Update the colors of our individual TabViewItems. This + // applies tab.background to the tabs via TerminalTab::ThemeColor. + // + // Do this second, so that we already know the bgColor of the titlebar. { auto tabBackground = theme.Tab() ? theme.Tab().Background() : nullptr; auto tabUnfocusedBackground = theme.Tab() ? theme.Tab().UnfocusedBackground() : nullptr; @@ -4218,10 +4165,7 @@ namespace winrt::TerminalApp::implementation { winrt::com_ptr tabImpl; tabImpl.copy_from(winrt::get_self(tab)); - // if (const auto& terminalTabImpl{ _GetTerminalTabImpl(tab) }) - // { tabImpl->ThemeColor(tabBackground, tabUnfocusedBackground, bgColor); - // } } } diff --git a/src/cascadia/WinRTUtils/inc/Utils.h b/src/cascadia/WinRTUtils/inc/Utils.h index 79070c2d58..c686428020 100644 --- a/src/cascadia/WinRTUtils/inc/Utils.h +++ b/src/cascadia/WinRTUtils/inc/Utils.h @@ -55,7 +55,19 @@ winrt::Windows::Foundation::IAsyncOperation SaveFilePicker(HWND winrt::Windows::Foundation::IAsyncOperation OpenImagePicker(HWND parentHwnd); #ifdef WINRT_Windows_UI_Xaml_H - +// Only compile me if Windows.UI.Xaml is already included. +// +// XAML Hacks: +// +// the App is always in the OS theme, so the +// App::Current().Resources() lookup will always get the value for the +// OS theme, not the requested theme. +// +// This helper allows us to instead lookup the value of a resource +// specified by `key` for the given `requestedTheme`, from the +// dictionaries in App.xaml. Make sure the value is actually there! +// Otherwise this'll throw like any other Lookup for a resource that +// isn't there. winrt::Windows::Foundation::IInspectable ThemeLookup(const auto& res, const winrt::Windows::UI::Xaml::ElementTheme& requestedTheme, const winrt::Windows::Foundation::IInspectable& key)