Repository: microsoft/terminal (language: cpp)

Issue:
Mica in the SUI BG doesn't work on Win10
This build appears to have resolved it for me in initial testing, with a completely unrelated side effect of the dark mode for settings having the light mode color background rendering it completely unreadable (but it at least appears to resolve this actual issue from what I can see so far)

![image](https://user-images.githubusercontent.com/17488780/211924397-f6dc36d0-dc26-4e83-9382-24a055efe441.png)

_Originally posted by @spootle in https://github.com/microsoft/terminal/issues/13388#issuecomment-1379527904_
      


Discussion / hints:
Pretty obviously, I set a transparent BG when we want mica, but _there is no mica_ so it's just W H I T E

Fix patch:
diff --git a/src/cascadia/TerminalSettingsEditor/MainPage.cpp b/src/cascadia/TerminalSettingsEditor/MainPage.cpp
index 9ae98822fde..7140b83c8b3 100644
--- a/src/cascadia/TerminalSettingsEditor/MainPage.cpp
+++ b/src/cascadia/TerminalSettingsEditor/MainPage.cpp
@@ -20,6 +20,7 @@
 #include <..\WinRTUtils\inc\Utils.h>
 
 #include <LibraryResources.h>
+#include <dwmapi.h>
 
 namespace winrt
 {
@@ -216,6 +217,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
     void MainPage::SetHostingWindow(uint64_t hostingWindow) noexcept
     {
         _hostingHwnd.emplace(reinterpret_cast<HWND>(hostingWindow));
+        // Now that we have a HWND, update our own BG to account for if that
+        // window is using mica or not.
+        _UpdateBackgroundForMica();
     }
 
     bool MainPage::TryPropagateHostingWindow(IInspectable object) noexcept
@@ -645,8 +649,30 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
     // If the theme asks for Mica, then drop out our background, so that we
     // can have mica too.
     void MainPage::_UpdateBackgroundForMica()
-
     {
+        bool isMicaAvailable = false;
+
+        // Check to see if our hosting window supports Mica at all. We'll check
+        // to see if the window has Mica enabled - if it does, then we can
+        // assume that it supports Mica.
+        //
+        // We're doing this instead of checking if we're on Windows build 22621
+        // or higher.
+        if (_hostingHwnd.has_value())
+        {
+            int attribute = DWMSBT_NONE;
+            const auto hr = DwmGetWindowAttribute(*_hostingHwnd, DWMWA_SYSTEMBACKDROP_TYPE, &attribute, sizeof(attribute));
+            if (SUCCEEDED(hr))
+            {
+                isMicaAvailable = attribute == DWMSBT_MAINWINDOW;
+            }
+        }
+
+        if (!isMicaAvailable)
+        {
+            return;
+        }
+
         const auto& theme = _settingsSource.GlobalSettings().CurrentTheme();
         const auto& requestedTheme = _settingsSource.GlobalSettings().CurrentTheme().RequestedTheme();
 


Test patch: