From abd8c9b46af056f9e706fcbf0857722c859bb0cd Mon Sep 17 00:00:00 2001 From: "Dustin L. Howett" Date: Fri, 7 Jul 2023 05:46:06 -0500 Subject: [PATCH] Remove TerminalTrySetDarkTheme, use the DWMWA directly (#15667) The DWMWA for this has been documented for quite a while now! I've also updated to a version of TerminalThemeHelpers that removes all the Dark Theme exports. --- dep/nuget/packages.config | 2 +- src/cascadia/WindowsTerminal/AppHost.cpp | 2 +- src/cascadia/WindowsTerminal/IslandWindow.cpp | 8 +++++++- src/cascadia/WindowsTerminal/IslandWindow.h | 1 + src/common.nugetversions.targets | 4 ++-- 5 files changed, 12 insertions(+), 5 deletions(-) diff --git a/dep/nuget/packages.config b/dep/nuget/packages.config index fb1f261b593c..d0c670dcd575 100644 --- a/dep/nuget/packages.config +++ b/dep/nuget/packages.config @@ -5,7 +5,7 @@ - + diff --git a/src/cascadia/WindowsTerminal/AppHost.cpp b/src/cascadia/WindowsTerminal/AppHost.cpp index 9d2066a5dac6..ddbbafdbe9b5 100644 --- a/src/cascadia/WindowsTerminal/AppHost.cpp +++ b/src/cascadia/WindowsTerminal/AppHost.cpp @@ -1089,7 +1089,7 @@ void AppHost::_updateTheme() // It must be done before WM_NCPAINT so that the borders are rendered with // the correct theme. // For more information, see GH#6620. - LOG_IF_FAILED(TerminalTrySetDarkTheme(_window->GetHandle(), _isActuallyDarkTheme(theme.RequestedTheme()))); + _window->UseDarkTheme(_isActuallyDarkTheme(theme.RequestedTheme())); // Update the window frame. If `rainbowFrame:true` is enabled, then that // will be used. Otherwise we'll try to use the `FrameBrush` set in the diff --git a/src/cascadia/WindowsTerminal/IslandWindow.cpp b/src/cascadia/WindowsTerminal/IslandWindow.cpp index 5c0e77929661..88e15c9ede5d 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/IslandWindow.cpp @@ -1873,6 +1873,12 @@ void IslandWindow::RemoveFromSystemMenu(const winrt::hstring& itemLabel) _systemMenuItems.erase(it->first); } +void IslandWindow::UseDarkTheme(const bool v) +{ + const BOOL attribute = v ? TRUE : FALSE; + std::ignore = DwmSetWindowAttribute(GetHandle(), DWMWA_USE_IMMERSIVE_DARK_MODE, &attribute, sizeof(attribute)); +} + void IslandWindow::UseMica(const bool newValue, const double /*titlebarOpacity*/) { // This block of code enables Mica for our window. By all accounts, this @@ -1907,7 +1913,7 @@ void IslandWindow::UseMica(const bool newValue, const double /*titlebarOpacity*/ // the darkness of our window. However, we're keeping this call to prevent // the window from appearing as a white rectangle for a frame before we load // the rest of the settings. - LOG_IF_FAILED(TerminalTrySetDarkTheme(_window.get(), true)); + UseDarkTheme(true); return TRUE; } diff --git a/src/cascadia/WindowsTerminal/IslandWindow.h b/src/cascadia/WindowsTerminal/IslandWindow.h index ca34bc125bf5..db7411f73455 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.h +++ b/src/cascadia/WindowsTerminal/IslandWindow.h @@ -65,6 +65,7 @@ class IslandWindow : void AddToSystemMenu(const winrt::hstring& itemLabel, winrt::delegate callback); void RemoveFromSystemMenu(const winrt::hstring& itemLabel); + void UseDarkTheme(const bool v); virtual void UseMica(const bool newValue, const double titlebarOpacity); WINRT_CALLBACK(DragRegionClicked, winrt::delegate<>); diff --git a/src/common.nugetversions.targets b/src/common.nugetversions.targets index bc949206615e..3113c1240724 100644 --- a/src/common.nugetversions.targets +++ b/src/common.nugetversions.targets @@ -46,7 +46,7 @@ - + @@ -82,7 +82,7 @@ - +