diff --git a/src/common/calculatePlasma.c b/src/common/calculatePlasma.c index 5d47778da..39da467e6 100644 --- a/src/common/calculatePlasma.c +++ b/src/common/calculatePlasma.c @@ -1,12 +1,22 @@ #include "fastfetch.h" +#include #include -void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr) +typedef enum PlasmaCategory +{ + PLASMA_CATEGORY_GENERAL, + PLASMA_CATEGORY_KDE, + PLASMA_CATEGORY_ICONS, + PLASMA_CATEGORY_OTHER +} PlasmaCategory; + +void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** colorNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr) { static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; static FFstrbuf themeName; + static FFstrbuf colorName; static FFstrbuf iconsName; static FFstrbuf fontName; static bool init = false; @@ -14,6 +24,9 @@ void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** if(themeNamePtr != NULL) *themeNamePtr = &themeName; + if(colorNamePtr != NULL) + *colorNamePtr = &colorName; + if(iconsNamePtr != NULL) *iconsNamePtr = &iconsName; @@ -31,6 +44,7 @@ void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** init = true; ffStrbufInit(&themeName); + ffStrbufInit(&colorName); ffStrbufInit(&iconsName); ffStrbufInit(&fontName); @@ -49,19 +63,49 @@ void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** char* line = NULL; size_t len = 0; + PlasmaCategory category = PLASMA_CATEGORY_OTHER; + while(getline(&line, &len, kdeglobals) != -1) { - sscanf(line, "widgetStyle=%[^\n]", themeName.chars); - sscanf(line, "widgetStyle=\"%[^\"]+", themeName.chars); + if(line[0] == '[') + { + char categoryName[32]; + sscanf(line, "[%[^]]", categoryName); - sscanf(line, "Theme=%[^\n]", iconsName.chars); - sscanf(line, "Theme=\"%[^\"]+", iconsName.chars); + if(strcasecmp(categoryName, "General") == 0) + category = PLASMA_CATEGORY_GENERAL; + else if(strcasecmp(categoryName, "KDE") == 0) + category = PLASMA_CATEGORY_KDE; + else if(strcasecmp(categoryName, "Icons") == 0) + category = PLASMA_CATEGORY_ICONS; + else + category = PLASMA_CATEGORY_OTHER; - sscanf(line, "font=%[^\n]", fontName.chars); - sscanf(line, "font=\"%[^\"]+", fontName.chars); + continue; + } + + if(category == PLASMA_CATEGORY_KDE) + { + sscanf(line, "widgetStyle=%[^\n]", themeName.chars); + sscanf(line, "widgetStyle=\"%[^\"]+", themeName.chars); + } + else if(category == PLASMA_CATEGORY_GENERAL) + { + sscanf(line, "ColorScheme=%[^\n]", colorName.chars); + sscanf(line, "ColorScheme=\"%[^\"]+", colorName.chars); + + sscanf(line, "font=%[^\n]", fontName.chars); + sscanf(line, "font=\"%[^\"]+", fontName.chars); + } + else if(category == PLASMA_CATEGORY_ICONS) + { + sscanf(line, "Theme=%[^\n]", iconsName.chars); + sscanf(line, "Theme=\"%[^\"]+", iconsName.chars); + } } ffStrbufRecalculateLength(&themeName); + ffStrbufRecalculateLength(&colorName); ffStrbufRecalculateLength(&iconsName); ffStrbufRecalculateLength(&fontName); @@ -71,8 +115,17 @@ void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** fclose(kdeglobals); ffStrbufDestroy(&kdeglobalsFile); - //When using Noto Sans 10, the default font in KDE Plasma, the font entry is deleted from the config file instead of set. - //So the pure existence of the file sets this font value if not set other in the file itself. + //In Plasma the default value is never set in the config file, but the whole key-value is discarded. + ///We must set these values by our self if the file exists (it always does here) + if(themeName.length == 0) + ffStrbufAppendS(&themeName, "Breeze"); + + if(colorName.length == 0) + ffStrbufAppendS(&colorName, "BreezeLight"); + + if(iconsName.length == 0) + ffStrbufAppendS(&iconsName, "Breeze"); + if(fontName.length == 0) ffStrbufAppendS(&fontName, "Noto Sans, 10"); diff --git a/src/common/threading.c b/src/common/threading.c index 1b08e943f..4f0694a9f 100644 --- a/src/common/threading.c +++ b/src/common/threading.c @@ -4,7 +4,7 @@ static inline void* calculatePlasmaThreadMain(void* instance) { - ffCalculatePlasma((FFinstance*)instance, NULL, NULL, NULL); + ffCalculatePlasma((FFinstance*)instance, NULL, NULL, NULL, NULL); return NULL; } diff --git a/src/fastfetch.c b/src/fastfetch.c index 2991c8fb4..ba2a47ec8 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -308,8 +308,10 @@ static inline void printCommandHelp(const char* command) } else if(strcasecmp(command, "theme-format") == 0) { - constructAndPrintCommandHelpFormat("theme", "{} [Plasma], {5}", 5, + constructAndPrintCommandHelpFormat("theme", "{} ({3}) [Plasma], {7}", 7, "Plasma theme", + "Plasma color scheme", + "Plasma color scheme pretty", "GTK2 theme", "GTK3 theme", "GTK4 theme", diff --git a/src/fastfetch.h b/src/fastfetch.h index 422efd88e..d61a863a0 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -170,7 +170,7 @@ void ffGetFont(const char* font, FFstrbuf* name, double* size); void ffGetFontPretty(FFstrbuf* buffer, const FFstrbuf* name, double size); //common/calculatePlasma.c -void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr); +void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** colorNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr); //common/calculateGTK.c void ffCalculateGTK2(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr); diff --git a/src/modules/font.c b/src/modules/font.c index a0b357d53..b13b5e3d6 100644 --- a/src/modules/font.c +++ b/src/modules/font.c @@ -3,7 +3,7 @@ void ffPrintFont(FFinstance* instance) { FFstrbuf* plasma; - ffCalculatePlasma(instance, NULL, NULL, &plasma); + ffCalculatePlasma(instance, NULL, NULL, NULL, &plasma); FFstrbuf* gtk2; ffCalculateGTK2(instance, NULL, NULL, >k2); diff --git a/src/modules/icons.c b/src/modules/icons.c index 507fdeb1c..02eb65810 100644 --- a/src/modules/icons.c +++ b/src/modules/icons.c @@ -3,7 +3,7 @@ void ffPrintIcons(FFinstance* instance) { FFstrbuf* plasma; - ffCalculatePlasma(instance, NULL, &plasma, NULL); + ffCalculatePlasma(instance, NULL, NULL, &plasma, NULL); FFstrbuf* gtk2; ffCalculateGTK2(instance, NULL, >k2, NULL); diff --git a/src/modules/theme.c b/src/modules/theme.c index 40b5aa3d8..5bea7032c 100644 --- a/src/modules/theme.c +++ b/src/modules/theme.c @@ -2,8 +2,9 @@ void ffPrintTheme(FFinstance* instance) { - FFstrbuf* plasma; - ffCalculatePlasma(instance, &plasma, NULL, NULL); + FFstrbuf* plasmaTheme; + FFstrbuf* plasmaColor; + ffCalculatePlasma(instance, &plasmaTheme, &plasmaColor, NULL, NULL); FFstrbuf* gtk2; ffCalculateGTK2(instance, >k2, NULL, NULL); @@ -14,12 +15,20 @@ void ffPrintTheme(FFinstance* instance) FFstrbuf* gtk4; ffCalculateGTK4(instance, >k4, NULL, NULL); - if(plasma->length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0) + if(plasmaTheme->length == 0 && plasmaColor->length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0) { ffPrintError(instance, &instance->config.themeKey, "Theme", "No themes found"); return; } + FF_STRBUF_CREATE(plasmaColorPretty); + if(ffStrbufStartsWithIgnCase(plasmaColor, plasmaTheme)) + ffStrbufAppendNS(&plasmaColorPretty, plasmaColor->length - plasmaTheme->length, &plasmaColor->chars[plasmaTheme->length]); + else + ffStrbufAppend(&plasmaColorPretty, plasmaColor); + + ffStrbufTrim(&plasmaColorPretty, ' '); + FF_STRBUF_CREATE(gtkPretty); ffGetGtkPretty(>kPretty, gtk2, gtk3, gtk4); @@ -27,9 +36,32 @@ void ffPrintTheme(FFinstance* instance) { ffPrintLogoAndKey(instance, &instance->config.themeKey, "Theme"); - if(plasma->length > 0) + if(plasmaTheme->length > 0) + { + ffStrbufWriteTo(plasmaTheme, stdout); + + if(plasmaColor->length > 0) + { + fputs(" (", stdout); + + if(plasmaColorPretty.length > 0) + ffStrbufWriteTo(&plasmaColorPretty, stdout); + else + ffStrbufWriteTo(plasmaColor, stdout); + + putchar(')'); + } + } + else if(plasmaColor->length > 0) + { + if(plasmaColorPretty.length > 0) + ffStrbufWriteTo(&plasmaColorPretty, stdout); + else + ffStrbufWriteTo(plasmaColor, stdout); + } + + if(plasmaTheme->length > 0 || plasmaColor->length > 0) { - ffStrbufWriteTo(plasma, stdout); fputs(" [Plasma]", stdout); if(gtkPretty.length > 0) @@ -40,12 +72,17 @@ void ffPrintTheme(FFinstance* instance) } else { - ffPrintFormatString(instance, &instance->config.themeKey, "Theme", &instance->config.themeFormat, 5, - (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, plasma}, + ffPrintFormatString(instance, &instance->config.themeKey, "Theme", &instance->config.themeFormat, 7, + (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, plasmaTheme}, + (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, plasmaColor}, + (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &plasmaColorPretty}, (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, gtk2}, (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, gtk3}, (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, gtk4}, (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, >kPretty} ); } + + ffStrbufDestroy(&plasmaColorPretty); + ffStrbufDestroy(>kPretty); } diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index 2bfdac0a1..1df40a4a4 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -1,6 +1,7 @@ #include "FFstrbuf.h" #include +#include #include void ffStrbufInit(FFstrbuf* strbuf) @@ -371,11 +372,6 @@ void ffStrbufSubstrBeforeFirstC(FFstrbuf* strbuf, const char c) ffStrbufSubstrBefore(strbuf, ffStrbufFirstIndexC(strbuf, c)); } -bool ffStrbufStartsWith(FFstrbuf* strbuf, FFstrbuf* start) -{ - return ffStrbufStartsWithNS(strbuf, start->length, start->chars); -} - void ffStrbufSubstrAfter(FFstrbuf* strbuf, uint32_t index) { if(index >= strbuf->length) @@ -396,22 +392,19 @@ void ffStrbufSubstrAfterLastC(FFstrbuf* strbuf, const char c) ffStrbufSubstrAfter(strbuf, index); } -static inline bool testSame(FFstrbuf* strbuf, uint32_t i, const char* str) +bool ffStrbufStartsWith(FFstrbuf* strbuf, FFstrbuf* start) { - if(i > strbuf->length) - return false; - - if(strbuf->chars[i] != str[i]) - return false; - - return true; + return ffStrbufStartsWithNS(strbuf, start->length, start->chars); } bool ffStrbufStartsWithS(FFstrbuf* strbuf, const char* start) { for(uint32_t i = 0; start[i] != '\0'; i++) { - if(!testSame(strbuf, i, start)) + if(i >= strbuf->length) + return false; + + if(strbuf->chars[i] != start[i]) return false; } return true; @@ -421,7 +414,41 @@ bool ffStrbufStartsWithNS(FFstrbuf* strbuf, uint32_t length, const char* start) { for(uint32_t i = 0; i < length; i++) { - if(!testSame(strbuf, i, start)) + if(i >= strbuf->length) + return false; + + if(strbuf->chars[i] != start[i]) + return false; + } + return true; +} + +bool ffStrbufStartsWithIgnCase(FFstrbuf* strbuf, FFstrbuf* start) +{ + return ffStrbufStartsWithNS(strbuf, start->length, start->chars); +} + +bool ffStrbufStartsWithIgnCaseS(FFstrbuf* strbuf, const char* start) +{ + for(uint32_t i = 0; start[i] != '\0'; i++) + { + if(i >= strbuf->length) + return false; + + if(tolower(strbuf->chars[i]) != tolower(start[i])) + return false; + } + return true; +} + +bool ffStrbufStartsWithIgnCaseNS(FFstrbuf* strbuf, uint32_t length, const char* start) +{ + for(uint32_t i = 0; i < length; i++) + { + if(i >= strbuf->length) + return false; + + if(tolower(strbuf->chars[i]) != tolower(start[i])) return false; } return true; diff --git a/src/util/FFstrbuf.h b/src/util/FFstrbuf.h index 2a5db79f5..b432cea08 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -81,6 +81,10 @@ bool ffStrbufStartsWith(FFstrbuf* strbuf, FFstrbuf* start); bool ffStrbufStartsWithS(FFstrbuf* strbuf, const char* start); bool ffStrbufStartsWithNS(FFstrbuf* strbuf, uint32_t length, const char* start); +bool ffStrbufStartsWithIgnCase(FFstrbuf* strbuf, FFstrbuf* start); +bool ffStrbufStartsWithIgnCaseS(FFstrbuf* strbuf, const char* start); +bool ffStrbufStartsWithIgnCaseNS(FFstrbuf* strbuf, uint32_t length, const char* start); + void ffStrbufRecalculateLength(FFstrbuf* strbuf); void ffStrbufDestroy(FFstrbuf* strbuf);