mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
WmTheme: detect accent color (Windows)
This commit is contained in:
@@ -6,36 +6,48 @@ bool ffDetectWmTheme(FFinstance* instance, FFstrbuf* themeOrError)
|
||||
{
|
||||
FF_UNUSED(instance);
|
||||
|
||||
{
|
||||
uint32_t bgrColor;
|
||||
DWORD bufSize = sizeof(bgrColor);
|
||||
if(RegGetValueW(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\DWM", L"AccentColor", RRF_RT_REG_DWORD, NULL, &bgrColor, &bufSize) == ERROR_SUCCESS)
|
||||
ffStrbufAppendF(themeOrError, "Accent Color - #%02X%02X%02X", bgrColor & 0xFF, (bgrColor >> 8) & 0xFF, (bgrColor >> 16) & 0xFF);
|
||||
}
|
||||
|
||||
FF_HKEY_AUTO_DESTROY hKey = NULL;
|
||||
if(ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", &hKey, NULL))
|
||||
{
|
||||
uint32_t SystemUsesLightTheme = 1;
|
||||
if(!ffRegReadUint(hKey, L"SystemUsesLightTheme", &SystemUsesLightTheme, themeOrError))
|
||||
return false;
|
||||
uint32_t value = 1;
|
||||
if(ffRegReadUint(hKey, L"SystemUsesLightTheme", &value, NULL))
|
||||
{
|
||||
if(themeOrError->length > 0) ffStrbufAppendS(themeOrError, ", ");
|
||||
ffStrbufAppendF(themeOrError, "System - %s", value ? "Light" : "Dark");
|
||||
}
|
||||
|
||||
uint32_t AppsUsesLightTheme = 1;
|
||||
if(!ffRegReadUint(hKey, L"AppsUseLightTheme", &AppsUsesLightTheme, themeOrError))
|
||||
return false;
|
||||
|
||||
ffStrbufAppendF(themeOrError, "System - %s, Apps - %s", SystemUsesLightTheme ? "Light" : "Dark", AppsUsesLightTheme ? "Light" : "Dark");
|
||||
|
||||
return true;
|
||||
if(ffRegReadUint(hKey, L"AppsUseLightTheme", &value, NULL))
|
||||
{
|
||||
if(themeOrError->length > 0) ffStrbufAppendS(themeOrError, ", ");
|
||||
ffStrbufAppendF(themeOrError, "Apps - %s", value ? "Light" : "Dark");
|
||||
}
|
||||
}
|
||||
else if(ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes", &hKey, NULL))
|
||||
{
|
||||
if(!ffRegReadStrbuf(hKey, L"CurrentTheme", themeOrError, themeOrError))
|
||||
return false;
|
||||
|
||||
ffStrbufSubstrBeforeLastC(themeOrError, '.');
|
||||
ffStrbufSubstrAfterLastC(themeOrError, '\\');
|
||||
if (isalpha(themeOrError->chars[0]))
|
||||
themeOrError->chars[0] = (char)toupper(themeOrError->chars[0]);
|
||||
|
||||
return true;
|
||||
FF_STRBUF_AUTO_DESTROY theme;
|
||||
ffStrbufInit(&theme);
|
||||
if(ffRegReadStrbuf(hKey, L"CurrentTheme", &theme, NULL))
|
||||
{
|
||||
ffStrbufSubstrBeforeLastC(themeOrError, '.');
|
||||
ffStrbufSubstrAfterLastC(themeOrError, '\\');
|
||||
if(isalpha(themeOrError->chars[0]))
|
||||
themeOrError->chars[0] = (char)toupper(themeOrError->chars[0]);
|
||||
if(themeOrError->length > 0) ffStrbufAppendS(themeOrError, ", ");
|
||||
ffStrbufAppendF(themeOrError, "Theme - %s", theme.chars);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
if(themeOrError->length == 0)
|
||||
{
|
||||
ffStrbufAppendS(themeOrError, "Failed to find current theme");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user