-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Win32 darkmode and fix title bar's context menu #11543
base: main
Are you sure you want to change the base?
Conversation
if (os_info.dwBuildNumber < 18362) | ||
SetProp(hwnd, TEXT("UseImmersiveDarkModeColors"), SDL_reinterpret_cast(HANDLE, SDL_static_cast(INT_PTR, value))); | ||
else { | ||
SDL_SharedObject *user32 = SDL_LoadObject("user32.dll"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be replaced with GetModuleHandle() and GetProcAddress() if you want to avoid a separate load.
if (SetPreferredAppModeFunc) | ||
SetPreferredAppModeFunc(UXTHEME_APPMODE_ALLOW_DARK); | ||
} | ||
if (RefreshImmersiveColorPolicyStateFunc) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SDL style is:
if (true) {
statement;
} else {
statement;
}
UXTHEME_APPMODE_FORCE_LIGHT, | ||
UXTHEME_APPMODE_MAX | ||
} WinPreferredAppMode; | ||
typedef enum { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add blank lines between declarations.
I'm not thrilled about using undocumented functions to implement dark mode, but other than that, this looks good to me. @icculus, thoughts? |
Especially because we're looking them up by ordinal instead of symbol name! Undocumentedness aside, are these numbers likely to change in later builds? |
Some functions were changed/added only in some subsequent win10 builds after dark mode appeared first, and then they haven't been changing for a long time. I don't think microsoft will change them for compatibility reasons. |
I'm fine with adding this, but we probably need some switch to turn this off in case a future build of Windows starts making this crash in the field. |
I agree, but I don't think I will be able to implement it. |
Just found some apps already use hidden uxtheme functions: |
Another option is to get the build number from Edit: I've overstated - |
Description
Use hidden uxtheme.dll and user32.dll functions for darkmode instead of using DwmSetWindowAttribute.
Fixes context menu on title bar.
Notes
I couldn't find function to get Windows build number so I import RtlGetVersion from ntdll to get it.
Existing Issue(s)
#11535