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 -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");
}