From 76424950e373d3b04ac3dd13019151bfba3e8423 Mon Sep 17 00:00:00 2001 From: sumuel Date: Mon, 17 Aug 2026 20:44:55 +0000 Subject: Add the files --- src/detection/theme/theme.h | 11 +++++++ src/detection/theme/theme_apple.c | 22 +++++++++++++ src/detection/theme/theme_linux.c | 60 +++++++++++++++++++++++++++++++++++ src/detection/theme/theme_nosupport.c | 5 +++ src/detection/theme/theme_windows.c | 27 ++++++++++++++++ 5 files changed, 125 insertions(+) create mode 100644 src/detection/theme/theme.h create mode 100644 src/detection/theme/theme_apple.c create mode 100644 src/detection/theme/theme_linux.c create mode 100644 src/detection/theme/theme_nosupport.c create mode 100644 src/detection/theme/theme_windows.c (limited to 'src/detection/theme') diff --git a/src/detection/theme/theme.h b/src/detection/theme/theme.h new file mode 100644 index 0000000..3498b1d --- /dev/null +++ b/src/detection/theme/theme.h @@ -0,0 +1,11 @@ +#pragma once + +#include "fastfetch.h" +#include "modules/theme/option.h" + +typedef struct FFThemeResult { + FFstrbuf theme1; + FFstrbuf theme2; +} FFThemeResult; + +const char* ffDetectTheme(FFThemeResult* result); diff --git a/src/detection/theme/theme_apple.c b/src/detection/theme/theme_apple.c new file mode 100644 index 0000000..a60d39c --- /dev/null +++ b/src/detection/theme/theme_apple.c @@ -0,0 +1,22 @@ +#include "theme.h" + +#include "detection/os/os.h" + +const char* ffDetectTheme(FFThemeResult* result) { + const FFOSResult* os = ffDetectOS(); + + char* str_end; + const char* version = os->version.chars; + unsigned long osNum = strtoul(version, &str_end, 10); + if (str_end != version) { + if (osNum > 15) { // Tahoe + ffStrbufSetStatic(&result->theme1, "Liquid Glass"); + } else if (osNum < 10) { + ffStrbufSetStatic(&result->theme1, "Platinum"); + } else { + ffStrbufSetStatic(&result->theme1, "Aqua"); + } + } + + return NULL; +} diff --git a/src/detection/theme/theme_linux.c b/src/detection/theme/theme_linux.c new file mode 100644 index 0000000..1de7db8 --- /dev/null +++ b/src/detection/theme/theme_linux.c @@ -0,0 +1,60 @@ +#include "theme.h" +#include "common/parsing.h" +#include "detection/gtk_qt/gtk_qt.h" +#include "detection/displayserver/displayserver.h" + +const char* ffDetectTheme(FFThemeResult* result) { + const FFDisplayServerResult* wmde = ffConnectDisplayServer(); + + if (ffStrbufIgnCaseEqualS(&wmde->wmProtocolName, FF_WM_PROTOCOL_TTY)) { + return "Theme isn't supported in TTY"; + } + + const FFQtResult* plasma = ffDetectQt(); + const FFstrbuf* gtk2 = &ffDetectGTK2()->theme; + const FFstrbuf* gtk3 = &ffDetectGTK3()->theme; + const FFstrbuf* gtk4 = &ffDetectGTK4()->theme; + + if (plasma->widgetStyle.length == 0 && plasma->colorScheme.length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0) { + return "No themes found"; + } + + ffParseGTK(&result->theme2, gtk2, gtk3, gtk4); + + FF_STRBUF_AUTO_DESTROY plasmaColorPretty = ffStrbufCreate(); + if (ffStrbufStartsWithIgnCase(&plasma->colorScheme, &plasma->widgetStyle)) { + ffStrbufAppendNS(&plasmaColorPretty, plasma->colorScheme.length - plasma->widgetStyle.length, &plasma->colorScheme.chars[plasma->widgetStyle.length]); + } else { + ffStrbufAppend(&plasmaColorPretty, &plasma->colorScheme); + } + + ffStrbufTrim(&plasmaColorPretty, ' '); + + if (plasma->widgetStyle.length > 0) { + ffStrbufAppend(&result->theme1, &plasma->widgetStyle); + + if (plasma->colorScheme.length > 0) { + ffStrbufAppendS(&result->theme1, " ("); + + if (plasmaColorPretty.length > 0) { + ffStrbufAppend(&result->theme1, &plasmaColorPretty); + } else { + ffStrbufAppend(&result->theme1, &plasma->colorScheme); + } + + ffStrbufAppendC(&result->theme1, ')'); + } + } else if (plasma->colorScheme.length > 0) { + if (plasmaColorPretty.length > 0) { + ffStrbufAppend(&result->theme1, &plasmaColorPretty); + } else { + ffStrbufAppend(&result->theme1, &plasma->colorScheme); + } + } + + if (plasma->widgetStyle.length > 0 || plasma->colorScheme.length > 0) { + ffStrbufAppendS(&result->theme1, " [Qt]"); + } + + return NULL; +} diff --git a/src/detection/theme/theme_nosupport.c b/src/detection/theme/theme_nosupport.c new file mode 100644 index 0000000..6f42b96 --- /dev/null +++ b/src/detection/theme/theme_nosupport.c @@ -0,0 +1,5 @@ +#include "theme.h" + +const char* ffDetectTheme(FF_A_UNUSED FFThemeResult* result) { + return "Not supported on this platform"; +} diff --git a/src/detection/theme/theme_windows.c b/src/detection/theme/theme_windows.c new file mode 100644 index 0000000..339b79b --- /dev/null +++ b/src/detection/theme/theme_windows.c @@ -0,0 +1,27 @@ +#include "theme.h" + +#include "detection/os/os.h" + +const char* ffDetectTheme(FFThemeResult* result) { + const FFOSResult* os = ffDetectOS(); + uint32_t ver = (uint32_t) ffStrbufToUInt(&os->version, 0); + if (ver > 1000) { + // Windows Server + if (ver >= 2016) { + ffStrbufSetStatic(&result->theme1, "Fluent"); + } else if (ver >= 2012) { + ffStrbufSetStatic(&result->theme1, "Metro"); + } else { + ffStrbufSetStatic(&result->theme1, "Aero"); + } + } else { + if (ver >= 10) { + ffStrbufSetStatic(&result->theme1, "Fluent"); + } else if (ver >= 8) { + ffStrbufSetStatic(&result->theme1, "Metro"); + } else { + ffStrbufSetStatic(&result->theme1, "Aero"); + } + } + return NULL; +} -- cgit v1.2.3