2021-04-07 12:55:11 +02:00
|
|
|
#include "fastfetch.h"
|
|
|
|
|
|
2021-04-09 19:21:56 +02:00
|
|
|
#include <string.h>
|
2021-04-07 17:36:03 +02:00
|
|
|
#include <pthread.h>
|
|
|
|
|
|
2021-04-09 19:21:56 +02:00
|
|
|
typedef enum PlasmaCategory
|
|
|
|
|
{
|
|
|
|
|
PLASMA_CATEGORY_GENERAL,
|
|
|
|
|
PLASMA_CATEGORY_KDE,
|
|
|
|
|
PLASMA_CATEGORY_ICONS,
|
|
|
|
|
PLASMA_CATEGORY_OTHER
|
|
|
|
|
} PlasmaCategory;
|
|
|
|
|
|
2021-05-07 14:55:43 +02:00
|
|
|
static bool detectFromConfigFile(const FFstrbuf* filename, FFPlasmaResult* result)
|
2021-04-07 12:55:11 +02:00
|
|
|
{
|
2021-05-07 14:55:43 +02:00
|
|
|
FILE* kdeglobals = fopen(filename->chars, "r");
|
2021-04-07 12:55:11 +02:00
|
|
|
if(kdeglobals == NULL)
|
2021-05-07 14:55:43 +02:00
|
|
|
return false;
|
2021-04-07 12:55:11 +02:00
|
|
|
|
|
|
|
|
char* line = NULL;
|
|
|
|
|
size_t len = 0;
|
|
|
|
|
|
2021-04-09 19:21:56 +02:00
|
|
|
PlasmaCategory category = PLASMA_CATEGORY_OTHER;
|
|
|
|
|
|
2021-04-07 12:55:11 +02:00
|
|
|
while(getline(&line, &len, kdeglobals) != -1)
|
|
|
|
|
{
|
2021-04-09 19:21:56 +02:00
|
|
|
if(line[0] == '[')
|
|
|
|
|
{
|
|
|
|
|
char categoryName[32];
|
2022-02-12 22:30:57 +01:00
|
|
|
sscanf(line, "[%31[^]]", categoryName);
|
2021-04-09 19:21:56 +02:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-22 18:42:14 +02:00
|
|
|
if(category == PLASMA_CATEGORY_KDE && result->widgetStyle.length == 0)
|
2022-04-08 15:50:49 +02:00
|
|
|
ffParsePropLine(line, "widgetStyle =", &result->widgetStyle);
|
2021-10-22 18:42:14 +02:00
|
|
|
else if(category == PLASMA_CATEGORY_ICONS && result->icons.length == 0)
|
2022-04-08 15:50:49 +02:00
|
|
|
ffParsePropLine(line, "Theme =", &result->icons);
|
2021-05-13 12:27:44 +02:00
|
|
|
else if(category == PLASMA_CATEGORY_GENERAL)
|
2021-04-09 19:21:56 +02:00
|
|
|
{
|
2021-10-22 18:42:14 +02:00
|
|
|
if(result->colorScheme.length == 0)
|
2022-04-08 15:50:49 +02:00
|
|
|
ffParsePropLine(line, "ColorScheme =", &result->colorScheme);
|
2021-10-22 18:42:14 +02:00
|
|
|
|
2021-11-13 16:46:32 +01:00
|
|
|
if(result->font.length == 0)
|
2022-04-08 15:50:49 +02:00
|
|
|
ffParsePropLine(line, "font =", &result->font);
|
2021-11-13 16:46:32 +01:00
|
|
|
|
|
|
|
|
//Before plasma 5.23, "Font" was the key instead of "font". Since a lot of distros ship older versions, we test for both.
|
2021-10-22 18:42:14 +02:00
|
|
|
if(result->font.length == 0)
|
2022-04-08 15:50:49 +02:00
|
|
|
ffParsePropLine(line, "Font =", &result->font);
|
2021-04-09 19:21:56 +02:00
|
|
|
}
|
2021-04-07 12:55:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(line != NULL)
|
|
|
|
|
free(line);
|
|
|
|
|
|
|
|
|
|
fclose(kdeglobals);
|
2021-05-07 14:55:43 +02:00
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const FFPlasmaResult* ffDetectPlasma(FFinstance* instance)
|
|
|
|
|
{
|
|
|
|
|
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
static FFPlasmaResult result;
|
|
|
|
|
static bool init = false;
|
|
|
|
|
pthread_mutex_lock(&mutex);
|
|
|
|
|
if(init)
|
|
|
|
|
{
|
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
return &result;
|
|
|
|
|
}
|
|
|
|
|
init = true;
|
|
|
|
|
|
|
|
|
|
ffStrbufInit(&result.widgetStyle);
|
|
|
|
|
ffStrbufInit(&result.colorScheme);
|
|
|
|
|
ffStrbufInit(&result.icons);
|
|
|
|
|
ffStrbufInit(&result.font);
|
|
|
|
|
|
2022-01-02 16:55:26 +01:00
|
|
|
const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance);
|
2021-05-14 12:43:54 +02:00
|
|
|
if(ffStrbufIgnCaseCompS(&wmde->deProcessName, "plasmashell") != 0)
|
|
|
|
|
{
|
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
return &result;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-07 14:55:43 +02:00
|
|
|
bool foundAFile = false;
|
|
|
|
|
|
|
|
|
|
//We need to do this because we use multiple threads on configDirs
|
|
|
|
|
FFstrbuf baseDirCopy;
|
|
|
|
|
ffStrbufInitA(&baseDirCopy, 64);
|
|
|
|
|
|
|
|
|
|
for(uint32_t i = 0; i < instance->state.configDirs.length; i++)
|
|
|
|
|
{
|
|
|
|
|
FFstrbuf* baseDir = (FFstrbuf*) ffListGet(&instance->state.configDirs, i);
|
|
|
|
|
|
|
|
|
|
ffStrbufSet(&baseDirCopy, baseDir);
|
|
|
|
|
ffStrbufAppendS(&baseDirCopy, "/kdeglobals");
|
|
|
|
|
|
|
|
|
|
if(detectFromConfigFile(&baseDirCopy, &result))
|
|
|
|
|
foundAFile = true;
|
|
|
|
|
|
|
|
|
|
if(
|
|
|
|
|
result.widgetStyle.length > 0 &&
|
|
|
|
|
result.colorScheme.length > 0 &&
|
|
|
|
|
result.icons.length > 0 &&
|
|
|
|
|
result.font.length > 0
|
|
|
|
|
) break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ffStrbufDestroy(&baseDirCopy);
|
|
|
|
|
|
|
|
|
|
if(!foundAFile)
|
|
|
|
|
{
|
|
|
|
|
pthread_mutex_unlock(&mutex);
|
|
|
|
|
return &result;
|
|
|
|
|
}
|
2021-04-07 12:55:11 +02:00
|
|
|
|
2021-04-09 19:21:56 +02:00
|
|
|
//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)
|
2021-04-22 21:41:42 +02:00
|
|
|
if(result.widgetStyle.length == 0)
|
|
|
|
|
ffStrbufAppendS(&result.widgetStyle, "Breeze");
|
2021-04-09 19:21:56 +02:00
|
|
|
|
2021-04-22 21:41:42 +02:00
|
|
|
if(result.colorScheme.length == 0)
|
|
|
|
|
ffStrbufAppendS(&result.colorScheme, "BreezeLight");
|
2021-04-09 19:21:56 +02:00
|
|
|
|
2021-04-22 21:41:42 +02:00
|
|
|
if(result.icons.length == 0)
|
|
|
|
|
ffStrbufAppendS(&result.icons, "Breeze");
|
2021-04-09 19:21:56 +02:00
|
|
|
|
2021-04-22 21:41:42 +02:00
|
|
|
if(result.font.length == 0)
|
|
|
|
|
ffStrbufAppendS(&result.font, "Noto Sans, 10");
|
2021-04-07 17:36:03 +02:00
|
|
|
|
|
|
|
|
pthread_mutex_unlock(&mutex);
|
2021-04-22 21:41:42 +02:00
|
|
|
return &result;
|
2021-04-07 12:55:11 +02:00
|
|
|
}
|