Closed darealshinji closed 8 years ago
I've added a description.
Thanks; merged.
I was thinking, maybe the whole popen()
part could be replaced with a different solution, like this:
#include <libgen.h> /* basename(3) */
[...]
void detect_wm_theme(void)
{
char theme[MAX_STRLEN] = "Unknown";
HKEY hkey;
DWORD str_size = MAX_STRLEN;
RegOpenKey(HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Themes", &hkey);
RegQueryValueEx(hkey, "CurrentTheme", 0, NULL, (BYTE *) theme,
&str_size);
if (!STREQ(theme, "Unknown"))
{
snprintf(theme, MAX_STRLEN, "%s", basename(theme));
char *end = theme + strlen(theme)-6;
if (STREQ(end, ".theme"))
theme[strlen(theme)-6] = 0;
}
snprintf(wm_theme_str, MAX_STRLEN, "%s", theme);
return;
}
Try b22f62a. It's pretty much line-for-line what you had above.
Works in Cygwin and MSYS2. But you have two little mistakes in there:
--- a/src/plat/win32/detect.c
+++ b/src/plat/win32/detect.c
@@ -427,7 +427,7 @@ void detect_wm_theme(void)
RegOpenKey(HKEY_CURRENT_USER,
"Software\\Microsoft\\Windows\\CurrentVersion\\Themes", &hkey);
RegQueryValueEx(hkey, "CurrentTheme", 0, NULL, (BYTE *) tmp_theme,
- &str_size)
+ &str_size);
/* if we successfully retrieved a theme from the registry */
if (!STREQ(tmp_theme, "Unknown"))
@@ -438,7 +438,7 @@ void detect_wm_theme(void)
/* if our retrieved theme ends with .theme, truncate it */
if (STREQ(suffix, ".theme"))
{
- tmp_theme[strlen(theme) - 6] = '\0';
+ tmp_theme[strlen(tmp_theme) - 6] = '\0';
}
}
Thanks for the catch! I'll merge this now.
Minor nit: Could you amend the commit to explain why we redefine
REG_QUERY_V
for MSYS targets?Something like this would be good:
Other than that, this looks good. Thanks!