From 605c2bac86415dcec1e2902cdc46dc11c1ad026a Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Wed, 9 Aug 2023 15:14:52 -0400 Subject: [PATCH] win: Add support for --force-light-mode command-line flag (fixes #3534) Like the existing --force-dark-mode flag. --- patch/patch.cfg | 6 +++ patch/patches/win_light_mode_3534.patch | 55 +++++++++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 patch/patches/win_light_mode_3534.patch diff --git a/patch/patch.cfg b/patch/patch.cfg index 82269e682..c99b1a778 100644 --- a/patch/patch.cfg +++ b/patch/patch.cfg @@ -655,5 +655,11 @@ patches = [ # cef_sandbox build. # https://chromium-review.googlesource.com/c/chromium/src/+/4718245 'name': 'base_escape_4718245' + }, + { + # win: Add support for "force-light-mode" command-line option. + # https://github.com/chromiumembedded/cef/issues/3534 + # https://chromium-review.googlesource.com/c/chromium/src/+/4766248 + 'name': 'win_light_mode_3534' } ] diff --git a/patch/patches/win_light_mode_3534.patch b/patch/patches/win_light_mode_3534.patch new file mode 100644 index 000000000..3268d1930 --- /dev/null +++ b/patch/patches/win_light_mode_3534.patch @@ -0,0 +1,55 @@ +diff --git base/win/dark_mode_support.cc base/win/dark_mode_support.cc +index 325bc70b6ba97..6ba7f2f2becf6 100644 +--- base/win/dark_mode_support.cc ++++ base/win/dark_mode_support.cc +@@ -6,6 +6,7 @@ + + #include + ++#include "base/command_line.h" + #include "base/native_library.h" + #include "base/win/windows_version.h" + +@@ -85,11 +86,20 @@ const DarkModeSupport& GetDarkModeSupport() { + return dark_mode_support; + } + ++bool IsForcedLightMode() { ++ static bool kIsForcedDarkMode = ++ base::CommandLine::ForCurrentProcess()->HasSwitch( ++ "force-light-mode"); ++ return kIsForcedDarkMode; ++} ++ + } // namespace + + namespace base::win { + + bool IsDarkModeAvailable() { ++ if (IsForcedLightMode()) ++ return false; + auto& dark_mode_support = GetDarkModeSupport(); + return (dark_mode_support.allow_dark_mode_for_app || + dark_mode_support.set_preferred_app_mode) && +diff --git ui/native_theme/native_theme_win.cc ui/native_theme/native_theme_win.cc +index 87807be3558a2..7b069213cfea6 100644 +--- ui/native_theme/native_theme_win.cc ++++ ui/native_theme/native_theme_win.cc +@@ -628,7 +628,7 @@ bool NativeThemeWin::ShouldUseDarkColors() const { + + NativeTheme::PreferredColorScheme + NativeThemeWin::CalculatePreferredColorScheme() const { +- if (!InForcedColorsMode()) ++ if (!InForcedColorsMode() || !supports_windows_dark_mode_) + return NativeTheme::CalculatePreferredColorScheme(); + + // According to the spec, the preferred color scheme for web content is 'dark' +@@ -1581,7 +1581,7 @@ void NativeThemeWin::RegisterThemeRegkeyObserver() { + + void NativeThemeWin::UpdateDarkModeStatus() { + bool dark_mode_enabled = false; +- if (hkcu_themes_regkey_.Valid()) { ++ if (supports_windows_dark_mode_ && hkcu_themes_regkey_.Valid()) { + DWORD apps_use_light_theme = 1; + hkcu_themes_regkey_.ReadValueDW(L"AppsUseLightTheme", + &apps_use_light_theme);