From: Eli Zaretskii Date: Sat, 30 Oct 2021 10:22:57 +0000 (+0300) Subject: Minor fixes for previous change X-Git-Tag: emacs-29.0.90~3671^2~348 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=520e358a3f7a849824bd1ac31c43097638352aee;p=emacs.git Minor fixes for previous change * src/w32fns.c (DWMWA_USE_IMMERSIVE_DARK_MODE_OLD): Define only if undefined. (w32_applytheme, w32_createwindow, globals_of_w32fns): Minor stylistic copyedits. * etc/NEWS: Reword the entry about using dark mode on MS-Windows. * doc/emacs/msdos.texi (Windows Misc): Fix wording and markup in the last change. --- diff --git a/doc/emacs/msdos.texi b/doc/emacs/msdos.texi index 3c6c61613e2..a4981f7fcc3 100644 --- a/doc/emacs/msdos.texi +++ b/doc/emacs/msdos.texi @@ -1182,11 +1182,12 @@ click-to-focus policy. @end ifnottex On Windows 10 (version 1809 and higher) and Windows 11, Emacs title -bars and scroll bars will follow the system Light or Dark mode, -similar to other programs such as Explorer and Command Prompt. To -change the color mode: Windows Settings > Personalization > Colors > -Choose your color (or Choose your default app mode); then restart -Emacs. +bars and scroll bars will follow the system's Light or Dark mode, +similar to other programs such as Explorer and Command Prompt. To +change the color mode, select @code{Personalization} from +@w{@code{Windows Settings->}}, then +@w{@code{Colors->Choose your color}} (or @w{@code{Choose your default +app mode}}; then restart Emacs. @ifnottex @include msdos-xtra.texi diff --git a/etc/NEWS b/etc/NEWS index 51ff53da184..da9e803e9e9 100644 --- a/etc/NEWS +++ b/etc/NEWS @@ -74,13 +74,6 @@ Image specifiers can now use ':type webp'. For example, an alist entry as '(window-width . (body-columns . 40))' will make the body of the chosen window 40 columns wide. -** MS-Windows - -+++ -*** Supports dark mode on Windows 10 (version 1809 and higher) and Windows 11. -Graphical frames now use the appropriate light or dark title bar and -scroll bars, based on the user's Windows color settings. - * Editing Changes in Emacs 29.1 @@ -449,6 +442,15 @@ when converting menus to use 'easy-menu-define'. * Changes in Emacs 29.1 on Non-Free Operating Systems +** MS-Windows + ++++ +*** Emacs now supports system dark mode. +On Windows 10 (version 1809 and higher) and Windows 11, Emacs will now +follow the system's dark mode: GUI frames use the appropriate light or +dark title bar and scroll bars, based on the user's Windows-wide color +settings. + ---------------------------------------------------------------------- This file is part of GNU Emacs. diff --git a/src/w32fns.c b/src/w32fns.c index bcf0f50c6a6..a16adeabfab 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -79,7 +79,9 @@ along with GNU Emacs. If not, see . */ */ #define DARK_MODE_APP_NAME L"DarkMode_Explorer" /* For Windows 10 version 1809, 1903, 1909. */ +#ifndef DWMWA_USE_IMMERSIVE_DARK_MODE_OLD #define DWMWA_USE_IMMERSIVE_DARK_MODE_OLD 19 +#endif /* For Windows 10 version 2004 and higher, and Windows 11. */ #ifndef DWMWA_USE_IMMERSIVE_DARK_MODE #define DWMWA_USE_IMMERSIVE_DARK_MODE 20 @@ -271,7 +273,7 @@ int w32_major_version; int w32_minor_version; int w32_build_number; -/* If the OS is set to use dark mode. */ +/* If the OS is set to use dark mode. */ BOOL w32_darkmode = FALSE; /* Distinguish between Windows NT and Windows 95. */ @@ -2301,28 +2303,28 @@ w32_init_class (HINSTANCE hinst) } } -/* Applies the Windows system theme (light or dark) to a window handle. */ +/* Applies the Windows system theme (light or dark) to the window + handle HWND. */ static void w32_applytheme (HWND hwnd) { if (w32_darkmode) { - /* Set window theme to that of a built-in Windows app (Explorer) - because it has dark scroll bars and other UI elements. */ + /* Set window theme to that of a built-in Windows app (Explorer), + because it has dark scroll bars and other UI elements. */ if (SetWindowTheme_fn) - { - SetWindowTheme_fn (hwnd, DARK_MODE_APP_NAME, NULL); - } - /* Set the titlebar to system dark mode. */ + SetWindowTheme_fn (hwnd, DARK_MODE_APP_NAME, NULL); + + /* Set the titlebar to system dark mode. */ if (DwmSetWindowAttribute_fn) { - /* Windows 10 version 2004 and up, Windows 11. */ + /* Windows 10 version 2004 and up, Windows 11. */ DWORD attr = DWMWA_USE_IMMERSIVE_DARK_MODE; - /* Windows 10 older than 2004. */ + /* Windows 10 older than 2004. */ if (w32_build_number < 19041) attr = DWMWA_USE_IMMERSIVE_DARK_MODE_OLD; - DwmSetWindowAttribute_fn - (hwnd, attr, &w32_darkmode, sizeof(w32_darkmode)); + DwmSetWindowAttribute_fn (hwnd, attr, + &w32_darkmode, sizeof (w32_darkmode)); } } } @@ -2444,7 +2446,7 @@ w32_createwindow (struct frame *f, int *coords) /* Enable drag-n-drop. */ DragAcceptFiles (hwnd, TRUE); - /* Enable system light/dark theme. */ + /* Enable system light/dark theme. */ w32_applytheme (hwnd); /* Do this to discard the default setting specified by our parent. */ @@ -11090,10 +11092,11 @@ globals_of_w32fns (void) For future wretches who may need to understand Windows build numbers: https://docs.microsoft.com/en-us/windows/release-health/release-information */ - if (w32_major_version >= 10 && w32_build_number >= 17763 - && os_subtype == OS_SUBTYPE_NT) + if (os_subtype == OS_SUBTYPE_NT + && w32_major_version >= 10 && w32_build_number >= 17763) { - /* Load dwmapi and uxtheme, which will be needed to set window themes. */ + /* Load dwmapi.dll and uxtheme.dll, which will be needed to set + window themes. */ HMODULE dwmapi_lib = LoadLibrary("dwmapi.dll"); DwmSetWindowAttribute_fn = (DwmSetWindowAttribute_Proc) get_proc_addr (dwmapi_lib, "DwmSetWindowAttribute"); @@ -11101,17 +11104,17 @@ globals_of_w32fns (void) SetWindowTheme_fn = (SetWindowTheme_Proc) get_proc_addr (uxtheme_lib, "SetWindowTheme"); - /* Check Windows Registry for system theme. DWORD set to 0 or 1. + /* Check Windows Registry for system theme and set w32_darkmode. TODO: "Nice to have" would be to create a lisp setting (which defaults to this Windows Registry value), then read that lisp value here instead. This would allow the user to forcibly override the system theme (which is also user-configurable in Windows settings; see MS-Windows section in Emacs manual). */ - LPBYTE val = w32_get_resource - ("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", - "AppsUseLightTheme", - NULL); - if (val && (DWORD)*val == 0) + LPBYTE val = + w32_get_resource ("Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", + "AppsUseLightTheme", + NULL); + if (val && *val == 0) w32_darkmode = TRUE; }