From a0a46ab73ff9cbb5e9608e781f704088dc3a9ab2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 6 Oct 2022 14:45:02 +0800 Subject: [PATCH] WMTheme: add support for WIndows --- CMakeLists.txt | 2 +- src/detection/wmtheme/wmtheme_windows.c | 41 +++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/detection/wmtheme/wmtheme_windows.c diff --git a/CMakeLists.txt b/CMakeLists.txt index f646f91d2..fbbd97bb1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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 diff --git a/src/detection/wmtheme/wmtheme_windows.c b/src/detection/wmtheme/wmtheme_windows.c new file mode 100644 index 000000000..7611f05da --- /dev/null +++ b/src/detection/wmtheme/wmtheme_windows.c @@ -0,0 +1,41 @@ +#include "fastfetch.h" +#include "wmtheme.h" + +#define WIN32_LEAN_AND_MEAN 1 +#include + +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; +}