[Bf-blender-cvs] [ddbac88c08e] master: Win32: Dark Mode Title Bar Color

Harley Acheson noreply at git.blender.org
Thu May 5 05:19:18 CEST 2022


Commit: ddbac88c08ef2f97e4d7b99690cef28322cfb0ed
Author: Harley Acheson
Date:   Wed May 4 20:18:15 2022 -0700
Branches: master
https://developer.blender.org/rBddbac88c08ef2f97e4d7b99690cef28322cfb0ed

Win32: Dark Mode Title Bar Color

Blender will respect Windows "Dark Mode" setting for title bar color.

See D14847 for details.

Differential Revision: https://developer.blender.org/D14847

Reviewed by Ray Molenkamp

===================================================================

M	build_files/cmake/platform/platform_win32.cmake
M	intern/ghost/intern/GHOST_SystemWin32.cpp
M	intern/ghost/intern/GHOST_WindowWin32.cpp
M	intern/ghost/intern/GHOST_WindowWin32.h

===================================================================

diff --git a/build_files/cmake/platform/platform_win32.cmake b/build_files/cmake/platform/platform_win32.cmake
index c5d2049b292..40c25abd585 100644
--- a/build_files/cmake/platform/platform_win32.cmake
+++ b/build_files/cmake/platform/platform_win32.cmake
@@ -104,7 +104,7 @@ string(APPEND CMAKE_MODULE_LINKER_FLAGS " /SAFESEH:NO /ignore:4099")
 list(APPEND PLATFORM_LINKLIBS
   ws2_32 vfw32 winmm kernel32 user32 gdi32 comdlg32 Comctl32 version
   advapi32 shfolder shell32 ole32 oleaut32 uuid psapi Dbghelp Shlwapi
-  pathcch Shcore
+  pathcch Shcore Dwmapi
 )
 
 if(WITH_INPUT_IME)
diff --git a/intern/ghost/intern/GHOST_SystemWin32.cpp b/intern/ghost/intern/GHOST_SystemWin32.cpp
index 83869188b65..ff02bc5781e 100644
--- a/intern/ghost/intern/GHOST_SystemWin32.cpp
+++ b/intern/ghost/intern/GHOST_SystemWin32.cpp
@@ -14,6 +14,7 @@
 #endif
 
 #include <commctrl.h>
+#include <dwmapi.h>
 #include <psapi.h>
 #include <shellapi.h>
 #include <shellscalingapi.h>
@@ -1985,6 +1986,11 @@ LRESULT WINAPI GHOST_SystemWin32::s_wndProc(HWND hwnd, UINT msg, WPARAM wParam,
             ::SetFocus(hwnd);
           }
           break;
+        case WM_SETTINGCHANGE:
+          if (wcscmp(LPCWSTR(lParam), L"ImmersiveColorSet") == 0) {
+            window->ThemeRefresh();
+          }
+          break;
         ////////////////////////////////////////////////////////////////////////
         // Window events, ignored
         ////////////////////////////////////////////////////////////////////////
diff --git a/intern/ghost/intern/GHOST_WindowWin32.cpp b/intern/ghost/intern/GHOST_WindowWin32.cpp
index 2ce224b666b..f74a4b17a51 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.cpp
+++ b/intern/ghost/intern/GHOST_WindowWin32.cpp
@@ -16,9 +16,7 @@
 
 #include "GHOST_ContextWGL.h"
 
-#ifdef WIN32_COMPOSITING
-#  include <Dwmapi.h>
-#endif
+#include <Dwmapi.h>
 
 #include <assert.h>
 #include <math.h>
@@ -172,6 +170,8 @@ GHOST_WindowWin32::GHOST_WindowWin32(GHOST_SystemWin32 *system,
       break;
   }
 
+  ThemeRefresh();
+
   ::ShowWindow(m_hWnd, nCmdShow);
 
 #ifdef WIN32_COMPOSITING
@@ -1016,6 +1016,25 @@ GHOST_TabletData GHOST_WindowWin32::getTabletData()
   }
 }
 
+void GHOST_WindowWin32::ThemeRefresh()
+{
+  DWORD lightMode;
+  DWORD pcbData = sizeof(lightMode);
+  if (RegGetValueW(HKEY_CURRENT_USER,
+                   L"Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize\\",
+                   L"AppsUseLightTheme",
+                   RRF_RT_REG_DWORD,
+                   NULL,
+                   &lightMode,
+                   &pcbData) == ERROR_SUCCESS) {
+    BOOL DarkMode = !lightMode;
+
+    /* 20 == DWMWA_USE_IMMERSIVE_DARK_MODE in Windows 11 SDK.  This value was undocumented for
+     * Windows 10 versions 2004 and later, supported for Windows 11 Build 22000 and later. */
+    DwmSetWindowAttribute(this->m_hWnd, 20, &DarkMode, sizeof(DarkMode));
+  }
+}
+
 uint16_t GHOST_WindowWin32::getDPIHint()
 {
   if (m_user32) {
diff --git a/intern/ghost/intern/GHOST_WindowWin32.h b/intern/ghost/intern/GHOST_WindowWin32.h
index d5f47871aff..bc678adff3c 100644
--- a/intern/ghost/intern/GHOST_WindowWin32.h
+++ b/intern/ghost/intern/GHOST_WindowWin32.h
@@ -294,6 +294,9 @@ class GHOST_WindowWin32 : public GHOST_Window {
   /** True if the window currently resizing. */
   bool m_inLiveResize;
 
+  /** Called when OS colors change and when the window is created. */
+  void ThemeRefresh();
+
 #ifdef WITH_INPUT_IME
   GHOST_ImeWin32 *getImeInput()
   {



More information about the Bf-blender-cvs mailing list