diff --git a/CMakeLists.txt b/CMakeLists.txt index f0f241fc3..af142f616 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -359,6 +359,7 @@ if(LINUX) src/detection/temps/temps_linux.c src/detection/terminalfont/terminalfont_linux.c src/detection/terminalshell/terminalshell_linux.c + src/detection/theme/theme_linux.c src/detection/uptime/uptime_linux.c src/detection/users/users_linux.c src/detection/wallpaper/wallpaper_linux.c @@ -400,6 +401,7 @@ elseif(ANDROID) src/detection/temps/temps_linux.c src/detection/terminalfont/terminalfont_android.c src/detection/terminalshell/terminalshell_linux.c + src/detection/theme/theme_nosupport.c src/detection/uptime/uptime_linux.c src/detection/users/users_linux.c src/detection/wallpaper/wallpaper_nosupport.c @@ -449,6 +451,7 @@ elseif(BSD) src/detection/temps/temps_linux.c src/detection/terminalfont/terminalfont_linux.c src/detection/terminalshell/terminalshell_linux.c + src/detection/theme/theme_linux.c src/detection/uptime/uptime_bsd.c src/detection/users/users_linux.c src/detection/wallpaper/wallpaper_linux.c @@ -492,6 +495,7 @@ elseif(APPLE) src/detection/temps/temps_apple.c src/detection/terminalfont/terminalfont_apple.m src/detection/terminalshell/terminalshell_linux.c + src/detection/theme/theme_nosupport.c src/detection/uptime/uptime_bsd.c src/detection/users/users_linux.c src/detection/wallpaper/wallpaper_apple.c @@ -535,6 +539,7 @@ elseif(WIN32) src/detection/terminalfont/terminalfont_windows.c src/detection/terminalshell/terminalshell_windows.c src/detection/temps/temps_windows.cpp + src/detection/theme/theme_nosupport.c src/detection/uptime/uptime_windows.c src/detection/users/users_windows.c src/detection/wallpaper/wallpaper_windows.c diff --git a/src/detection/theme/theme.h b/src/detection/theme/theme.h new file mode 100644 index 000000000..252b4873f --- /dev/null +++ b/src/detection/theme/theme.h @@ -0,0 +1,10 @@ +#pragma once + +#ifndef FF_INCLUDED_detection_theme +#define FF_INCLUDED_detection_theme + +#include "fastfetch.h" + +const char* ffDetectTheme(const FFinstance* instance, FFstrbuf* result); + +#endif diff --git a/src/detection/theme/theme_linux.c b/src/detection/theme/theme_linux.c new file mode 100644 index 000000000..bcacf89ea --- /dev/null +++ b/src/detection/theme/theme_linux.c @@ -0,0 +1,69 @@ +#include "theme.h" +#include "common/parsing.h" +#include "detection/gtk_qt/gtk_qt.h" +#include "detection/displayserver/displayserver.h" + +const char* ffDetectTheme(const FFinstance* instance, FFstrbuf* result) +{ + const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance); + + if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, FF_WM_PROTOCOL_TTY) == 0) + return "Theme isn't supported in TTY"; + + const FFQtResult* plasma = ffDetectQt(instance); + const FFstrbuf* gtk2 = &ffDetectGTK2(instance)->theme; + const FFstrbuf* gtk3 = &ffDetectGTK3(instance)->theme; + const FFstrbuf* gtk4 = &ffDetectGTK4(instance)->theme; + + if(plasma->widgetStyle.length == 0 && plasma->colorScheme.length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0) + return "No themes found"; + + FF_STRBUF_AUTO_DESTROY plasmaColorPretty; + ffStrbufInit(&plasmaColorPretty); + 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, ' '); + + FF_STRBUF_AUTO_DESTROY gtkPretty; + ffStrbufInit(>kPretty); + ffParseGTK(>kPretty, gtk2, gtk3, gtk4); + + if(plasma->widgetStyle.length > 0) + { + ffStrbufAppend(result, &plasma->widgetStyle); + + if(plasma->colorScheme.length > 0) + { + ffStrbufAppendS(result, " ("); + + if(plasmaColorPretty.length > 0) + ffStrbufAppend(result, &plasmaColorPretty); + else + ffStrbufAppend(result, &plasma->colorScheme); + + ffStrbufAppendC(result, ')'); + } + } + else if(plasma->colorScheme.length > 0) + { + if(plasmaColorPretty.length > 0) + ffStrbufAppend(result, &plasmaColorPretty); + else + ffStrbufAppend(result, &plasma->colorScheme); + } + + if(plasma->widgetStyle.length > 0 || plasma->colorScheme.length > 0) + { + ffStrbufAppendS(result, " [QT]"); + + if(gtkPretty.length > 0) + ffStrbufAppendS(result, ", "); + } + + ffStrbufAppend(result, >kPretty); + + return NULL; +} diff --git a/src/detection/theme/theme_nosupport.c b/src/detection/theme/theme_nosupport.c new file mode 100644 index 000000000..d0e9fd073 --- /dev/null +++ b/src/detection/theme/theme_nosupport.c @@ -0,0 +1,6 @@ +#include "theme.h" + +const char* ffDetectTheme(FF_MAYBE_UNUSED const FFinstance* instance, FF_MAYBE_UNUSED FFstrbuf* result) +{ + return "Not supported on this platform"; +} diff --git a/src/fastfetch.c b/src/fastfetch.c index a76bd99a3..0bb548134 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -207,14 +207,8 @@ static inline void printCommandHelp(const char* command) } else if(strcasecmp(command, "theme-format") == 0) { - constructAndPrintCommandHelpFormat("theme", "{} ({3}) [Plasma], {7}", 7, - "Plasma theme", - "Plasma color scheme", - "Plasma color scheme pretty", - "GTK2 theme", - "GTK3 theme", - "GTK4 theme", - "Combined GTK themes" + constructAndPrintCommandHelpFormat("theme", "{}", 1, + "Combined themes" ); } else if(strcasecmp(command, "icons-format") == 0) diff --git a/src/modules/theme.c b/src/modules/theme.c index 9dde574d7..b89f093d4 100644 --- a/src/modules/theme.c +++ b/src/modules/theme.c @@ -1,104 +1,30 @@ #include "fastfetch.h" #include "common/printing.h" -#include "common/parsing.h" -#include "detection/gtk_qt/gtk_qt.h" -#include "detection/displayserver/displayserver.h" +#include "detection/theme/theme.h" #define FF_THEME_MODULE_NAME "Theme" -#define FF_THEME_NUM_FORMAT_ARGS 7 +#define FF_THEME_NUM_FORMAT_ARGS 1 void ffPrintTheme(FFinstance* instance) { - #if defined(__ANDROID__) || defined(__APPLE__) || defined(_WIN32) - - FF_UNUSED(instance); - ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "Theme detection is not supported"); - return; - - #else - - const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance); - - if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, FF_WM_PROTOCOL_TTY) == 0) + FF_STRBUF_AUTO_DESTROY theme; + ffStrbufInit(&theme); + const char* error = ffDetectTheme(instance, &theme); + if (error) { - ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "Theme isn't supported in TTY"); + ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "%s", error); return; } - const FFQtResult* plasma = ffDetectQt(instance); - const FFstrbuf* gtk2 = &ffDetectGTK2(instance)->theme; - const FFstrbuf* gtk3 = &ffDetectGTK3(instance)->theme; - const FFstrbuf* gtk4 = &ffDetectGTK4(instance)->theme; - - if(plasma->widgetStyle.length == 0 && plasma->colorScheme.length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0) - { - ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "No themes found"); - return; - } - - FF_STRBUF_AUTO_DESTROY plasmaColorPretty; - ffStrbufInit(&plasmaColorPretty); - 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, ' '); - - FF_STRBUF_AUTO_DESTROY gtkPretty; - ffStrbufInit(>kPretty); - ffParseGTK(>kPretty, gtk2, gtk3, gtk4); - if(instance->config.theme.outputFormat.length == 0) { ffPrintLogoAndKey(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme.key); - - if(plasma->widgetStyle.length > 0) - { - ffStrbufWriteTo(&plasma->widgetStyle, stdout); - - if(plasma->colorScheme.length > 0) - { - fputs(" (", stdout); - - if(plasmaColorPretty.length > 0) - ffStrbufWriteTo(&plasmaColorPretty, stdout); - else - ffStrbufWriteTo(&plasma->colorScheme, stdout); - - putchar(')'); - } - } - else if(plasma->colorScheme.length > 0) - { - if(plasmaColorPretty.length > 0) - ffStrbufWriteTo(&plasmaColorPretty, stdout); - else - ffStrbufWriteTo(&plasma->colorScheme, stdout); - } - - if(plasma->widgetStyle.length > 0 || plasma->colorScheme.length > 0) - { - fputs(" [QT]", stdout); - - if(gtkPretty.length > 0) - fputs(", ", stdout); - } - - ffStrbufPutTo(>kPretty, stdout); + ffStrbufPutTo(&theme, stdout); } else { ffPrintFormat(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, FF_THEME_NUM_FORMAT_ARGS, (FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &plasma->widgetStyle}, - {FF_FORMAT_ARG_TYPE_STRBUF, &plasma->colorScheme}, - {FF_FORMAT_ARG_TYPE_STRBUF, &plasmaColorPretty}, - {FF_FORMAT_ARG_TYPE_STRBUF, gtk2}, - {FF_FORMAT_ARG_TYPE_STRBUF, gtk3}, - {FF_FORMAT_ARG_TYPE_STRBUF, gtk4}, - {FF_FORMAT_ARG_TYPE_STRBUF, >kPretty} + {FF_FORMAT_ARG_TYPE_STRBUF, &theme} }); } - - #endif }