summaryrefslogtreecommitdiff
path: root/src/w32.c
diff options
context:
space:
mode:
authorVince Salvino <salvino@coderedcorp.com>2021-10-27 17:32:09 -0400
committerEli Zaretskii <eliz@gnu.org>2021-10-30 12:55:35 +0300
commitc79d8fa4163faf83796446b330225986ce5db275 (patch)
tree809acc5ba440eceac28002d28de5742cfe8ad39d /src/w32.c
parentc30f95078c0735447c0bf293f2e6f573bc7057a3 (diff)
downloademacs-c79d8fa4163faf83796446b330225986ce5db275.tar.gz
Support system dark mode on Windows 10 version 1809 and higher
* src/w32fns.c (DARK_MODE_APP_NAME) (DWMWA_USE_IMMERSIVE_DARK_MODE_OLD) (DWMWA_USE_IMMERSIVE_DARK_MODE): Define. (w32_applytheme): New function. (w32_createvscrollbar, w32_createhscrollbar, w32_createwindow): Call 'w32_applytheme'. (globals_of_w32fns): Load 'DwmSetWindowAttribute' and 'SetWindowTheme' from their DLLs, and initialize 'w32_darkmode'. * src/w32.c (w32_get_resource): Accept an additional argument instead of hard-coding REG_ROOT; callers changed. (Bug#51404) * etc/NEWS: * doc/emacs/msdos.texi (Windows Misc): Document the new feature.
Diffstat (limited to 'src/w32.c')
-rw-r--r--src/w32.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/w32.c b/src/w32.c
index 9fe698d28d7..369e7ee4e1f 100644
--- a/src/w32.c
+++ b/src/w32.c
@@ -2820,8 +2820,15 @@ sys_putenv (char *str)
#define REG_ROOT "SOFTWARE\\GNU\\Emacs"
+/* Query a value from the Windows Registry (under HKCU and HKLM),
+ where `key` is the registry key, `name` is the name, and `lpdwtype`
+ is a pointer to the return value's type. `lpwdtype` can be NULL if
+ you do not care about the type.
+
+ Returns: pointer to the value, or null pointer if the key/name does
+ not exist. */
LPBYTE
-w32_get_resource (const char *key, LPDWORD lpdwtype)
+w32_get_resource (const char *key, const char *name, LPDWORD lpdwtype)
{
LPBYTE lpvalue;
HKEY hrootkey = NULL;
@@ -2830,13 +2837,13 @@ w32_get_resource (const char *key, LPDWORD lpdwtype)
/* Check both the current user and the local machine to see if
we have any resources. */
- if (RegOpenKeyEx (HKEY_CURRENT_USER, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
+ if (RegOpenKeyEx (HKEY_CURRENT_USER, key, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
{
lpvalue = NULL;
- if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS
+ if (RegQueryValueEx (hrootkey, name, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS
&& (lpvalue = xmalloc (cbData)) != NULL
- && RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
+ && RegQueryValueEx (hrootkey, name, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
{
RegCloseKey (hrootkey);
return (lpvalue);
@@ -2847,13 +2854,13 @@ w32_get_resource (const char *key, LPDWORD lpdwtype)
RegCloseKey (hrootkey);
}
- if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, REG_ROOT, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
+ if (RegOpenKeyEx (HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hrootkey) == ERROR_SUCCESS)
{
lpvalue = NULL;
- if (RegQueryValueEx (hrootkey, key, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS
+ if (RegQueryValueEx (hrootkey, name, NULL, NULL, NULL, &cbData) == ERROR_SUCCESS
&& (lpvalue = xmalloc (cbData)) != NULL
- && RegQueryValueEx (hrootkey, key, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
+ && RegQueryValueEx (hrootkey, name, NULL, lpdwtype, lpvalue, &cbData) == ERROR_SUCCESS)
{
RegCloseKey (hrootkey);
return (lpvalue);
@@ -3077,7 +3084,7 @@ init_environment (char ** argv)
int dont_free = 0;
char bufc[SET_ENV_BUF_SIZE];
- if ((lpval = w32_get_resource (env_vars[i].name, &dwType)) == NULL
+ if ((lpval = w32_get_resource (REG_ROOT, env_vars[i].name, &dwType)) == NULL
/* Also ignore empty environment variables. */
|| *lpval == 0)
{