summaryrefslogtreecommitdiffstats
path: root/src/detection/wmtheme
diff options
context:
space:
mode:
Diffstat (limited to 'src/detection/wmtheme')
-rw-r--r--src/detection/wmtheme/wmtheme.h5
-rw-r--r--src/detection/wmtheme/wmtheme_apple.m40
-rw-r--r--src/detection/wmtheme/wmtheme_haiku.cpp30
-rw-r--r--src/detection/wmtheme/wmtheme_linux.c340
-rw-r--r--src/detection/wmtheme/wmtheme_nosupport.c7
-rw-r--r--src/detection/wmtheme/wmtheme_windows.c182
6 files changed, 604 insertions, 0 deletions
diff --git a/src/detection/wmtheme/wmtheme.h b/src/detection/wmtheme/wmtheme.h
new file mode 100644
index 0000000..a737a7a
--- /dev/null
+++ b/src/detection/wmtheme/wmtheme.h
@@ -0,0 +1,5 @@
+#pragma once
+
+#include "fastfetch.h"
+
+bool ffDetectWmTheme(FFstrbuf* themeOrError);
diff --git a/src/detection/wmtheme/wmtheme_apple.m b/src/detection/wmtheme/wmtheme_apple.m
new file mode 100644
index 0000000..8c43877
--- /dev/null
+++ b/src/detection/wmtheme/wmtheme_apple.m
@@ -0,0 +1,40 @@
+#include "fastfetch.h"
+#include "wmtheme.h"
+
+#import <Foundation/Foundation.h>
+
+bool ffDetectWmTheme(FFstrbuf* themeOrError)
+{
+ NSError* error;
+ NSString* fileName = [NSString stringWithFormat:@"file://%s/Library/Preferences/.GlobalPreferences.plist", instance.state.platform.homeDir.chars];
+ NSDictionary* dict = [NSDictionary dictionaryWithContentsOfURL:[NSURL URLWithString:fileName]
+ error:&error];
+ if(error)
+ {
+ ffStrbufAppendS(themeOrError, error.localizedDescription.UTF8String);
+ return false;
+ }
+
+ NSNumber* wmThemeColor = dict[@"AppleAccentColor"];
+ if(!wmThemeColor)
+ ffStrbufAppendS(themeOrError, "Multicolor");
+ else
+ {
+ switch(wmThemeColor.intValue)
+ {
+ case -1: ffStrbufAppendS(themeOrError, "Graphite"); break;
+ case 0: ffStrbufAppendS(themeOrError, "Red"); break;
+ case 1: ffStrbufAppendS(themeOrError, "Orange"); break;
+ case 2: ffStrbufAppendS(themeOrError, "Yellow"); break;
+ case 3: ffStrbufAppendS(themeOrError, "Green"); break;
+ case 4: ffStrbufAppendS(themeOrError, "Blue"); break;
+ case 5: ffStrbufAppendS(themeOrError, "Purple"); break;
+ case 6: ffStrbufAppendS(themeOrError, "Pink"); break;
+ default: ffStrbufAppendS(themeOrError, "Unknown"); break;
+ }
+ }
+
+ NSString* wmTheme = dict[@"AppleInterfaceStyle"];
+ ffStrbufAppendF(themeOrError, " (%s)", wmTheme ? wmTheme.UTF8String : "Light");
+ return true;
+}
diff --git a/src/detection/wmtheme/wmtheme_haiku.cpp b/src/detection/wmtheme/wmtheme_haiku.cpp
new file mode 100644
index 0000000..243eaa4
--- /dev/null
+++ b/src/detection/wmtheme/wmtheme_haiku.cpp
@@ -0,0 +1,30 @@
+extern "C" {
+#include "fastfetch.h"
+#include "wmtheme.h"
+}
+
+#include <Application.h>
+#include <private/interface/DecorInfo.h>
+
+bool ffDetectWmTheme(FFstrbuf* themeOrError)
+{
+ // We need a valid be_app to query the app_server here.
+ BApplication app("application/x-vnd.fastfetch-cli-fastfetch");
+
+ DecorInfoUtility *util = new DecorInfoUtility();
+ DecorInfo* decor = NULL;
+
+ if (util) {
+ decor = util->CurrentDecorator();
+ if (decor) {
+ ffStrbufAppendS(themeOrError, decor->Name().String());
+ }
+ delete util;
+ if (decor) {
+ return true;
+ }
+ }
+
+ ffStrbufAppendS(themeOrError, "Failed to get DecorInfo");
+ return false;
+}
diff --git a/src/detection/wmtheme/wmtheme_linux.c b/src/detection/wmtheme/wmtheme_linux.c
new file mode 100644
index 0000000..e912302
--- /dev/null
+++ b/src/detection/wmtheme/wmtheme_linux.c
@@ -0,0 +1,340 @@
+#include "wmtheme.h"
+#include "common/io.h"
+#include "common/properties.h"
+#include "common/parsing.h"
+#include "common/settings.h"
+#include "common/strutil.h"
+#include "common/mallocHelper.h"
+#include "detection/gtk_qt/gtk_qt.h"
+#include "detection/displayserver/displayserver.h"
+
+static bool detectWMThemeFromConfigFile(const char* configFile, const char* themeRegex, const char* defaultValue, FFstrbuf* themeOrError) {
+ if (!ffParsePropFileConfig(configFile, themeRegex, themeOrError)) {
+ ffStrbufAppendF(themeOrError, "Config file %s doesn't exist", configFile);
+ return false;
+ }
+
+ if (themeOrError->length == 0) {
+ if (defaultValue == NULL) {
+ ffStrbufAppendF(themeOrError, "Couldn't find WM theme in %s", configFile);
+ return false;
+ }
+
+ ffStrbufAppendS(themeOrError, defaultValue);
+ return true;
+ }
+
+ // Remove Plasma-generated prefixes
+ uint32_t idx = 0;
+
+ idx = ffStrbufFirstIndexS(themeOrError, "qml_");
+ if (idx != themeOrError->length) {
+ ffStrbufSubstrAfter(themeOrError, idx + 3);
+ }
+
+ idx = ffStrbufFirstIndexS(themeOrError, "svg__");
+ if (idx != themeOrError->length) {
+ ffStrbufSubstrAfter(themeOrError, idx + 4);
+ }
+
+ return true;
+}
+
+static bool detectWMThemeFromSettings(const char* dconfKey, const char* gsettingsSchemaName, const char* gsettingsPath, const char* gsettingsKey, FFstrbuf* themeOrError) {
+ const char* theme = ffSettingsGetGnome(dconfKey, gsettingsSchemaName, gsettingsPath, gsettingsKey, FF_VARIANT_TYPE_STRING).strValue;
+
+ if (!ffStrSet(theme)) {
+ ffStrbufAppendS(themeOrError, "Couldn't find WM theme in DConf or GSettings");
+ return false;
+ }
+
+ ffStrbufAppendS(themeOrError, theme);
+ return true;
+}
+
+static bool detectGTKThemeAsWMTheme(FFstrbuf* themeOrError) {
+ const FFGTKResult* gtk = ffDetectGTK4();
+ if (gtk->theme.length > 0) {
+ goto ok;
+ }
+
+ gtk = ffDetectGTK3();
+ if (gtk->theme.length > 0) {
+ goto ok;
+ }
+
+ gtk = ffDetectGTK2();
+ if (gtk->theme.length > 0) {
+ goto ok;
+ }
+
+ ffStrbufAppendS(themeOrError, "Couldn't detect GTK4/3/2 theme");
+ return false;
+
+ok:
+ ffStrbufAppend(themeOrError, &gtk->theme);
+ return true;
+}
+
+static bool detectMutter(FFstrbuf* themeOrError) {
+ const char* theme = ffSettingsGetGnome("/org/gnome/shell/extensions/user-theme/name", "org.gnome.shell.extensions.user-theme", NULL, "name", FF_VARIANT_TYPE_STRING).strValue;
+ if (ffStrSet(theme)) {
+ ffStrbufAppendS(themeOrError, theme);
+ return true;
+ }
+
+ return detectGTKThemeAsWMTheme(themeOrError);
+}
+
+static bool detectMuffin(FFstrbuf* themeOrError) {
+ FF_AUTO_FREE const char* name = ffSettingsGetGnome("/org/cinnamon/theme/name", "org.cinnamon.theme", NULL, "name", FF_VARIANT_TYPE_STRING).strValue;
+ FF_AUTO_FREE const char* theme = ffSettingsGetGnome("/org/cinnamon/desktop/wm/preferences/theme", "org.cinnamon.desktop.wm.preferences", NULL, "theme", FF_VARIANT_TYPE_STRING).strValue;
+
+ if (name == NULL && theme == NULL) {
+ ffStrbufAppendS(themeOrError, "Couldn't find muffin theme in GSettings / DConf");
+ return false;
+ }
+
+ if (name == NULL) {
+ ffStrbufAppendS(themeOrError, theme);
+ return true;
+ }
+
+ if (theme == NULL) {
+ ffStrbufAppendS(themeOrError, name);
+ return true;
+ }
+
+ ffStrbufAppendF(themeOrError, "%s (%s)", name, theme);
+ return true;
+}
+
+static bool detectXFWM4(FFstrbuf* themeOrError) {
+ const char* theme = ffSettingsGetXFConf("xfwm4", "/general/theme", FF_VARIANT_TYPE_STRING).strValue;
+
+ if (theme == NULL) {
+ ffStrbufAppendS(themeOrError, "Couldn't find xfwm4::/general/theme in XFConf");
+ return false;
+ }
+
+ ffStrbufAppendS(themeOrError, theme);
+ return true;
+}
+
+static bool detectOpenbox(const FFstrbuf* dePrettyName, FFstrbuf* themeOrError) {
+ FF_STRBUF_AUTO_DESTROY absolutePath = ffStrbufCreateA(64);
+ const char* configFileSubpath = "openbox/rc.xml";
+ if (ffStrbufIgnCaseEqualS(dePrettyName, "LXQt")) {
+ configFileSubpath = "openbox/lxqt-rc.xml";
+ } else if (ffStrbufIgnCaseEqualS(dePrettyName, "LXDE")) {
+ configFileSubpath = "openbox/lxde-rc.xml";
+ }
+
+ if (!ffSearchUserConfigFile(&instance.state.platform.configDirs, configFileSubpath, &absolutePath)) {
+ ffStrbufAppendF(themeOrError, "Couldn't find config file \"%s\"", configFileSubpath);
+ return false;
+ }
+
+ FF_STRBUF_AUTO_DESTROY content = ffStrbufCreate();
+ if (!ffReadFileBuffer(absolutePath.chars, &content)) {
+ ffStrbufAppendF(themeOrError, "Couldn't read \"%s\"", absolutePath.chars);
+ return false;
+ }
+
+ const char* themeStart = strstr(content.chars, "<theme>");
+ if (themeStart == NULL) {
+ goto theme_not_found;
+ }
+
+ const char* themeEnd = strstr(themeStart, "</theme>");
+ if (__builtin_expect(themeEnd == NULL, false)) { // very rare case
+ goto theme_not_found;
+ }
+
+ const char* nameStart = strstr(themeStart, "<name>");
+ if (nameStart == NULL) {
+ goto name_not_found;
+ }
+
+ const char* nameEnd = strstr(nameStart, "</name>");
+ if (nameEnd == NULL || nameEnd > themeEnd) { // (nameEnd > themeEnd) means name is not a theme's child
+ goto name_not_found;
+ }
+
+ nameStart += strlen("<name>");
+ ffStrbufAppendNS(themeOrError, (uint32_t) (nameEnd - nameStart), nameStart);
+ ffStrbufTrim(themeOrError, ' ');
+
+ if (themeOrError->length == 0) {
+ goto name_not_found;
+ }
+
+ return true;
+
+theme_not_found:
+ ffStrbufAppendF(themeOrError, "Couldn't find theme node in \"%s\"", absolutePath.chars);
+ return false;
+
+name_not_found:
+ ffStrbufAppendF(themeOrError, "Couldn't find theme name in \"%s\"", absolutePath.chars);
+ return false;
+}
+
+static bool detectCosmicComp(FFstrbuf* themeOrError) {
+ FF_STRBUF_AUTO_DESTROY path = ffStrbufCreateCopy(FF_LIST_FIRST(FFstrbuf, instance.state.platform.configDirs));
+ ffStrbufAppendS(&path, "cosmic/");
+ uint32_t basePathLength = path.length;
+
+ const char* variant;
+ {
+ char isDarkC;
+ ffStrbufAppendS(&path, "com.system76.CosmicTheme.Mode/v1/is_dark");
+ if (ffReadFileData(path.chars, 1, &isDarkC) == 1) {
+ variant = isDarkC == 't' || isDarkC == '1' ? "Dark" : "Light";
+ } else {
+ ffStrbufAppendF(themeOrError, "Couldn't read cosmic theme mode from %s", path.chars);
+ return false;
+ }
+ ffStrbufSubstrBefore(&path, basePathLength);
+ }
+
+ FF_STRBUF_AUTO_DESTROY name = ffStrbufCreate();
+ ffStrbufAppendF(&path, "com.system76.CosmicTheme.%s/v1/name", variant);
+ if (ffReadFileBuffer(path.chars, &name)) {
+ ffStrbufTrimSpace(&name);
+ ffStrbufTrim(&name, '"');
+ }
+ ffStrbufSubstrBefore(&path, basePathLength);
+
+ if (name.length > 0) {
+ ffStrbufAppend(themeOrError, &name);
+ } else {
+ ffStrbufAppendS(themeOrError, variant);
+ }
+
+ FF_STRBUF_AUTO_DESTROY accent = ffStrbufCreate();
+ ffStrbufAppendF(&path, "com.system76.CosmicTheme.%s/v1/accent", variant);
+ if (ffReadFileBuffer(path.chars, &accent)) {
+ const char* baseStart = strstr(accent.chars, "base:");
+ if (baseStart != NULL) {
+ const char* contentStart = strchr(baseStart, '(');
+ if (contentStart != NULL) {
+ int depth = 1;
+ const char* contentEnd = contentStart + 1;
+ while (*contentEnd != '\0' && depth > 0) {
+ if (*contentEnd == '(') {
+ ++depth;
+ } else if (*contentEnd == ')') {
+ --depth;
+ }
+ ++contentEnd;
+ }
+
+ if (depth == 0) {
+ double red = 0.0, green = 0.0, blue = 0.0, alpha = 1.0;
+ bool ok = true;
+ for (uint32_t i = 0; i < 4; ++i) {
+ const char* key =
+ i == 0 ? "red:" : (i == 1 ? "green:" : (i == 2 ? "blue:" : "alpha:"));
+ const char* componentStart = strstr(contentStart, key);
+ if (componentStart == NULL || componentStart >= contentEnd) {
+ ok = false;
+ break;
+ }
+
+ componentStart += strlen(key);
+ char* componentEnd = NULL;
+ double value = strtod(componentStart, &componentEnd);
+ if (componentEnd == componentStart) {
+ ok = false;
+ break;
+ }
+
+ if (i == 0) {
+ red = value;
+ } else if (i == 1) {
+ green = value;
+ } else if (i == 2) {
+ blue = value;
+ } else {
+ alpha = value;
+ }
+ }
+
+ if (ok) {
+ uint32_t r = red <= 0.0 ? 0 : (red >= 1.0 ? 255 : (uint32_t) (red * 255.0 + 0.5));
+ uint32_t g = green <= 0.0 ? 0 : (green >= 1.0 ? 255 : (uint32_t) (green * 255.0 + 0.5));
+ uint32_t b = blue <= 0.0 ? 0 : (blue >= 1.0 ? 255 : (uint32_t) (blue * 255.0 + 0.5));
+ uint32_t a = alpha <= 0.0 ? 0 : (alpha >= 1.0 ? 255 : (uint32_t) (alpha * 255.0 + 0.5));
+ uint32_t rgb = (r << 16) | (g << 8) | b;
+ if (a == 255) {
+ ffStrbufAppendF(themeOrError, " - #%06X", rgb);
+ } else {
+ ffStrbufAppendF(themeOrError, " - #%06X%02X", rgb, a);
+ }
+ }
+ }
+ }
+ }
+ }
+ ffStrbufSubstrBefore(&path, basePathLength);
+
+ if (name.length > 0) {
+ ffStrbufAppendF(themeOrError, " (%s)", variant);
+ }
+
+ return true;
+}
+
+bool ffDetectWmTheme(FFstrbuf* themeOrError) {
+ const FFDisplayServerResult* wm = ffConnectDisplayServer();
+
+ if (wm->wmPrettyName.length == 0) {
+ ffStrbufAppendS(themeOrError, "WM Theme needs successful WM detection");
+ return false;
+ }
+
+ if (ffStrbufIgnCaseEqualS(&wm->wmPrettyName, FF_WM_PRETTY_KWIN)) {
+ return detectWMThemeFromConfigFile("kwinrc", "theme =", "Breeze", themeOrError);
+ }
+
+ if (ffStrbufIgnCaseEqualS(&wm->wmPrettyName, FF_WM_PRETTY_COSMIC_COMP)) {
+ return detectCosmicComp(themeOrError);
+ }
+
+ if (
+ ffStrbufIgnCaseEqualS(&wm->wmPrettyName, FF_WM_PRETTY_XFWM4) ||
+ (ffStrbufIgnCaseEqualS(&wm->wmPrettyName, "labwc") && ffStrbufIgnCaseEqualS(&wm->dePrettyName, FF_DE_PRETTY_XFCE4))) {
+ return detectXFWM4(themeOrError);
+ }
+
+ if (ffStrbufIgnCaseEqualS(&wm->wmPrettyName, FF_WM_PRETTY_MUTTER)) {
+ if (
+ ffStrbufIgnCaseEqualS(&wm->dePrettyName, FF_DE_PRETTY_GNOME) ||
+ ffStrbufIgnCaseEqualS(&wm->dePrettyName, FF_DE_PRETTY_GNOME_CLASSIC)) {
+ return detectMutter(themeOrError);
+ } else {
+ return detectGTKThemeAsWMTheme(themeOrError);
+ }
+ }
+
+ if (ffStrbufIgnCaseEqualS(&wm->wmPrettyName, FF_WM_PRETTY_MUFFIN)) {
+ return detectMuffin(themeOrError);
+ }
+
+ if (ffStrbufIgnCaseEqualS(&wm->wmPrettyName, FF_WM_PRETTY_MARCO)) {
+ return detectWMThemeFromSettings("/org/mate/Marco/general/theme", "org.mate.Marco.general", NULL, "theme", themeOrError);
+ }
+
+ if (ffStrbufIgnCaseEqualS(&wm->wmPrettyName, FF_WM_PRETTY_OPENBOX)) {
+ return detectOpenbox(&wm->dePrettyName, themeOrError);
+ }
+
+ if (ffStrbufIgnCaseEqualS(&wm->wmPrettyName, FF_WM_PRETTY_ENLIGHTENMENT)) {
+ return detectGTKThemeAsWMTheme(themeOrError);
+ }
+
+ ffStrbufAppendS(themeOrError, "Unknown WM: ");
+ ffStrbufAppend(themeOrError, &wm->wmPrettyName);
+ return false;
+}
diff --git a/src/detection/wmtheme/wmtheme_nosupport.c b/src/detection/wmtheme/wmtheme_nosupport.c
new file mode 100644
index 0000000..8cba51a
--- /dev/null
+++ b/src/detection/wmtheme/wmtheme_nosupport.c
@@ -0,0 +1,7 @@
+#include "fastfetch.h"
+#include "wmtheme.h"
+
+bool ffDetectWmTheme(FFstrbuf* themeOrError) {
+ ffStrbufAppendS(themeOrError, "Not supported on this platform");
+ return false;
+}
diff --git a/src/detection/wmtheme/wmtheme_windows.c b/src/detection/wmtheme/wmtheme_windows.c
new file mode 100644
index 0000000..5d16a84
--- /dev/null
+++ b/src/detection/wmtheme/wmtheme_windows.c
@@ -0,0 +1,182 @@
+#include "fastfetch.h"
+#include "wmtheme.h"
+#include "common/windows/registry.h"
+
+const char* colorHexToString(DWORD hex) {
+ switch (hex) {
+ case 0x696cc3:
+ return "Yellow gold";
+ case 0xff8c00:
+ return "Gold";
+ case 0xf7630c:
+ return "Orange bright";
+ case 0xca5010:
+ return "Orange dark";
+ case 0xda3b01:
+ return "Rust";
+ case 0xef6950:
+ return "Pale rust";
+ case 0xd13438:
+ return "Brick red";
+ case 0xff4343:
+ return "Mod red";
+ case 0xe74856:
+ return "Pale red";
+ case 0xe81123:
+ return "Red";
+ case 0xea005e:
+ return "Rose bright";
+ case 0xc30052:
+ return "Rose";
+ case 0xe3008c:
+ return "Plum light";
+ case 0xbf0077:
+ return "Plum";
+ case 0xc239b3:
+ return "Orchid light";
+ case 0x9a0089:
+ return "Orchid";
+ case 0x0078d4:
+ return "Blue";
+ case 0x0063b1:
+ return "Navy blue";
+ case 0x8d8bd7:
+ return "Purple shadow";
+ case 0x6b69d6:
+ return "Purple shadow dark";
+ case 0x8764b8:
+ return "Iris pastel";
+ case 0x744da9:
+ return "Iris Spring";
+ case 0xb146c2:
+ return "Violet red light";
+ case 0x881798:
+ return "Violet red";
+ case 0x0099bc:
+ return "Cool blue bright";
+ case 0x2d7d9a:
+ return "Cool blue";
+ case 0x00b7c3:
+ return "Seafoam";
+ case 0x038387:
+ return "Seafoam teal";
+ case 0x00b294:
+ return "Mint light";
+ case 0x018574:
+ return "Mint dark";
+ case 0x00cc6a:
+ return "Turf green";
+ case 0x10893e:
+ return "Sport green";
+ case 0x7a7574:
+ return "Gray";
+ case 0x5d5a58:
+ return "Gray brown";
+ case 0x68768a:
+ return "Steel blue";
+ case 0x515c6b:
+ return "Metal blue";
+ case 0x567c73:
+ return "Pale moss";
+ case 0x486860:
+ return "Moss";
+ case 0x498205:
+ return "Meadow green";
+ case 0x107c10:
+ return "Green";
+ case 0x767676:
+ return "Overcast";
+ case 0x4c4a48:
+ return "Storm";
+ case 0x69797e:
+ return "Blue gray";
+ case 0x4a5459:
+ return "Gray dark";
+ case 0x647c64:
+ return "Liddy green";
+ case 0x4c574e:
+ return "Sage";
+ case 0x807143:
+ return "Camouflage desert";
+ case 0x766c59:
+ return "Camouflage";
+ case 0x000000:
+ return "Black";
+ case 0xFFFFFF:
+ return "White";
+ default:
+ return NULL;
+ }
+}
+
+bool ffDetectWmTheme(FFstrbuf* themeOrError) {
+ {
+ FF_AUTO_CLOSE_FD HANDLE hKey = NULL;
+ if (ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes", &hKey, NULL)) {
+ FF_STRBUF_AUTO_DESTROY theme = ffStrbufCreate();
+ if (ffRegReadStrbuf(hKey, L"CurrentTheme", &theme, NULL)) {
+ ffStrbufSubstrBeforeLastC(&theme, '.');
+ ffStrbufSubstrAfterLastC(&theme, '\\');
+ if (isalpha(theme.chars[0])) {
+ theme.chars[0] = (char) toupper(theme.chars[0]);
+ }
+
+ ffStrbufAppend(themeOrError, &theme);
+ }
+ }
+ }
+
+ do {
+ uint32_t rgbColor;
+ uint32_t bgrColor;
+ FF_AUTO_CLOSE_FD HANDLE hKey = NULL;
+ if (ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"Software\\Microsoft\\Windows\\DWM", &hKey, NULL)) {
+ if (ffRegReadUint(hKey, L"AccentColor", &bgrColor, NULL)) {
+ rgbColor = ((bgrColor & 0xFF) << 16) | (bgrColor & 0xFF00) | ((bgrColor >> 16) & 0xFF);
+ } else if (ffRegReadUint(hKey, L"ColorizationColor", &rgbColor, NULL)) {
+ rgbColor &= 0xFFFFFF;
+ } else {
+ break;
+ }
+ } else {
+ break;
+ }
+
+ if (themeOrError->length > 0) {
+ ffStrbufAppendS(themeOrError, " - ");
+ }
+ const char* text = colorHexToString(rgbColor);
+ if (text) {
+ ffStrbufAppendS(themeOrError, text);
+ } else {
+ ffStrbufAppendF(themeOrError, "#%06lX", (long) rgbColor);
+ }
+ } while (false);
+
+ {
+ FF_AUTO_CLOSE_FD HANDLE hKey = NULL;
+ if (ffRegOpenKeyForRead(HKEY_CURRENT_USER, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", &hKey, NULL)) {
+ uint32_t system = 1, apps = 1;
+ if (ffRegReadValues(hKey, 2, (FFRegValueArg[]) {
+ FF_ARG(system, L"SystemUsesLightTheme"),
+ FF_ARG(apps, L"AppsUseLightTheme"),
+ },
+ NULL)) {
+ bool paren = themeOrError->length > 0;
+ if (paren) {
+ ffStrbufAppendS(themeOrError, " (");
+ }
+ ffStrbufAppendF(themeOrError, "System: %s, Apps: %s", system ? "Light" : "Dark", apps ? "Light" : "Dark");
+ if (paren) {
+ ffStrbufAppendC(themeOrError, ')');
+ }
+ }
+ }
+ }
+
+ if (themeOrError->length == 0) {
+ ffStrbufSetStatic(themeOrError, "Failed to find current theme");
+ return false;
+ }
+ return true;
+}