mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-11-08 06:00:08 +01:00
global results are now stored in state
This commit is contained in:
+70
-91
@@ -4,28 +4,34 @@
|
||||
#include <pthread.h>
|
||||
#include <dconf/client/dconf-client.h>
|
||||
|
||||
static inline bool allPropertiesSet(FFstrbuf* themeNamePtr, FFstrbuf* iconsNamePtr, FFstrbuf* fontNamePtr)
|
||||
static inline bool allPropertiesSet(FFgtkval* gtkval)
|
||||
{
|
||||
return
|
||||
themeNamePtr->length > 0 &&
|
||||
iconsNamePtr->length > 0 &&
|
||||
fontNamePtr->length > 0;
|
||||
gtkval->theme.length > 0 &&
|
||||
gtkval->icons.length > 0 &&
|
||||
gtkval->font.length > 0;
|
||||
}
|
||||
|
||||
|
||||
static inline void applyGTKDConfSettings(const gchar* themeName, FFstrbuf* themeNamePtr, const gchar* iconsName, FFstrbuf* iconsNamePtr, const gchar* fontName, FFstrbuf* fontNamePtr)
|
||||
static inline void initGtkval(FFgtkval* gtkval)
|
||||
{
|
||||
if(themeNamePtr->length == 0)
|
||||
ffStrbufAppendS(themeNamePtr, themeName);
|
||||
|
||||
if(iconsNamePtr->length == 0)
|
||||
ffStrbufAppendS(iconsNamePtr, iconsName);
|
||||
|
||||
if(fontNamePtr->length == 0)
|
||||
ffStrbufAppendS(fontNamePtr, fontName);
|
||||
ffStrbufInit(>kval->theme);
|
||||
ffStrbufInit(>kval->icons);
|
||||
ffStrbufInit(>kval->font);
|
||||
}
|
||||
|
||||
static void parseGTKDConfSettings(FFinstance* instance, FFstrbuf* themeNamePtr, FFstrbuf* iconsNamePtr, FFstrbuf* fontNamePtr)
|
||||
static inline void applyGTKDConfSettings(FFgtkval* gtkval, const gchar* themeName, const gchar* iconsName, const gchar* fontName)
|
||||
{
|
||||
if(gtkval->theme.length == 0)
|
||||
ffStrbufAppendS(>kval->theme, themeName);
|
||||
|
||||
if(gtkval->icons.length == 0)
|
||||
ffStrbufAppendS(>kval->icons, iconsName);
|
||||
|
||||
if(gtkval->font.length == 0)
|
||||
ffStrbufAppendS(>kval->font, fontName);
|
||||
}
|
||||
|
||||
static void parseGTKDConfSettings(FFinstance* instance, FFgtkval* gtkval)
|
||||
{
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
@@ -39,7 +45,7 @@ static void parseGTKDConfSettings(FFinstance* instance, FFstrbuf* themeNamePtr,
|
||||
|
||||
if(init)
|
||||
{
|
||||
applyGTKDConfSettings(themeName, themeNamePtr, iconsName, iconsNamePtr, fontName, fontNamePtr);
|
||||
applyGTKDConfSettings(gtkval, themeName, iconsName, fontName);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return;
|
||||
}
|
||||
@@ -96,11 +102,11 @@ static void parseGTKDConfSettings(FFinstance* instance, FFstrbuf* themeNamePtr,
|
||||
|
||||
dlclose(dconf);
|
||||
|
||||
applyGTKDConfSettings(themeName, themeNamePtr, iconsName, iconsNamePtr, fontName, fontNamePtr);
|
||||
applyGTKDConfSettings(gtkval, themeName, iconsName, fontName);
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
static void parseGTKConfigFile(FFstrbuf* fileName, FFstrbuf* themeNamePtr, FFstrbuf* iconsNamePtr, FFstrbuf* fontNamePtr)
|
||||
static void parseGTKConfigFile(FFstrbuf* fileName, FFgtkval* gtkval)
|
||||
{
|
||||
FILE* file = fopen(fileName->chars, "r");
|
||||
if(file == NULL)
|
||||
@@ -111,22 +117,22 @@ static void parseGTKConfigFile(FFstrbuf* fileName, FFstrbuf* themeNamePtr, FFstr
|
||||
|
||||
while(getline(&line, &len, file) != -1)
|
||||
{
|
||||
if(themeNamePtr->length == 0)
|
||||
if(gtkval->theme.length == 0)
|
||||
{
|
||||
sscanf(line, "gtk-theme-name=%[^\n]", themeNamePtr->chars);
|
||||
sscanf(line, "gtk-theme-name=\"%[^\"]+", themeNamePtr->chars);
|
||||
sscanf(line, "gtk-theme-name=%[^\n]", gtkval->theme.chars);
|
||||
sscanf(line, "gtk-theme-name=\"%[^\"]+", gtkval->theme.chars);
|
||||
}
|
||||
|
||||
if(iconsNamePtr->length == 0)
|
||||
if(gtkval->icons.length == 0)
|
||||
{
|
||||
sscanf(line, "gtk-icon-theme-name=%[^\n]", iconsNamePtr->chars);
|
||||
sscanf(line, "gtk-icon-theme-name=\"%[^\"]+", iconsNamePtr->chars);
|
||||
sscanf(line, "gtk-icon-theme-name=%[^\n]", gtkval->icons.chars);
|
||||
sscanf(line, "gtk-icon-theme-name=\"%[^\"]+", gtkval->icons.chars);
|
||||
}
|
||||
|
||||
if(fontNamePtr->length == 0)
|
||||
if(gtkval->font.length == 0)
|
||||
{
|
||||
sscanf(line, "gtk-font-name=%[^\n]", fontNamePtr->chars);
|
||||
sscanf(line, "gtk-font-name=\"%[^\"]+", fontNamePtr->chars);
|
||||
sscanf(line, "gtk-font-name=%[^\n]", gtkval->font.chars);
|
||||
sscanf(line, "gtk-font-name=\"%[^\"]+", gtkval->font.chars);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,61 +141,61 @@ static void parseGTKConfigFile(FFstrbuf* fileName, FFstrbuf* themeNamePtr, FFstr
|
||||
|
||||
fclose(file);
|
||||
|
||||
ffStrbufRecalculateLength(themeNamePtr);
|
||||
ffStrbufRecalculateLength(iconsNamePtr);
|
||||
ffStrbufRecalculateLength(fontNamePtr);
|
||||
ffStrbufRecalculateLength(>kval->theme);
|
||||
ffStrbufRecalculateLength(>kval->icons);
|
||||
ffStrbufRecalculateLength(>kval->font);
|
||||
}
|
||||
|
||||
static void calculateGTKFromConfigDir(const char* configDir, const char* version, FFstrbuf* themeNamePtr, FFstrbuf* iconsNamePtr, FFstrbuf* fontNamePtr)
|
||||
static void calculateGTKFromConfigDir(const char* configDir, const char* version, FFgtkval* gtkval)
|
||||
{
|
||||
// <configdir>/gtk-<version>.0/settings.ini
|
||||
FFstrbuf file1;
|
||||
ffStrbufInitA(&file1, 64);
|
||||
ffStrbufAppendS(&file1, configDir);
|
||||
ffStrbufAppendS(&file1, "gtk-");
|
||||
ffStrbufAppendS(&file1, "/gtk-");
|
||||
ffStrbufAppendS(&file1, version);
|
||||
ffStrbufAppendS(&file1, ".0/settings.ini");
|
||||
parseGTKConfigFile(&file1, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
parseGTKConfigFile(&file1, gtkval);
|
||||
ffStrbufDestroy(&file1);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
if(allPropertiesSet(gtkval))
|
||||
return;
|
||||
|
||||
// <configdir>/gtk-<version>.0/gtkrc
|
||||
FFstrbuf file2;
|
||||
ffStrbufInitA(&file2, 64);
|
||||
ffStrbufAppendS(&file2, configDir);
|
||||
ffStrbufAppendS(&file2, "gtk-");
|
||||
ffStrbufAppendS(&file2, "/gtk-");
|
||||
ffStrbufAppendS(&file2, version);
|
||||
ffStrbufAppendS(&file2, ".0/gtkrc");
|
||||
parseGTKConfigFile(&file2, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
parseGTKConfigFile(&file2, gtkval);
|
||||
ffStrbufDestroy(&file2);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
if(allPropertiesSet(gtkval))
|
||||
return;
|
||||
|
||||
// <configdir>/gtkrc-<version>.0
|
||||
FFstrbuf file3;
|
||||
ffStrbufInitA(&file3, 64);
|
||||
ffStrbufAppendS(&file3, configDir);
|
||||
ffStrbufAppendS(&file3, "gtkrc-");
|
||||
ffStrbufAppendS(&file3, "/gtkrc-");
|
||||
ffStrbufAppendS(&file3, version);
|
||||
ffStrbufAppendS(&file3, ".0");
|
||||
parseGTKConfigFile(&file3, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
parseGTKConfigFile(&file3, gtkval);
|
||||
ffStrbufDestroy(&file3);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
if(allPropertiesSet(gtkval))
|
||||
return;
|
||||
|
||||
// <configdir>/.gtkrc-<version>.0
|
||||
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);
|
||||
parseGTKConfigFile(&file4, gtkval);
|
||||
ffStrbufDestroy(&file4);
|
||||
}
|
||||
|
||||
static void calculateGTK(FFinstance* instance, const char* version, FFstrbuf* themeNamePtr, FFstrbuf* iconsNamePtr, FFstrbuf* fontNamePtr)
|
||||
static void calculateGTK(FFinstance* instance, const char* version, FFgtkval* gtkval)
|
||||
{
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
@@ -198,18 +204,19 @@ static void calculateGTK(FFinstance* instance, const char* version, FFstrbuf* th
|
||||
static bool xdgIsDifferent;
|
||||
static bool init = false;
|
||||
|
||||
initGtkval(gtkval);
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
if(!init)
|
||||
{
|
||||
ffStrbufInitA(&configDir, 64);
|
||||
ffStrbufAppendS(&configDir, instance->state.passwd->pw_dir);
|
||||
ffStrbufAppendS(&configDir, "/.config/");
|
||||
ffStrbufAppendS(&configDir, "/.config");
|
||||
|
||||
ffStrbufInitA(&xdgConfigDir, 64);
|
||||
ffStrbufAppendS(&xdgConfigDir, getenv("XDG_CONFIG_HOME"));
|
||||
if(xdgConfigDir.length > 0 && xdgConfigDir.chars[xdgConfigDir.length - 1] != '/')
|
||||
ffStrbufAppendC(&xdgConfigDir, '/');
|
||||
ffStrbufTrimRight(&xdgConfigDir, '/');
|
||||
|
||||
xdgIsDifferent = ffStrbufComp(&configDir, &xdgConfigDir) != 0;
|
||||
|
||||
@@ -220,81 +227,53 @@ static void calculateGTK(FFinstance* instance, const char* version, FFstrbuf* th
|
||||
|
||||
if(xdgIsDifferent)
|
||||
{
|
||||
calculateGTKFromConfigDir(xdgConfigDir.chars, version, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
// $XDG_CONFIG_HOME
|
||||
calculateGTKFromConfigDir(xdgConfigDir.chars, version, gtkval);
|
||||
if(allPropertiesSet(gtkval))
|
||||
return;
|
||||
}
|
||||
|
||||
calculateGTKFromConfigDir(configDir.chars, version, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
// /home/<user>/.config
|
||||
calculateGTKFromConfigDir(configDir.chars, version, gtkval);
|
||||
if(allPropertiesSet(gtkval))
|
||||
return;
|
||||
|
||||
// <homedir>/gtkrc-<version>.0
|
||||
FFstrbuf homeConfig1;
|
||||
ffStrbufInitA(&homeConfig1, 64);
|
||||
ffStrbufAppendS(&homeConfig1, instance->state.passwd->pw_dir);
|
||||
ffStrbufAppendS(&homeConfig1, "/gtkrc-");
|
||||
ffStrbufAppendS(&homeConfig1, version);
|
||||
ffStrbufAppendS(&homeConfig1, ".0");
|
||||
parseGTKConfigFile(&homeConfig1, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
ffStrbufDestroy(&homeConfig1);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
// /home/<user>
|
||||
calculateGTKFromConfigDir(instance->state.passwd->pw_dir, version, gtkval);
|
||||
if(allPropertiesSet(gtkval))
|
||||
return;
|
||||
|
||||
// <homedir>/.gtkrc-<version>.0
|
||||
FFstrbuf homeConfig2;
|
||||
ffStrbufInitA(&homeConfig2, 64);
|
||||
ffStrbufAppendS(&homeConfig2, instance->state.passwd->pw_dir);
|
||||
ffStrbufAppendS(&homeConfig2, "/.gtkrc-");
|
||||
ffStrbufAppendS(&homeConfig2, version);
|
||||
ffStrbufAppendS(&homeConfig2, ".0");
|
||||
parseGTKConfigFile(&homeConfig2, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
ffStrbufDestroy(&homeConfig2);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
return;
|
||||
|
||||
parseGTKDConfSettings(instance, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
if(allPropertiesSet(themeNamePtr, iconsNamePtr, fontNamePtr))
|
||||
parseGTKDConfSettings(instance, gtkval);
|
||||
if(allPropertiesSet(gtkval))
|
||||
return;
|
||||
|
||||
calculateGTKFromConfigDir("/etc/", version, themeNamePtr, iconsNamePtr, fontNamePtr);
|
||||
// /etc
|
||||
calculateGTKFromConfigDir("/etc/", version, gtkval);
|
||||
}
|
||||
|
||||
#define FF_CALCULATE_GTK_IMPL(version) \
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; \
|
||||
static FFstrbuf themeName; \
|
||||
static FFstrbuf iconsName; \
|
||||
static FFstrbuf fontName; \
|
||||
static bool init = false; \
|
||||
if(themeNamePtr != NULL) \
|
||||
*themeNamePtr = &themeName; \
|
||||
if(iconsNamePtr != NULL) \
|
||||
*iconsNamePtr = &iconsName; \
|
||||
if(fontNamePtr != NULL) \
|
||||
*fontNamePtr = &fontName; \
|
||||
pthread_mutex_lock(&mutex); \
|
||||
if(init){ \
|
||||
pthread_mutex_unlock(&mutex);\
|
||||
return; \
|
||||
} \
|
||||
init = true; \
|
||||
ffStrbufInit(&themeName); \
|
||||
ffStrbufInit(&iconsName); \
|
||||
ffStrbufInit(&fontName); \
|
||||
calculateGTK(instance, #version, &themeName, &iconsName, &fontName); \
|
||||
calculateGTK(instance, #version, &instance->state.gtk##version); \
|
||||
pthread_mutex_unlock(&mutex);
|
||||
|
||||
void ffCalculateGTK2(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr)
|
||||
void ffCalculateGTK2(FFinstance* instance)
|
||||
{
|
||||
FF_CALCULATE_GTK_IMPL(2)
|
||||
}
|
||||
|
||||
void ffCalculateGTK3(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr)
|
||||
void ffCalculateGTK3(FFinstance* instance)
|
||||
{
|
||||
FF_CALCULATE_GTK_IMPL(3)
|
||||
}
|
||||
|
||||
void ffCalculateGTK4(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr)
|
||||
void ffCalculateGTK4(FFinstance* instance)
|
||||
{
|
||||
FF_CALCULATE_GTK_IMPL(4)
|
||||
}
|
||||
|
||||
@@ -11,28 +11,11 @@ typedef enum PlasmaCategory
|
||||
PLASMA_CATEGORY_OTHER
|
||||
} PlasmaCategory;
|
||||
|
||||
void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf** colorNamePtr, FFstrbuf** iconsNamePtr, FFstrbuf** fontNamePtr)
|
||||
void ffCalculatePlasma(FFinstance* instance)
|
||||
{
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static FFstrbuf themeName;
|
||||
static FFstrbuf colorName;
|
||||
static FFstrbuf iconsName;
|
||||
static FFstrbuf fontName;
|
||||
static bool init = false;
|
||||
|
||||
if(themeNamePtr != NULL)
|
||||
*themeNamePtr = &themeName;
|
||||
|
||||
if(colorNamePtr != NULL)
|
||||
*colorNamePtr = &colorName;
|
||||
|
||||
if(iconsNamePtr != NULL)
|
||||
*iconsNamePtr = &iconsName;
|
||||
|
||||
if(fontNamePtr != NULL)
|
||||
*fontNamePtr = &fontName;
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
if(init)
|
||||
@@ -43,10 +26,10 @@ void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf**
|
||||
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&themeName);
|
||||
ffStrbufInit(&colorName);
|
||||
ffStrbufInit(&iconsName);
|
||||
ffStrbufInit(&fontName);
|
||||
ffStrbufInit(&instance->state.plasma.widgetStyle);
|
||||
ffStrbufInit(&instance->state.plasma.colorScheme);
|
||||
ffStrbufInit(&instance->state.plasma.icons);
|
||||
ffStrbufInit(&instance->state.plasma.font);
|
||||
|
||||
FF_STRBUF_CREATE(kdeglobalsFile);
|
||||
ffStrbufAppendS(&kdeglobalsFile, instance->state.passwd->pw_dir);
|
||||
@@ -86,28 +69,28 @@ void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf**
|
||||
|
||||
if(category == PLASMA_CATEGORY_KDE)
|
||||
{
|
||||
sscanf(line, "widgetStyle=%[^\n]", themeName.chars);
|
||||
sscanf(line, "widgetStyle=\"%[^\"]+", themeName.chars);
|
||||
sscanf(line, "widgetStyle=%[^\n]", instance->state.plasma.widgetStyle.chars);
|
||||
sscanf(line, "widgetStyle=\"%[^\"]+", instance->state.plasma.widgetStyle.chars);
|
||||
}
|
||||
else if(category == PLASMA_CATEGORY_GENERAL)
|
||||
{
|
||||
sscanf(line, "ColorScheme=%[^\n]", colorName.chars);
|
||||
sscanf(line, "ColorScheme=\"%[^\"]+", colorName.chars);
|
||||
sscanf(line, "ColorScheme=%[^\n]", instance->state.plasma.colorScheme.chars);
|
||||
sscanf(line, "ColorScheme=\"%[^\"]+", instance->state.plasma.colorScheme.chars);
|
||||
|
||||
sscanf(line, "font=%[^\n]", fontName.chars);
|
||||
sscanf(line, "font=\"%[^\"]+", fontName.chars);
|
||||
sscanf(line, "font=%[^\n]", instance->state.plasma.font.chars);
|
||||
sscanf(line, "font=\"%[^\"]+", instance->state.plasma.font.chars);
|
||||
}
|
||||
else if(category == PLASMA_CATEGORY_ICONS)
|
||||
{
|
||||
sscanf(line, "Theme=%[^\n]", iconsName.chars);
|
||||
sscanf(line, "Theme=\"%[^\"]+", iconsName.chars);
|
||||
sscanf(line, "Theme=%[^\n]", instance->state.plasma.icons.chars);
|
||||
sscanf(line, "Theme=\"%[^\"]+", instance->state.plasma.icons.chars);
|
||||
}
|
||||
}
|
||||
|
||||
ffStrbufRecalculateLength(&themeName);
|
||||
ffStrbufRecalculateLength(&colorName);
|
||||
ffStrbufRecalculateLength(&iconsName);
|
||||
ffStrbufRecalculateLength(&fontName);
|
||||
ffStrbufRecalculateLength(&instance->state.plasma.widgetStyle);
|
||||
ffStrbufRecalculateLength(&instance->state.plasma.colorScheme);
|
||||
ffStrbufRecalculateLength(&instance->state.plasma.icons);
|
||||
ffStrbufRecalculateLength(&instance->state.plasma.font);
|
||||
|
||||
if(line != NULL)
|
||||
free(line);
|
||||
@@ -117,17 +100,17 @@ void ffCalculatePlasma(FFinstance* instance, FFstrbuf** themeNamePtr, FFstrbuf**
|
||||
|
||||
//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(instance->state.plasma.widgetStyle.length == 0)
|
||||
ffStrbufAppendS(&instance->state.plasma.widgetStyle, "Breeze");
|
||||
|
||||
if(colorName.length == 0)
|
||||
ffStrbufAppendS(&colorName, "BreezeLight");
|
||||
if(instance->state.plasma.colorScheme.length == 0)
|
||||
ffStrbufAppendS(&instance->state.plasma.colorScheme, "BreezeLight");
|
||||
|
||||
if(iconsName.length == 0)
|
||||
ffStrbufAppendS(&iconsName, "Breeze");
|
||||
if(instance->state.plasma.icons.length == 0)
|
||||
ffStrbufAppendS(&instance->state.plasma.icons, "Breeze");
|
||||
|
||||
if(fontName.length == 0)
|
||||
ffStrbufAppendS(&fontName, "Noto Sans, 10");
|
||||
if(instance->state.plasma.font.length == 0)
|
||||
ffStrbufAppendS(&instance->state.plasma.font, "Noto Sans, 10");
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <unistd.h>
|
||||
#include <pthread.h>
|
||||
|
||||
static void getTerminalName(FFinstance* instance, const char* pid, FFstrbuf* exeName, FFstrbuf* processName, FFstrbuf* error)
|
||||
static void getTerminalName(FFinstance* instance, const char* pid)
|
||||
{
|
||||
char statFile[234];
|
||||
sprintf(statFile, "/proc/%s/stat", pid);
|
||||
@@ -12,7 +12,7 @@ static void getTerminalName(FFinstance* instance, const char* pid, FFstrbuf* exe
|
||||
FILE* stat = fopen(statFile, "r");
|
||||
if(stat == NULL)
|
||||
{
|
||||
ffStrbufSetF(error, "fopen(\"%s\", \"r\") == NULL", statFile);
|
||||
ffStrbufSetF(&instance->state.terminal.error, "fopen(\"%s\", \"r\") == NULL", statFile);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ static void getTerminalName(FFinstance* instance, const char* pid, FFstrbuf* exe
|
||||
char ppid[256];
|
||||
if(fscanf(stat, "%*s (%[^)])%*s%s", name, ppid) != 2)
|
||||
{
|
||||
ffStrbufSetS(error, "fscanf(stat, \"%*s (%[^)])%*s%s\", name, ppid) != 2");
|
||||
ffStrbufSetS(&instance->state.terminal.error, "fscanf(stat, \"%*s (%[^)])%*s%s\", name, ppid) != 2");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -37,38 +37,25 @@ static void getTerminalName(FFinstance* instance, const char* pid, FFstrbuf* exe
|
||||
strcasecmp(name, "doas") == 0 ||
|
||||
strcasecmp(name, "strace") == 0 )
|
||||
{
|
||||
getTerminalName(instance, ppid, exeName, processName, error);
|
||||
getTerminalName(instance, ppid);
|
||||
return;
|
||||
}
|
||||
|
||||
char cmdlineFile[234];
|
||||
sprintf(cmdlineFile, "/proc/%s/cmdline", pid);
|
||||
|
||||
ffGetFileContent(cmdlineFile, exeName);
|
||||
ffStrbufSubstrBeforeFirstC(exeName, '\0');
|
||||
ffStrbufSubstrAfterLastC(exeName, '/');
|
||||
ffGetFileContent(cmdlineFile, &instance->state.terminal.exeName);
|
||||
ffStrbufSubstrBeforeFirstC(&instance->state.terminal.exeName, '\0');
|
||||
ffStrbufSubstrAfterLastC(&instance->state.terminal.exeName, '/');
|
||||
|
||||
ffStrbufSetS(processName, name);
|
||||
ffStrbufSetS(&instance->state.terminal.processName, name);
|
||||
}
|
||||
|
||||
void ffCalculateTerminal(FFinstance* instance, FFstrbuf** exeNamePtr, FFstrbuf** processNamePtr, FFstrbuf** errorPtr)
|
||||
void ffCalculateTerminal(FFinstance* instance)
|
||||
{
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static FFstrbuf exeName;
|
||||
static FFstrbuf processName;
|
||||
static FFstrbuf error;
|
||||
static bool init = false;
|
||||
|
||||
if(exeNamePtr != NULL)
|
||||
*exeNamePtr = &exeName;
|
||||
|
||||
if(processNamePtr != NULL)
|
||||
*processNamePtr = &processName;
|
||||
|
||||
if(errorPtr != NULL)
|
||||
*errorPtr = &error;
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
if(init)
|
||||
@@ -78,14 +65,14 @@ void ffCalculateTerminal(FFinstance* instance, FFstrbuf** exeNamePtr, FFstrbuf**
|
||||
}
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&exeName);
|
||||
ffStrbufInit(&processName);
|
||||
ffStrbufInit(&error);
|
||||
ffStrbufInit(&instance->state.terminal.exeName);
|
||||
ffStrbufInit(&instance->state.terminal.processName);
|
||||
ffStrbufInit(&instance->state.terminal.error);
|
||||
|
||||
char ppid[256];
|
||||
sprintf(ppid, "%i", getppid());
|
||||
|
||||
getTerminalName(instance, ppid, &exeName, &processName, &error);
|
||||
getTerminalName(instance, ppid);
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
+14
-26
@@ -3,26 +3,11 @@
|
||||
#include <dirent.h>
|
||||
#include <pthread.h>
|
||||
|
||||
void ffCalculateWM(FFinstance* instance, FFstrbuf** prettyNamePtr, FFstrbuf** processNamePtr, FFstrbuf** errorPtr)
|
||||
void ffCalculateWM(FFinstance* instance)
|
||||
{
|
||||
UNUSED(instance);
|
||||
|
||||
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
static FFstrbuf prettyName;
|
||||
static FFstrbuf processName;
|
||||
static FFstrbuf error;
|
||||
static bool init = false;
|
||||
|
||||
if(prettyNamePtr != NULL)
|
||||
*prettyNamePtr = &prettyName;
|
||||
|
||||
if(processNamePtr != NULL)
|
||||
*processNamePtr = &processName;
|
||||
|
||||
if(errorPtr != NULL)
|
||||
*errorPtr = &error;
|
||||
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
if(init)
|
||||
@@ -33,14 +18,14 @@ void ffCalculateWM(FFinstance* instance, FFstrbuf** prettyNamePtr, FFstrbuf** pr
|
||||
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&prettyName);
|
||||
ffStrbufInit(&processName);
|
||||
ffStrbufInit(&error);
|
||||
ffStrbufInit(&instance->state.wm.processName);
|
||||
ffStrbufInit(&instance->state.wm.prettyName);
|
||||
ffStrbufInit(&instance->state.wm.error);
|
||||
|
||||
DIR* proc = opendir("/proc/");
|
||||
if(proc == NULL)
|
||||
{
|
||||
ffStrbufSetS(&error, "opendir(\"/proc/\") == NULL");
|
||||
ffStrbufSetS(&instance->state.wm.error, "opendir(\"/proc/\") == NULL");
|
||||
pthread_mutex_unlock(&mutex);
|
||||
return;
|
||||
}
|
||||
@@ -55,19 +40,22 @@ void ffCalculateWM(FFinstance* instance, FFstrbuf** prettyNamePtr, FFstrbuf** pr
|
||||
char path[20];
|
||||
sprintf(path, "/proc/%.8s/comm", dirent->d_name);
|
||||
|
||||
ffGetFileContent(path, &processName);
|
||||
ffGetFileContent(path, &instance->state.wm.processName);
|
||||
|
||||
if(ffStrbufIgnCaseCompS(&processName, "kwin_wayland") == 0 || ffStrbufIgnCaseCompS(&processName, "kwin_x11") == 0)
|
||||
ffStrbufSetS(&prettyName, "KWin");
|
||||
if(ffStrbufIgnCaseCompS(&instance->state.wm.processName, "kwin_wayland") == 0 || ffStrbufIgnCaseCompS(&instance->state.wm.processName, "kwin_x11") == 0)
|
||||
ffStrbufSetS(&instance->state.wm.prettyName, "KWin");
|
||||
|
||||
if(prettyName.length > 0)
|
||||
if(instance->state.wm.prettyName.length > 0)
|
||||
break;
|
||||
}
|
||||
|
||||
closedir(proc);
|
||||
|
||||
if(prettyName.length == 0)
|
||||
ffStrbufSetS(&error, "No process name matches the name of known display managers");
|
||||
if(instance->state.wm.prettyName.length == 0)
|
||||
{
|
||||
ffStrbufSetS(&instance->state.wm.error, "No process name matches the name of known display managers");
|
||||
ffStrbufClear(&instance->state.wm.processName);
|
||||
}
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
}
|
||||
|
||||
@@ -83,6 +83,14 @@ void ffInitInstance(FFinstance* instance)
|
||||
ffCacheValidate(instance);
|
||||
}
|
||||
|
||||
void ffCalculatePlasmaAndGtk(FFinstance* instance)
|
||||
{
|
||||
ffCalculatePlasma(instance);
|
||||
ffCalculateGTK2(instance);
|
||||
ffCalculateGTK3(instance);
|
||||
ffCalculateGTK3(instance);
|
||||
}
|
||||
|
||||
static void ffCleanup(FFinstance* instance)
|
||||
{
|
||||
UNUSED(instance);
|
||||
|
||||
@@ -4,37 +4,37 @@
|
||||
|
||||
static inline void* calculatePlasmaThreadMain(void* instance)
|
||||
{
|
||||
ffCalculatePlasma((FFinstance*)instance, NULL, NULL, NULL, NULL);
|
||||
ffCalculatePlasma((FFinstance*)instance);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline void* calculateGTK2ThreadMain(void* instance)
|
||||
{
|
||||
ffCalculateGTK2((FFinstance*)instance, NULL, NULL, NULL);
|
||||
ffCalculateGTK2((FFinstance*)instance);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline void* calculateGTK3ThreadMain(void* instance)
|
||||
{
|
||||
ffCalculateGTK3((FFinstance*)instance, NULL, NULL, NULL);
|
||||
ffCalculateGTK3((FFinstance*)instance);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline void* calculateGTK4ThreadMain(void* instance)
|
||||
{
|
||||
ffCalculateGTK4((FFinstance*)instance, NULL, NULL, NULL);
|
||||
ffCalculateGTK4((FFinstance*)instance);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline void* calculateWMThreadMain(void* instance)
|
||||
{
|
||||
ffCalculateWM((FFinstance*)instance, NULL, NULL, NULL);
|
||||
ffCalculateWM((FFinstance*)instance);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static inline void* calculateTerminalThreadMain(void* instance)
|
||||
{
|
||||
ffCalculateTerminal((FFinstance*)instance, NULL, NULL, NULL);
|
||||
ffCalculateTerminal((FFinstance*)instance);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user