Repository: microsoft/terminal (language: cpp)

Issue:
[1.17] Setting the $theme.tabRow.background to `#00000000` results in double titlebar
<img width="104" alt="MicrosoftTeams-image (4)" src="https://user-images.githubusercontent.com/11050425/207742017-9d3412af-d59b-43ff-8f0e-43b8b2e984da.png">



Discussion / hints:
GAH GOD I thought I fixed that. Regressed probably in the last few commits of #13935 
Uh shoot I'm not seeing this

![image](https://user-images.githubusercontent.com/18356694/210573934-65dac8f2-0cfc-463f-8c91-0fed9a64dadc.png)

That's on `1.17.3481.0`. 

Maybe I need a different set of settings? 

So, I've noticed that I only see this after a settings reload... or sometimes when locking/unlocking my workstation. There's some interplay between the different window styles we go through on the way to "no titlebar."
what settings tho
This is all I've got in the themes department:

```json
    "theme": "Cool Things",
    "themes": 
    [
        {
            "name": "Cool Things",
            "tab": 
            {
                "background": "terminalBackground",
                "showCloseButton": "always",
                "unfocusedBackground": null
            },
            "tabRow": 
            {
                "background": "#00000000",
                "unfocusedBackground": null
            }
        }
    ],
    "alwaysShowTabs": true,
    "showTabsInTitlebar": true,
```
FUDGE okay, that does repro for me, with 
![image](https://user-images.githubusercontent.com/18356694/213565417-44e8121d-01b2-477a-8a8a-18978b5e641c.png)

I'll figure that out. I bet there's a weird interaction between the `#00000000` and the `null`


Yep, that's what does it. 

If the window is inactive when the settings are changed, the NCIW will use the _current_ `TitlebarBrush` to determine if we need to totally obscure the titlebar or not. For this theme, the ThemeColor is null, so the NCIW evaluates that as opaque, so it decides it's fine to have a titlebar.

Easiest way to do this is probably expose another property out of applogic to make this easy. 

Fix patch:
diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp
index 803aa9c561e..9b20e3c7aa2 100644
--- a/src/cascadia/WindowsTerminal/AppHost.cpp
+++ b/src/cascadia/WindowsTerminal/AppHost.cpp
@@ -1344,7 +1344,20 @@ winrt::fire_and_forget AppHost::_RenameWindowRequested(const winrt::Windows::Fou
     }
 }
 
-bool _isActuallyDarkTheme(const auto requestedTheme)
+static double _opacityFromBrush(const winrt::Windows::UI::Xaml::Media::Brush& brush)
+{
+    if (auto acrylic = brush.try_as<winrt::Windows::UI::Xaml::Media::AcrylicBrush>())
+    {
+        return acrylic.TintOpacity();
+    }
+    else if (auto solidColor = brush.try_as<winrt::Windows::UI::Xaml::Media::SolidColorBrush>())
+    {
+        return solidColor.Opacity();
+    }
+    return 1.0;
+}
+
+static bool _isActuallyDarkTheme(const auto requestedTheme)
 {
     switch (requestedTheme)
     {
@@ -1365,7 +1378,10 @@ void AppHost::_updateTheme()
     _window->OnApplicationThemeChanged(theme.RequestedTheme());
 
     const auto b = _logic.TitlebarBrush();
-    const auto opacity = b ? ThemeColor::ColorFromBrush(b).A / 255.0 : 0.0;
+    const auto color = ThemeColor::ColorFromBrush(b);
+    const auto colorOpacity = b ? color.A / 255.0 : 0.0;
+    const auto brushOpacity = _opacityFromBrush(b);
+    const auto opacity = std::min(colorOpacity, brushOpacity);
     _window->UseMica(theme.Window() ? theme.Window().UseMica() : false, opacity);
 
     // This is a hack to make the window borders dark instead of light.
@@ -1639,6 +1655,7 @@ void AppHost::_PropertyChangedHandler(const winrt::Windows::Foundation::IInspect
         {
             auto nonClientWindow{ static_cast<NonClientIslandWindow*>(_window.get()) };
             nonClientWindow->SetTitlebarBackground(_logic.TitlebarBrush());
+            _updateTheme();
         }
     }
 }


Test patch: