Skip to content

Commit

Permalink
Enhanced dark mode. (#984)
Browse files Browse the repository at this point in the history
* Dark mode for title bar and menus.
  • Loading branch information
Berrysoft committed Apr 10, 2020
1 parent 3aaedf6 commit b888672
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/winmain.c
Expand Up @@ -183,7 +183,6 @@ trace_winsize(char * tag)
#define trace_winsize(tag)
#endif


static HRESULT (WINAPI * pDwmIsCompositionEnabled)(BOOL *) = 0;
static HRESULT (WINAPI * pDwmExtendFrameIntoClientArea)(HWND, const MARGINS *) = 0;
static HRESULT (WINAPI * pDwmEnableBlurBehindWindow)(HWND, void *) = 0;
Expand All @@ -193,7 +192,8 @@ static HRESULT (WINAPI * pSetWindowCompositionAttribute)(HWND, void *) = 0;
static BOOL (WINAPI * pSystemParametersInfo)(UINT, UINT, PVOID, UINT) = 0;

static BOOLEAN (WINAPI * pShouldAppsUseDarkMode)(void) = 0; /* undocumented */
static BOOLEAN (WINAPI * pShouldSystUseDarkMode)(void) = 0; /* undocumented */
static BOOLEAN (WINAPI * pAllowDarkModeForApp)(BOOLEAN) = 0; /* undocumented */
static DWORD (WINAPI * pSetPreferredAppMode)(DWORD) = 0; /* undocumented */
static HRESULT (WINAPI * pSetWindowTheme)(HWND, const wchar_t *, const wchar_t *) = 0;

#define HTHEME HANDLE
Expand Down Expand Up @@ -243,8 +243,13 @@ load_dwm_funcs(void)
if (uxtheme) {
pShouldAppsUseDarkMode =
(void *)GetProcAddress(uxtheme, MAKEINTRESOURCEA(132)); /* ordinal */
pShouldSystUseDarkMode =
(void *)GetProcAddress(uxtheme, MAKEINTRESOURCEA(138)); /* ordinal */
if (HIWORD(GetVersion()) < 18362) { /* 1903 */
pAllowDarkModeForApp =
(void *)GetProcAddress(uxtheme, MAKEINTRESOURCEA(135)); /* ordinal */
} else {
pSetPreferredAppMode =
(void *)GetProcAddress(uxtheme, MAKEINTRESOURCEA(135)); /* ordinal */
}
pSetWindowTheme =
(void *)GetProcAddress(uxtheme, "SetWindowTheme");
pOpenThemeData =
Expand Down Expand Up @@ -4875,6 +4880,15 @@ main(int argc, char *argv[])
}
}

// Set app mode
if (pAllowDarkModeForApp || pSetPreferredAppMode) {
if (HIWORD(GetVersion()) < 18362) {
pAllowDarkModeForApp(1);
} else {
pSetPreferredAppMode(1); /* AllowDark */
}
}

// The window class.
class_atom = RegisterClassExW(&(WNDCLASSEXW){
.cbSize = sizeof(WNDCLASSEXW),
Expand Down Expand Up @@ -4937,19 +4951,20 @@ main(int argc, char *argv[])
trace_winsize("createwindow");

// Dark mode support
if (pShouldSystUseDarkMode) {
if (pShouldAppsUseDarkMode) {
HIGHCONTRASTW hc;
hc.cbSize = sizeof hc;
pSystemParametersInfo(SPI_GETHIGHCONTRAST, sizeof hc, &hc, 0);
//printf("High Contrast scheme <%ls>\n", hc.lpszDefaultScheme);

if (!(hc.dwFlags & HCF_HIGHCONTRASTON) && pShouldSystUseDarkMode()) {
if (!(hc.dwFlags & HCF_HIGHCONTRASTON) && pShouldAppsUseDarkMode()) {
pSetWindowTheme(wnd, W("DarkMode_Explorer"), NULL);
BOOL dark = 1;

// set DWMWA_USE_IMMERSIVE_DARK_MODE
pDwmSetWindowAttribute(wnd, 20, &dark, sizeof dark);
pDwmSetWindowAttribute(wnd, 19, &dark, sizeof dark);
if (pDwmSetWindowAttribute(wnd, 20, &dark, sizeof dark)) {
pDwmSetWindowAttribute(wnd, 19, &dark, sizeof dark);
}
}
}

Expand Down

0 comments on commit b888672

Please sign in to comment.