basic XFCE support

This commit is contained in:
Linus Dierheimer
2021-05-09 21:41:17 +02:00
parent 7432fc7a19
commit e89b326d57
7 changed files with 73 additions and 32 deletions
+1 -1
View File
@@ -46,7 +46,7 @@ KWin, Mutter, Muffin, Openbox, XFWM, Sway, Wayfire, Weston
### Window manager themes:
```
KWin, Mutter, Muffin, Openbox (LXDE, LXQT & without DE)
KWin, Mutter, Muffin, XFWM, Openbox (LXDE, LXQT & without DE)
```
### Terminal fonts:
+1
View File
@@ -118,6 +118,7 @@ __fastfetch_completion()
"--color-logo"
"--print-remaining-logo"
"--multithreading"
"--allow-slow-operations"
)
local FF_OPTIONS_STRING=(
+38 -10
View File
@@ -17,7 +17,8 @@ typedef enum DEHint
FF_DE_HINT_UNKNOWN = 0,
FF_DE_HINT_PLASMA,
FF_DE_HINT_GNOME,
FF_DE_HINT_CINNAMON
FF_DE_HINT_CINNAMON,
FF_DE_HINT_XFCE4
} DEHint;
typedef struct ProcData
@@ -114,7 +115,7 @@ static bool applyPrettyNameIfWM(FFWMDEResult* result, const FFstrbuf* processNam
}
else if(ffStrbufIgnCaseCompS(processName, "xfwm4") == 0)
{
ffStrbufSetS(&result->wmPrettyName, "XFWM");
ffStrbufSetS(&result->wmPrettyName, "Xfwm4");
*protocolHint = FF_PROTOCOL_HINT_X11;
}
else if(ffStrbufIgnCaseCompS(processName, "gnome-session-binary") == 0)
@@ -139,6 +140,8 @@ static bool applyDEHintIfDE(const FFstrbuf* processName, DEHint* deHint)
*deHint = FF_DE_HINT_GNOME;
else if(ffStrbufIgnCaseCompS(processName, "cinnamon") == 0)
*deHint = FF_DE_HINT_CINNAMON;
else if(ffStrbufIgnCaseCompS(processName, "xfce4-session") == 0)
*deHint = FF_DE_HINT_XFCE4;
return *deHint != FF_DE_HINT_UNKNOWN;
}
@@ -224,7 +227,30 @@ static void getCinnamon(FFWMDEResult* result)
ffStrbufRecalculateLength(&result->deVersion);
}
static inline void getDEFromHint(FFWMDEResult* result, ProcData* procData)
static void getXFCE4(FFinstance* instance, FFWMDEResult* result)
{
ffStrbufSetS(&result->deProcessName, "xfce4-session");
ffStrbufSetS(&result->dePrettyName, "Xfce4");
ffParsePropFile("/usr/share/gtk-doc/html/libxfce4ui/index.html", "<div><p class=\"releaseinfo\">Version %[^\n]", result->deVersion.chars);
ffStrbufRecalculateLength(&result->deVersion);
if(result->deVersion.length == 0 && instance->config.allowSlowOperations)
{
//This is really, really slow. Thank you, XFCE developers
ffProcessAppendStdOut(&result->deVersion, (char* const[]){
"xfce4-session",
"--version",
NULL
});
ffStrbufSubstrBeforeFirstC(&result->deVersion, '(');
ffStrbufSubstrAfterFirstC(&result->deVersion, ' ');
ffStrbufTrim(&result->deVersion, ' ');
}
}
static inline void getDEFromHint(FFinstance* instance, FFWMDEResult* result, ProcData* procData)
{
getFromProcDir(result, procData, false);
@@ -237,9 +263,11 @@ static inline void getDEFromHint(FFWMDEResult* result, ProcData* procData)
getGnome(result);
else if(procData->deHint == FF_DE_HINT_CINNAMON)
getCinnamon(result);
else if(procData->deHint == FF_DE_HINT_XFCE4)
getXFCE4(instance, result);
}
static inline void getDE(FFWMDEResult* result, ProcData* procData)
static inline void getDE(FFinstance* instance, FFWMDEResult* result, ProcData* procData)
{
// if sessionDesktop is not set or sessionDesktiop == WM, try finding DE via /proc
if(
@@ -248,7 +276,7 @@ static inline void getDE(FFWMDEResult* result, ProcData* procData)
ffStrbufIgnCaseCompS(&result->wmProcessName, result->sessionDesktop) == 0 ||
ffStrbufIgnCaseCompS(&result->wmPrettyName, result->sessionDesktop) == 0
) {
getDEFromHint(result, procData);
getDEFromHint(instance, result, procData);
return;
}
@@ -258,6 +286,8 @@ static inline void getDE(FFWMDEResult* result, ProcData* procData)
getGnome(result);
else if(strcasecmp(result->sessionDesktop, "X-Cinnamon") == 0 || strcasecmp(result->sessionDesktop, "Cinnamon") == 0)
getCinnamon(result);
else if(strcasecmp(result->sessionDesktop, "XFCE") == 0 || strcasecmp(result->sessionDesktop, "X-XFCE") == 0 || strcasecmp(result->sessionDesktop, "XFCE4") == 0 || strcasecmp(result->sessionDesktop, "X-XFCE4") == 0)
getXFCE4(instance, result);
else
{
ffStrbufSetS(&result->deProcessName, result->sessionDesktop);
@@ -304,7 +334,7 @@ static inline void getSessionType(FFWMDEResult* result, ProtocolHint protocolHin
getSessionTypeFallback(result, protocolHint);
}
static inline void getWMDE(FFWMDEResult* result)
static inline void getWMDE(FFinstance* instance, FFWMDEResult* result)
{
ProcData procData;
procData.proc = opendir("/proc");
@@ -314,7 +344,7 @@ static inline void getWMDE(FFWMDEResult* result)
getSessionDesktop(result);
getWM(result, &procData);
getDE(result, &procData);
getDE(instance, result, &procData);
if(result->wmProtocolName.length == 0 && procData.protocolHint != FF_PROTOCOL_HINT_UNKNOWN)
getSessionTypeFallback(result, procData.protocolHint);
@@ -325,8 +355,6 @@ static inline void getWMDE(FFWMDEResult* result)
const FFWMDEResult* ffDetectWMDE(FFinstance* instance)
{
UNUSED(instance);
static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
static FFWMDEResult result;
static bool init = false;
@@ -349,7 +377,7 @@ const FFWMDEResult* ffDetectWMDE(FFinstance* instance)
//Don't run anyting when on TTY. This prevents us to catch process from other users in at least that case.
if(ffStrbufIgnCaseCompS(&result.wmProtocolName, "TTY") != 0)
getWMDE(&result);
getWMDE(instance, &result);
pthread_mutex_unlock(&mutex);
+1
View File
@@ -108,6 +108,7 @@ static void defaultConfig(FFconfig* config)
config->recache = false;
config->cacheSave = true;
config->printRemainingLogo = true;
config->allowSlowOperations = false;
//Since most of these properties are unlikely to be used at once, give them minimal heap space (the \0 character)
ffStrbufInitA(&config->osFormat, 1);
+17 -15
View File
@@ -46,18 +46,19 @@ static inline void printHelp()
" --print-available-presets: list presets fastfetch knows about. They can be loaded with --load-config. (+)\n"
"\n"
"General options:\n"
" --structure <structure>: sets the structure of the fetch. Must be a colon seperated list of keys. Use --print-available-modules to show the default\n"
" --set <key=value>: hard set the value of an key\n"
" -c <color>, --color <color>: sets the color of the keys. Must be a linux console color code (+)\n"
" --spacing <width>: sets the distance between logo and text\n"
" -s <str>, --seperator <str>: sets the seperator between key and value. Default is a colon with a space\n"
" -x <offset>, --offsetx <offset>: sets the x offset. Can be negative to cut the logo, but no more than logo width.\n"
" --show-errors <?value>: print occuring errors\n"
" -r <?value> --recache <?value>: generate new cached values\n"
" --nocache <?value>: dont use cached values, but also dont overwrite existing ones\n"
" --print-remaining-logo <?value>: print the remaining logo, if it is higher than the number of lines shown\n"
" --multithreading <?value>: use multiple threads to detect values\n"
" --load-config <file>: load a config file (+)\n"
" --structure <structure>: sets the structure of the fetch. Must be a colon seperated list of keys. Use --print-available-modules to show the default\n"
" --set <key=value>: hard set the value of an key\n"
" -c <color>, --color <color>: sets the color of the keys. Must be a linux console color code (+)\n"
" --spacing <width>: sets the distance between logo and text\n"
" -s <str>, --seperator <str>: sets the seperator between key and value. Default is a colon with a space\n"
" -x <offset>, --offsetx <offset>: sets the x offset. Can be negative to cut the logo, but no more than logo width.\n"
" --show-errors <?value>: print occuring errors\n"
" -r <?value> --recache <?value>: generate new cached values\n"
" --nocache <?value>: dont use cached values, but also dont overwrite existing ones\n"
" --print-remaining-logo <?value>: print the remaining logo, if it is higher than the number of lines shown\n"
" --multithreading <?value>: use multiple threads to detect values\n"
" --load-config <file>: load a config file (+)\n"
" --allow-slow-operations <?value>: Allow operations that are usually very slow for more detailed output\n"
"\n"
"Logo options:\n"
" -l <name>, --logo <name>: sets the shown logo. Also changes the main color accordingly\n"
@@ -643,10 +644,9 @@ static void optionParseConfigFile(FFinstance* instance, FFdata* data, const char
static inline bool optionParseBoolean(const char* str)
{
if(str == NULL)
return true;
return (
str == NULL ||
*str == '\0' ||
strcasecmp(str, "true") == 0 ||
strcasecmp(str, "yes") == 0 ||
strcasecmp(str, "on") == 0 ||
@@ -778,6 +778,8 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
instance->config.printRemainingLogo = optionParseBoolean(value);
else if(strcasecmp(key, "--multithreading") == 0)
data->multithreading = optionParseBoolean(value);
else if(strcasecmp(key, "--allow-slow-operations") == 0)
instance->config.allowSlowOperations = optionParseBoolean(value);
else if(strcasecmp(key, "--structure") == 0)
optionParseString(key, value, &data->structure);
else if(strcasecmp(key, "-l") == 0 || strcasecmp(key, "--logo") == 0)
+1
View File
@@ -46,6 +46,7 @@ typedef struct FFconfig
bool recache;
bool cacheSave;
bool printRemainingLogo;
bool allowSlowOperations;
FFstrbuf osFormat;
FFstrbuf osKey;
+14 -6
View File
@@ -19,20 +19,26 @@ static void printWMTheme(FFinstance* instance, const char* theme)
}
}
static void printKWin(FFinstance* instance)
static void printWMThemeFromConfig(FFinstance* instance, const char* configFile, const char* themeRegex, const char* defaultValue)
{
char theme[256];
bool fileFound = ffParsePropFileConfig(instance, "kwinrc", "theme=%s", theme);
if(!ffParsePropFileConfig(instance, configFile, themeRegex, theme))
{
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Config file %s doesn't exist", configFile);
return;
}
if(*theme == '\0')
{
if(!fileFound)
if(defaultValue == NULL)
{
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find \"theme=\" in \".config/kwinrc\"");
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find theme in %s", configFile);
return;
}
strcpy(theme, "Breeze");
printWMTheme(instance, defaultValue);
return;
}
printWMTheme(instance, theme);
@@ -159,7 +165,9 @@ void ffPrintWMTheme(FFinstance* instance)
}
if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "KWin") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "KDE") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "Plasma") == 0)
printKWin(instance);
printWMThemeFromConfig(instance, "kwinrc", " theme=%s", "Breeze");
else if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "Xfwm4") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "Xfwm") == 0)
printWMThemeFromConfig(instance, "xfce4/xfconf/xfce-perchannel-xml/xfwm4.xml", " <property name=\"theme\" type=\"string\" value=\"%[^\"]", "Default");
else if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "Mutter") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "Gnome") == 0 || ffStrbufIgnCaseCompS(&result->wmPrettyName, "Ubuntu") == 0)
printMutter(instance);
else if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "Muffin") == 0)