mirror of
https://github.com/godotengine/godot.git
synced 2024-11-25 05:33:11 +00:00
[Windows] Add Windows version and Wine checks for Windows 10+ dark mode API.
This commit is contained in:
parent
e351b89117
commit
dbc4e3f350
@ -5595,52 +5595,57 @@ DisplayServerWindows::DisplayServerWindows(const String &p_rendering_driver, Win
|
|||||||
|
|
||||||
HMODULE nt_lib = LoadLibraryW(L"ntdll.dll");
|
HMODULE nt_lib = LoadLibraryW(L"ntdll.dll");
|
||||||
if (nt_lib) {
|
if (nt_lib) {
|
||||||
RtlGetVersionPtr RtlGetVersion = (RtlGetVersionPtr)GetProcAddress(nt_lib, "RtlGetVersion");
|
WineGetVersionPtr wine_get_version = (WineGetVersionPtr)GetProcAddress(nt_lib, "wine_get_version"); // Do not read Windows build number under Wine, it can be set to arbitrary value.
|
||||||
if (RtlGetVersion) {
|
if (!wine_get_version) {
|
||||||
RtlGetVersion(&os_ver);
|
RtlGetVersionPtr RtlGetVersion = (RtlGetVersionPtr)GetProcAddress(nt_lib, "RtlGetVersion");
|
||||||
|
if (RtlGetVersion) {
|
||||||
|
RtlGetVersion(&os_ver);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
FreeLibrary(nt_lib);
|
FreeLibrary(nt_lib);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load UXTheme.
|
// Load UXTheme, available on Windows 10+ only.
|
||||||
HMODULE ux_theme_lib = LoadLibraryW(L"uxtheme.dll");
|
if (os_ver.dwBuildNumber >= 10240) {
|
||||||
if (ux_theme_lib) {
|
HMODULE ux_theme_lib = LoadLibraryW(L"uxtheme.dll");
|
||||||
ShouldAppsUseDarkMode = (ShouldAppsUseDarkModePtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(132));
|
if (ux_theme_lib) {
|
||||||
GetImmersiveColorFromColorSetEx = (GetImmersiveColorFromColorSetExPtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(95));
|
ShouldAppsUseDarkMode = (ShouldAppsUseDarkModePtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(132));
|
||||||
GetImmersiveColorTypeFromName = (GetImmersiveColorTypeFromNamePtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(96));
|
GetImmersiveColorFromColorSetEx = (GetImmersiveColorFromColorSetExPtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(95));
|
||||||
GetImmersiveUserColorSetPreference = (GetImmersiveUserColorSetPreferencePtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(98));
|
GetImmersiveColorTypeFromName = (GetImmersiveColorTypeFromNamePtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(96));
|
||||||
if (os_ver.dwBuildNumber >= 17763) {
|
GetImmersiveUserColorSetPreference = (GetImmersiveUserColorSetPreferencePtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(98));
|
||||||
AllowDarkModeForAppPtr AllowDarkModeForApp = nullptr;
|
if (os_ver.dwBuildNumber >= 17763) { // Windows 10 Redstone 5 (1809)+ only.
|
||||||
SetPreferredAppModePtr SetPreferredAppMode = nullptr;
|
AllowDarkModeForAppPtr AllowDarkModeForApp = nullptr;
|
||||||
FlushMenuThemesPtr FlushMenuThemes = nullptr;
|
SetPreferredAppModePtr SetPreferredAppMode = nullptr;
|
||||||
if (os_ver.dwBuildNumber < 18362) {
|
FlushMenuThemesPtr FlushMenuThemes = nullptr;
|
||||||
AllowDarkModeForApp = (AllowDarkModeForAppPtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(135));
|
if (os_ver.dwBuildNumber < 18362) { // Windows 10 Redstone 5 (1809) and 19H1 (1903) only.
|
||||||
} else {
|
AllowDarkModeForApp = (AllowDarkModeForAppPtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(135));
|
||||||
SetPreferredAppMode = (SetPreferredAppModePtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(135));
|
} else { // Windows 10 19H2 (1909)+ only.
|
||||||
FlushMenuThemes = (FlushMenuThemesPtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(136));
|
SetPreferredAppMode = (SetPreferredAppModePtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(135));
|
||||||
}
|
FlushMenuThemes = (FlushMenuThemesPtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(136));
|
||||||
RefreshImmersiveColorPolicyStatePtr RefreshImmersiveColorPolicyState = (RefreshImmersiveColorPolicyStatePtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(104));
|
|
||||||
if (ShouldAppsUseDarkMode) {
|
|
||||||
bool dark_mode = ShouldAppsUseDarkMode();
|
|
||||||
if (SetPreferredAppMode) {
|
|
||||||
SetPreferredAppMode(dark_mode ? APPMODE_ALLOWDARK : APPMODE_DEFAULT);
|
|
||||||
} else if (AllowDarkModeForApp) {
|
|
||||||
AllowDarkModeForApp(dark_mode);
|
|
||||||
}
|
}
|
||||||
if (RefreshImmersiveColorPolicyState) {
|
RefreshImmersiveColorPolicyStatePtr RefreshImmersiveColorPolicyState = (RefreshImmersiveColorPolicyStatePtr)GetProcAddress(ux_theme_lib, MAKEINTRESOURCEA(104));
|
||||||
RefreshImmersiveColorPolicyState();
|
if (ShouldAppsUseDarkMode) {
|
||||||
}
|
bool dark_mode = ShouldAppsUseDarkMode();
|
||||||
if (FlushMenuThemes) {
|
if (SetPreferredAppMode) {
|
||||||
FlushMenuThemes();
|
SetPreferredAppMode(dark_mode ? APPMODE_ALLOWDARK : APPMODE_DEFAULT);
|
||||||
|
} else if (AllowDarkModeForApp) {
|
||||||
|
AllowDarkModeForApp(dark_mode);
|
||||||
|
}
|
||||||
|
if (RefreshImmersiveColorPolicyState) {
|
||||||
|
RefreshImmersiveColorPolicyState();
|
||||||
|
}
|
||||||
|
if (FlushMenuThemes) {
|
||||||
|
FlushMenuThemes();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
ux_theme_available = ShouldAppsUseDarkMode && GetImmersiveColorFromColorSetEx && GetImmersiveColorTypeFromName && GetImmersiveUserColorSetPreference;
|
ux_theme_available = ShouldAppsUseDarkMode && GetImmersiveColorFromColorSetEx && GetImmersiveColorTypeFromName && GetImmersiveUserColorSetPreference;
|
||||||
if (os_ver.dwBuildNumber >= 18363) {
|
if (os_ver.dwBuildNumber >= 18363) {
|
||||||
dark_title_available = true;
|
dark_title_available = true;
|
||||||
if (os_ver.dwBuildNumber < 19041) {
|
if (os_ver.dwBuildNumber < 19041) {
|
||||||
use_legacy_dark_mode_before_20H1 = true;
|
use_legacy_dark_mode_before_20H1 = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,6 +162,7 @@ enum PreferredAppMode {
|
|||||||
APPMODE_MAX = 4
|
APPMODE_MAX = 4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef const char *(CDECL *WineGetVersionPtr)(void);
|
||||||
typedef bool(WINAPI *ShouldAppsUseDarkModePtr)();
|
typedef bool(WINAPI *ShouldAppsUseDarkModePtr)();
|
||||||
typedef DWORD(WINAPI *GetImmersiveColorFromColorSetExPtr)(UINT dwImmersiveColorSet, UINT dwImmersiveColorType, bool bIgnoreHighContrast, UINT dwHighContrastCacheMode);
|
typedef DWORD(WINAPI *GetImmersiveColorFromColorSetExPtr)(UINT dwImmersiveColorSet, UINT dwImmersiveColorType, bool bIgnoreHighContrast, UINT dwHighContrastCacheMode);
|
||||||
typedef int(WINAPI *GetImmersiveColorTypeFromNamePtr)(const WCHAR *name);
|
typedef int(WINAPI *GetImmersiveColorTypeFromNamePtr)(const WCHAR *name);
|
||||||
|
Loading…
Reference in New Issue
Block a user