Repository: microsoft/terminal
File: src/cascadia/TerminalApp/TerminalPage.cpp (C++)

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

            TitlebarBrush(acrylicBrush);
            bgColor = backgroundColor;

            setBG = true;
        }
        else if (theme.TabRow())
        {
            if (const auto tabRowBg{ _activated ? theme.TabRow().Background() :
                                                  theme.TabRow().UnfocusedBackground() })
            {
                const auto terminalBrush = [this]() -> Media::Brush {
                    if (const auto& control{ _GetActiveControl() })
                    {
                        return control.BackgroundBrush();
                    }
                    else if (auto settingsTab = _GetFocusedTab().try_as<TerminalApp::SettingsTab>())
                    {
                        return settingsTab.Content().try_as<Controls::Page>().Background();
                    }
                    return nullptr;
                }();

                const auto themeBrush{ tabRowBg.Evaluate(res, terminalBrush, true) };
                bgColor = ThemeColor::ColorFromBrush(themeBrush);
                TitlebarBrush(themeBrush);

                setBG = true;
            }
        }

        if (!setBG)
        {
            // Nothing was set in the theme - fall back to our original `TabViewBackground` color.
            TitlebarBrush(backgroundSolidBrush);
        }

        if (!_settings.GlobalSettings().ShowTabsInTitlebar())
        {
            _tabRow.Background(TitlebarBrush());
        }

        // Update the new tab button to have better contrast with the new color.
        // In theory, it would be convenient to also change these for the
        // inactive tabs as well, but we're leaving that as a follow up.
        _SetNewTabButtonColor(bgColor, bgColor);

Review comment (bug):
Why not write this?
```cpp
Media::Brush terminalBrush{ nullptr };
if (...)
{
    terminalBrush = ...;
}
else if (...)
{
    terminalBrush = ...;
}
```

That's the way we've written these things in a lot of other places.

Code after:

            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<winrt::hstring>(dictionaryKey) !=
                        winrt::unbox_value<winrt::hstring>(requestedThemeKey))
                    {
                        // No? skip it.
                        continue;
                    }
                    // Look for the requested resource in this dict.
                    const auto themeDictionary = dict.as<winrt::Windows::UI::Xaml::ResourceDictionary>();
                    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 = lookup(res, requestedTheme, tabViewBackgroundKey).as<Media::SolidColorBrush>();

        til::color bgColor = backgroundSolidBrush.Color();

        if (_settings.GlobalSettings().UseAcrylicInTabRow())
        {
            const til::color backgroundColor = backgroundSolidBrush.Color();
            const auto acrylicBrush = Media::AcrylicBrush();
            acrylicBrush.BackgroundSource(Media::AcrylicBackgroundSource::HostBackdrop);
            acrylicBrush.FallbackColor(bgColor);
            acrylicBrush.TintColor(bgColor);
            acrylicBrush.TintOpacity(0.5);

            TitlebarBrush(acrylicBrush);