Skip to content

Commit

Permalink
Windows: Dark mode improvement; the context menu of the game's window…
Browse files Browse the repository at this point in the history
… titlebar now also honors the system's dark mode setting. However, we are using undocumented APIs for this, so there are no guarantees that those APIs will remain unchanged in the future. If needed, the macro USE_UNDOCUMENTED_DARKMODE_API can be set to 0 to disable the feature.
  • Loading branch information
AnotherCommander committed Nov 12, 2024
1 parent 5b0b3a2 commit 7f5034b
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/SDL/MyOpenGLView.m
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,28 @@
#include <ctype.h>

#if OOLITE_WINDOWS
#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE
#define DWMWA_USE_IMMERSIVE_DARK_MODE 20
#endif
HRESULT WINAPI DwmSetWindowAttribute (HWND hwnd, DWORD dwAttribute, LPCVOID pvAttribute, DWORD cbAttribute);

#define USE_UNDOCUMENTED_DARKMODE_API 1

#if USE_UNDOCUMENTED_DARKMODE_API
#ifndef LOAD_LIBRARY_SEARCH_SYSTEM32
#define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800
#endif
typedef DWORD(WINAPI* pfnSetPreferredAppMode)(DWORD appMode);
enum PreferredAppMode
{
Default,
AllowDark,
ForceDark,
ForceLight,
Max
};
#endif
#endif //OOLITE_WINDOWS

@interface MyOpenGLView (OOPrivate)

Expand Down Expand Up @@ -250,7 +269,19 @@ - (id) init
}

atDesktopResolution = YES;

#if USE_UNDOCUMENTED_DARKMODE_API
// dark mode stuff - this is mainly for the winodw titlebar's context menu
HMODULE hUxTheme = LoadLibraryExW(L"uxtheme.dll", NULL, LOAD_LIBRARY_SEARCH_SYSTEM32);
if (hUxTheme)
{
// hack alert! ordinal 135 is undocumented and could change in a future version of Windows
pfnSetPreferredAppMode SetPreferredAppMode = (pfnSetPreferredAppMode)GetProcAddress(hUxTheme, MAKEINTRESOURCEA(135));
if (SetPreferredAppMode) SetPreferredAppMode(AllowDark);
FreeLibrary(hUxTheme);
}
#endif
#endif //OOLITE_WINDOWS

grabMouseStatus = NO;

Expand Down

0 comments on commit 7f5034b

Please sign in to comment.