faster plasma detection

This commit is contained in:
Linus Dierheimer
2021-04-07 12:55:11 +02:00
parent 5f23f2b027
commit ed7e186f4b
7 changed files with 101 additions and 43 deletions
+1
View File
@@ -48,6 +48,7 @@ set(SRCS
src/common.c
src/logo.c
src/util/FFstrbuf.c
src/helpers/calculatePlasma.c
src/helpers/calculateGtk.c
src/helpers/calculateTerminal.c
src/helpers/calculateWM.c
+1
View File
@@ -161,6 +161,7 @@ void ffPrintLogos(bool color);
//Helper functions
void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr);
void ffCalculateGTK2(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr);
void ffCalculateGTK4(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr);
void ffCalculateGTK3(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr);
+1 -1
View File
@@ -165,7 +165,7 @@ static void calculateGTKFromConfigDir(const char* configDir, const char* version
FFstrbuf file4;
ffStrbufInitA(&file4, 64);
ffStrbufAppendS(&file4, configDir);
ffStrbufAppendS(&file4, "gtkrc-");
ffStrbufAppendS(&file4, ".gtkrc-");
ffStrbufAppendS(&file4, version);
ffStrbufAppendS(&file4, ".0");
parseGTKConfigFile(&file4, themeNamePtr, iconsNamePtr, fontNamePtr);
+67
View File
@@ -0,0 +1,67 @@
#include "fastfetch.h"
void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr)
{
static FFstrbuf themeName;
static FFstrbuf iconsName;
static FFstrbuf fontName;
if(themeNamePtr != NULL)
*themeNamePtr = &themeName;
if(iconsNamePtr != NULL)
*iconsNamePtr = &iconsName;
if(fontNamePtr != NULL)
*fontNamePtr = &fontName;
static bool init = false;
if(init)
return;
init = true;
ffStrbufInit(&themeName);
ffStrbufInit(&iconsName);
ffStrbufInit(&fontName);
FF_STRBUF_CREATE(kdeglobalsFile);
ffStrbufAppendS(&kdeglobalsFile, instance->state.passwd->pw_dir);
ffStrbufAppendS(&kdeglobalsFile, "/.config/kdeglobals");
FILE* kdeglobals = fopen(kdeglobalsFile.chars, "r");
if(kdeglobals == NULL)
{
ffStrbufDestroy(&kdeglobalsFile);
return;
}
char* line = NULL;
size_t len = 0;
while(getline(&line, &len, kdeglobals) != -1)
{
sscanf(line, "widgetStyle=%[^\n]", themeName.chars);
sscanf(line, "widgetStyle=\"%[^\"]+", themeName.chars);
sscanf(line, "Theme=%[^\n]", iconsName.chars);
sscanf(line, "Theme=\"%[^\"]+", iconsName.chars);
sscanf(line, "font=%[^\n]", fontName.chars);
sscanf(line, "font=\"%[^\"]+", fontName.chars);
}
ffStrbufRecalculateLength(&themeName);
ffStrbufRecalculateLength(&iconsName);
ffStrbufRecalculateLength(&fontName);
if(line != NULL)
free(line);
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.
if(fontName.length == 0)
ffStrbufAppendS(&fontName, "Noto Sans, 10");
}
+9 -30
View File
@@ -4,20 +4,8 @@
void ffPrintFont(FFinstance* instance)
{
FF_STRBUF_CREATE(plasmaFile);
ffStrbufAppendS(&plasmaFile, instance->state.passwd->pw_dir);
ffStrbufAppendS(&plasmaFile, "/.config/kdeglobals");
//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.
bool plasmaFileExists = access(plasmaFile.chars, F_OK) == 0;
char plasma[256];
plasma[0] = '\0';
if(plasmaFileExists)
ffParsePropFile(plasmaFile.chars, "font=%[^\n]", plasma);
ffStrbufDestroy(&plasmaFile);
FFstrbuf* plasma;
ffCalculatePlasma(instance, NULL, NULL, &plasma);
FFstrbuf* gtk2;
ffCalculateGTK2(instance, NULL, NULL, &gtk2);
@@ -28,28 +16,17 @@ void ffPrintFont(FFinstance* instance)
FFstrbuf* gtk4;
ffCalculateGTK4(instance, NULL, NULL, &gtk4);
if(plasma[0] == '\0' && !plasmaFileExists && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
if(plasma->length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
{
ffPrintError(instance, &instance->config.fontKey, "Font", "No fonts found");
return;
}
FF_STRBUF_CREATE(plasmaName);
FF_STRBUF_CREATE(plasmaPretty);
double plasmaSize;
if(plasma[0] == '\0' && plasmaFileExists)
{
strcpy(plasma, "Noto Sans, 10");
ffStrbufSetS(&plasmaName, "Noto Sans");
plasmaSize = 10;
ffStrbufSetS(&plasmaPretty, "Noto Sans (10pt)");
}
else
{
ffParseFont(plasma, &plasmaName, &plasmaSize);
ffFontPretty(&plasmaPretty, &plasmaName, plasmaSize);
}
ffParseFont(plasma->chars, &plasmaName, &plasmaSize);
FF_STRBUF_CREATE(plasmaPretty);
ffFontPretty(&plasmaPretty, &plasmaName, plasmaSize);
FF_STRBUF_CREATE(gtk2Name);
double gtk2Size;
@@ -76,7 +53,7 @@ void ffPrintFont(FFinstance* instance)
{
ffPrintLogoAndKey(instance, &instance->config.fontKey, "Font");
if(plasma[0] != '\0')
if(plasma->length > 0)
{
ffStrbufWriteTo(&plasmaPretty, stdout);
fputs(" [Plasma]", stdout);
@@ -120,4 +97,6 @@ void ffPrintFont(FFinstance* instance)
ffStrbufDestroy(&gtk3Name);
ffStrbufDestroy(&gtk3Pretty);
ffStrbufDestroy(&gtkPretty);
}
+11 -7
View File
@@ -2,8 +2,8 @@
void ffPrintIcons(FFinstance* instance)
{
char plasma[256];
ffParsePropFileHome(instance, ".config/kdeglobals", "Theme=%[^\n]", plasma);
FFstrbuf* plasma;
ffCalculatePlasma(instance, NULL, &plasma, NULL);
FFstrbuf* gtk2;
ffCalculateGTK2(instance, NULL, &gtk2, NULL);
@@ -14,7 +14,7 @@ void ffPrintIcons(FFinstance* instance)
FFstrbuf* gtk4;
ffCalculateGTK4(instance, NULL, &gtk4, NULL);
if(plasma[0] == '\0' && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
if(plasma->length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
{
ffPrintError(instance, &instance->config.iconsKey, "Icons", "No icons found");
return;
@@ -27,10 +27,14 @@ void ffPrintIcons(FFinstance* instance)
{
ffPrintLogoAndKey(instance, &instance->config.iconsKey, "Icons");
if(plasma[0] == '\0')
printf("Breeze [Plasma], ");
else
printf("%s [Plasma], ", plasma);
if(plasma->length > 0)
{
ffStrbufWriteTo(plasma, stdout);
fputs(" [Plasma]", stdout);
if(gtkPretty.length > 0)
fputs(", ", stdout);
}
ffStrbufPutTo(&gtkPretty, stdout);
}
+11 -5
View File
@@ -2,8 +2,8 @@
void ffPrintTheme(FFinstance* instance)
{
char plasma[256];
ffParsePropFileHome(instance, ".config/kdeglobals", "Name=%[^\n]", plasma);
FFstrbuf* plasma;
ffCalculatePlasma(instance, &plasma, NULL, NULL);
FFstrbuf* gtk2;
ffCalculateGTK2(instance, &gtk2, NULL, NULL);
@@ -14,7 +14,7 @@ void ffPrintTheme(FFinstance* instance)
FFstrbuf* gtk4;
ffCalculateGTK4(instance, &gtk4, NULL, NULL);
if(plasma[0] == '\0' && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
if(plasma->length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0)
{
ffPrintError(instance, &instance->config.themeKey, "Theme", "No themes found");
return;
@@ -27,8 +27,14 @@ void ffPrintTheme(FFinstance* instance)
{
ffPrintLogoAndKey(instance, &instance->config.themeKey, "Theme");
if(plasma[0] != '\0')
printf("%s [Plasma], ", plasma);
if(plasma->length > 0)
{
ffStrbufWriteTo(plasma, stdout);
fputs(" [Plasma]", stdout);
if(gtkPretty.length > 0)
fputs(", ", stdout);
}
ffStrbufPutTo(&gtkPretty, stdout);
}