mirror of
https://github.com/godotengine/godot.git
synced 2024-11-27 09:16:35 +08:00
Added dark mode support for Windows 10, versions 1909(18363) and above
This commit is contained in:
parent
26b1fd0d84
commit
a16ca4b96c
@ -52,6 +52,10 @@
|
|||||||
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
|
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1
|
||||||
|
#define DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 19
|
||||||
|
#endif
|
||||||
|
|
||||||
#if defined(__GNUC__)
|
#if defined(__GNUC__)
|
||||||
// Workaround GCC warning from -Wcast-function-type.
|
// Workaround GCC warning from -Wcast-function-type.
|
||||||
#define GetProcAddress (void *)GetProcAddress
|
#define GetProcAddress (void *)GetProcAddress
|
||||||
@ -2959,6 +2963,14 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
|
|||||||
|
|
||||||
// Process window messages.
|
// Process window messages.
|
||||||
switch (uMsg) {
|
switch (uMsg) {
|
||||||
|
case WM_CREATE: {
|
||||||
|
if (is_dark_mode_supported() && dark_title_available) {
|
||||||
|
BOOL value = is_dark_mode();
|
||||||
|
|
||||||
|
::DwmSetWindowAttribute(windows[window_id].hWnd, use_legacy_dark_mode_before_20H1 ? DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 : DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
|
||||||
|
SendMessageW(windows[window_id].hWnd, WM_PAINT, 0, 0);
|
||||||
|
}
|
||||||
|
} break;
|
||||||
case WM_NCPAINT: {
|
case WM_NCPAINT: {
|
||||||
if (RenderingServer::get_singleton() && (windows[window_id].borderless || (windows[window_id].fullscreen && windows[window_id].multiwindow_fs))) {
|
if (RenderingServer::get_singleton() && (windows[window_id].borderless || (windows[window_id].fullscreen && windows[window_id].multiwindow_fs))) {
|
||||||
Color color = RenderingServer::get_singleton()->get_default_clear_color();
|
Color color = RenderingServer::get_singleton()->get_default_clear_color();
|
||||||
@ -3091,14 +3103,14 @@ LRESULT DisplayServerWindows::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARA
|
|||||||
if (lParam && CompareStringOrdinal(reinterpret_cast<LPCWCH>(lParam), -1, L"ImmersiveColorSet", -1, true) == CSTR_EQUAL) {
|
if (lParam && CompareStringOrdinal(reinterpret_cast<LPCWCH>(lParam), -1, L"ImmersiveColorSet", -1, true) == CSTR_EQUAL) {
|
||||||
if (is_dark_mode_supported() && dark_title_available) {
|
if (is_dark_mode_supported() && dark_title_available) {
|
||||||
BOOL value = is_dark_mode();
|
BOOL value = is_dark_mode();
|
||||||
::DwmSetWindowAttribute(windows[window_id].hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
|
::DwmSetWindowAttribute(windows[window_id].hWnd, use_legacy_dark_mode_before_20H1 ? DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 : DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case WM_THEMECHANGED: {
|
case WM_THEMECHANGED: {
|
||||||
if (is_dark_mode_supported() && dark_title_available) {
|
if (is_dark_mode_supported() && dark_title_available) {
|
||||||
BOOL value = is_dark_mode();
|
BOOL value = is_dark_mode();
|
||||||
::DwmSetWindowAttribute(windows[window_id].hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
|
::DwmSetWindowAttribute(windows[window_id].hWnd, use_legacy_dark_mode_before_20H1 ? DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 : DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
|
||||||
}
|
}
|
||||||
} break;
|
} break;
|
||||||
case WM_SYSCOMMAND: // Intercept system commands.
|
case WM_SYSCOMMAND: // Intercept system commands.
|
||||||
@ -4351,7 +4363,7 @@ DisplayServer::WindowID DisplayServerWindows::_create_window(WindowMode p_mode,
|
|||||||
|
|
||||||
if (is_dark_mode_supported() && dark_title_available) {
|
if (is_dark_mode_supported() && dark_title_available) {
|
||||||
BOOL value = is_dark_mode();
|
BOOL value = is_dark_mode();
|
||||||
::DwmSetWindowAttribute(wd.hWnd, DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
|
::DwmSetWindowAttribute(wd.hWnd, use_legacy_dark_mode_before_20H1 ? DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 : DWMWA_USE_IMMERSIVE_DARK_MODE, &value, sizeof(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef RD_ENABLED
|
#ifdef RD_ENABLED
|
||||||
@ -4489,6 +4501,7 @@ WTEnablePtr DisplayServerWindows::wintab_WTEnable = nullptr;
|
|||||||
|
|
||||||
// UXTheme API.
|
// UXTheme API.
|
||||||
bool DisplayServerWindows::dark_title_available = false;
|
bool DisplayServerWindows::dark_title_available = false;
|
||||||
|
bool DisplayServerWindows::use_legacy_dark_mode_before_20H1 = false;
|
||||||
bool DisplayServerWindows::ux_theme_available = false;
|
bool DisplayServerWindows::ux_theme_available = false;
|
||||||
ShouldAppsUseDarkModePtr DisplayServerWindows::ShouldAppsUseDarkMode = nullptr;
|
ShouldAppsUseDarkModePtr DisplayServerWindows::ShouldAppsUseDarkMode = nullptr;
|
||||||
GetImmersiveColorFromColorSetExPtr DisplayServerWindows::GetImmersiveColorFromColorSetEx = nullptr;
|
GetImmersiveColorFromColorSetExPtr DisplayServerWindows::GetImmersiveColorFromColorSetEx = nullptr;
|
||||||
@ -4610,8 +4623,11 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
|
|||||||
GetImmersiveUserColorSetPreference = (GetImmersiveUserColorSetPreferencePtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(98));
|
GetImmersiveUserColorSetPreference = (GetImmersiveUserColorSetPreferencePtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(98));
|
||||||
|
|
||||||
ux_theme_available = ShouldAppsUseDarkMode && GetImmersiveColorFromColorSetEx && GetImmersiveColorTypeFromName && GetImmersiveUserColorSetPreference;
|
ux_theme_available = ShouldAppsUseDarkMode && GetImmersiveColorFromColorSetEx && GetImmersiveColorTypeFromName && GetImmersiveUserColorSetPreference;
|
||||||
if (os_ver.dwBuildNumber >= 22000) {
|
if (os_ver.dwBuildNumber >= 18363) {
|
||||||
dark_title_available = true;
|
dark_title_available = true;
|
||||||
|
if (os_ver.dwBuildNumber < 19041) {
|
||||||
|
use_legacy_dark_mode_before_20H1 = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -294,6 +294,7 @@ class DisplayServerWindows : public DisplayServer {
|
|||||||
|
|
||||||
// UXTheme API
|
// UXTheme API
|
||||||
static bool dark_title_available;
|
static bool dark_title_available;
|
||||||
|
static bool use_legacy_dark_mode_before_20H1;
|
||||||
static bool ux_theme_available;
|
static bool ux_theme_available;
|
||||||
static ShouldAppsUseDarkModePtr ShouldAppsUseDarkMode;
|
static ShouldAppsUseDarkModePtr ShouldAppsUseDarkMode;
|
||||||
static GetImmersiveColorFromColorSetExPtr GetImmersiveColorFromColorSetEx;
|
static GetImmersiveColorFromColorSetExPtr GetImmersiveColorFromColorSetEx;
|
||||||
|
Loading…
Reference in New Issue
Block a user