WMTheme: add support for WIndows

This commit is contained in:
李通洲
2022-10-06 14:45:02 +08:00
parent bedd6a1d5d
commit a0a46ab73f
2 changed files with 42 additions and 1 deletions
+1 -1
View File
@@ -317,7 +317,7 @@ if(WIN_MSYS)
src/detection/displayserver/displayserver_windows.c
src/detection/terminalfont/terminalfont_linux.c
src/detection/media/media_linux.c
src/detection/wmtheme/wmtheme_linux.c
src/detection/wmtheme/wmtheme_windows.c
src/detection/font/font_linux.c
src/detection/opengl/opengl_windows.c
src/util/windows/wmi.cpp
+41
View File
@@ -0,0 +1,41 @@
#include "fastfetch.h"
#include "wmtheme.h"
#define WIN32_LEAN_AND_MEAN 1
#include <Windows.h>
bool ffDetectWmTheme(FFinstance* instance, FFstrbuf* themeOrError)
{
FF_UNUSED(instance);
HKEY hKey;
if(RegOpenKeyExW(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", 0, KEY_READ, &hKey) != ERROR_SUCCESS)
{
ffStrbufAppendS(themeOrError, "RegOpenKeyExW() failed");
return false;
}
bool result = true;
int SystemUsesLightTheme = 1;
DWORD bufSize = sizeof(SystemUsesLightTheme);
if(RegQueryValueExW(hKey, L"SystemUsesLightTheme", NULL, NULL, (LPBYTE)&SystemUsesLightTheme, &bufSize) != ERROR_SUCCESS)
{
ffStrbufAppendS(themeOrError, "RegOpenKeyExW(SystemUsesLightTheme) failed");
goto exit;
}
int AppsUsesLightTheme = 1;
bufSize = sizeof(AppsUsesLightTheme);
if(RegQueryValueExW(hKey, L"AppsUseLightTheme", NULL, NULL, (LPBYTE)&AppsUsesLightTheme, &bufSize) != ERROR_SUCCESS)
{
ffStrbufAppendS(themeOrError, "RegOpenKeyExW(AppsUseLightTheme) failed");
goto exit;
}
ffStrbufAppendF(themeOrError, "System - %s, Apps - %s", SystemUsesLightTheme ? "Light" : "Dark", AppsUsesLightTheme ? "Light" : "Dark");
exit:
RegCloseKey(hKey);
return result;
}