From af358b704987f3b4d370c203a5de5bef88b3f1cf Mon Sep 17 00:00:00 2001 From: Mike Griese Date: Wed, 20 Sep 2023 15:47:25 -0500 Subject: [PATCH] Don't update the settings, unless the theme actually changed (#16004) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `ImmersiveColorSet` gets sent more often than just on a theme change. It notably gets sent when the PC is locked, or the UAC prompt opens. ## Validation Steps Performed Tested manually by setting the font to `garbo`and: * locking, then logging back in. No dialog ✅ * UAC via run dialog + `regedit`. No dialog ✅ * Actually changing the OS theme. Dialog ✅ Closes #15732 (cherry picked from commit c1bdcf8b9732fab115275416557712878992e04a) Service-Card-Id: 90600308 Service-Version: 1.18 --- src/cascadia/WindowsTerminal/IslandWindow.cpp | 13 ++++++++++++- src/cascadia/WindowsTerminal/IslandWindow.h | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/cascadia/WindowsTerminal/IslandWindow.cpp b/src/cascadia/WindowsTerminal/IslandWindow.cpp index 87ec8d5dbce..9bea05acfe9 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.cpp +++ b/src/cascadia/WindowsTerminal/IslandWindow.cpp @@ -199,6 +199,8 @@ void IslandWindow::_HandleCreateWindow(const WPARAM, const LPARAM lParam) noexce UpdateWindow(_window.get()); UpdateWindowIconForActiveMetrics(_window.get()); + + _currentSystemThemeIsDark = Theme::IsSystemInDarkTheme(); } // Method Description: @@ -745,7 +747,16 @@ long IslandWindow::_calculateTotalSize(const bool isWidth, const long clientSize // themes, color schemes that might depend on the OS theme if (param == L"ImmersiveColorSet") { - _UpdateSettingsRequestedHandlers(); + // GH#15732: Don't update the settings, unless the theme + // _actually_ changed. ImmersiveColorSet gets sent more often + // than just on a theme change. It notably gets sent when the PC + // is locked, or the UAC prompt opens. + auto isCurrentlyDark = Theme::IsSystemInDarkTheme(); + if (isCurrentlyDark != _currentSystemThemeIsDark) + { + _currentSystemThemeIsDark = isCurrentlyDark; + _UpdateSettingsRequestedHandlers(); + } } } break; diff --git a/src/cascadia/WindowsTerminal/IslandWindow.h b/src/cascadia/WindowsTerminal/IslandWindow.h index c0abd343e1b..eee013c529a 100644 --- a/src/cascadia/WindowsTerminal/IslandWindow.h +++ b/src/cascadia/WindowsTerminal/IslandWindow.h @@ -117,6 +117,7 @@ class IslandWindow : RECT _rcWindowBeforeFullscreen{}; RECT _rcWorkBeforeFullscreen{}; UINT _dpiBeforeFullscreen{ 96 }; + bool _currentSystemThemeIsDark{ true }; void _coldInitialize(); void _warmInitialize();