From 9c26a76c9db288e04611f8275fe35969b0935b4a Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sun, 28 Mar 2021 20:36:49 +0200 Subject: [PATCH] WM is once again shown in a plasma session --- src/common.c | 8 +++++++- src/fastfetch.c | 2 +- src/fastfetch.h | 1 + src/modules/wm.c | 34 ++++++++++++++-------------------- 4 files changed, 23 insertions(+), 22 deletions(-) diff --git a/src/common.c b/src/common.c index 62cbc1919..209155d58 100644 --- a/src/common.c +++ b/src/common.c @@ -225,7 +225,7 @@ void ffPrintError(FFinstance* instance, const char* key, const char* message, .. va_end(arguments); } -void ffGetFileContent(const char* fileName, FFstrbuf* buffer) +void ffAppendFileContent(const char* fileName, FFstrbuf* buffer) { int fd = open(fileName, O_RDONLY); if(fd == -1) @@ -247,6 +247,12 @@ void ffGetFileContent(const char* fileName, FFstrbuf* buffer) close(fd); } +void ffGetFileContent(const char* fileName, FFstrbuf* buffer) +{ + ffStrbufClear(buffer); + ffAppendFileContent(fileName, buffer); +} + static const FFstrbuf* getCacheDir(FFinstance* instance) { static FFstrbuf cacheDir; diff --git a/src/fastfetch.c b/src/fastfetch.c index 096c5d2d6..cf10abbd1 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -222,7 +222,7 @@ static inline void printCommandHelp(const char* command) else if(strcasecmp(command, "de-format") == 0) constructAndPrintCommandHelpFormat("de", "{} {} ({})", 3, "DE name", "DE version", "Name of display server"); else if(strcasecmp(command, "wm-format") == 0) - constructAndPrintCommandHelpFormat("wm", "{}", 1, "WM name"); + constructAndPrintCommandHelpFormat("wm", "{2}", 2, "WM process name", "WM pretty name"); else if(strcasecmp(command, "theme-format") == 0) constructAndPrintCommandHelpFormat("theme", "{} [Plasma], {5}", 5, "Plasma theme", "GTK2 theme", "GTK3 theme", "GTK4 theme", "Combined GTK themes"); else if(strcasecmp(command, "icons-format") == 0) diff --git a/src/fastfetch.h b/src/fastfetch.h index dcd0ec319..732c5b921 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -119,6 +119,7 @@ void ffInitState(FFstate* state); void ffDefaultConfig(FFconfig* config); void ffPrintKey(FFconfig* config, const char* key); void ffPrintLogoAndKey(FFinstance* instance, const char* key); +void ffAppendFileContent(const char* fileName, FFstrbuf* buffer); void ffGetFileContent(const char* fileName, FFstrbuf* buffer); void ffParsePropFile(const char* file, const char* regex, char* buffer); void ffParsePropFileHome(FFinstance* instance, const char* relativeFile, const char* regex, char* buffer); diff --git a/src/modules/wm.c b/src/modules/wm.c index 0c9d211da..7e32b0b56 100644 --- a/src/modules/wm.c +++ b/src/modules/wm.c @@ -2,16 +2,6 @@ #include -static bool parseProcessName(FFstrbuf* name) -{ - if(ffStrbufIgnCaseCompS(name, "kwin_wayland") == 0 || ffStrbufIgnCaseCompS(name, "kwin_x11") == 0) - ffStrbufSetS(name, "KWin"); - else - return false; - - return true; -} - void ffPrintWM(FFinstance* instance) { DIR* proc = opendir("/proc/"); @@ -23,9 +13,8 @@ void ffPrintWM(FFinstance* instance) struct dirent* dirent; - FF_STRBUF_CREATE(name); - - bool found = false; + FF_STRBUF_CREATE(processName); + FF_STRBUF_CREATE(prettyName); while((dirent = readdir(proc)) != NULL) { @@ -35,9 +24,12 @@ void ffPrintWM(FFinstance* instance) char path[20]; sprintf(path, "/proc/%.8s/comm", dirent->d_name); - ffGetFileContent(path, &name); + ffGetFileContent(path, &processName); - if((found = parseProcessName(&name))) + if(ffStrbufIgnCaseCompS(&processName, "kwin_wayland") == 0 || ffStrbufIgnCaseCompS(&processName, "kwin_x11") == 0) + ffStrbufSetS(&prettyName, "KWin"); + + if(prettyName.length > 0) break; } @@ -45,21 +37,23 @@ void ffPrintWM(FFinstance* instance) if(instance->config.wmFormat.length == 0) { - if(!found) + if(prettyName.length == 0) { ffPrintError(instance, "WM", "No process name matches the name of known display managers"); return; } ffPrintLogoAndKey(instance, "WM"); - ffStrbufPutTo(&name, stdout); + ffStrbufPutTo(&prettyName, stdout); } else { - ffPrintFormatString(instance, "WM", &instance->config.wmFormat, 1, - (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &name} + ffPrintFormatString(instance, "WM", &instance->config.wmFormat, 2, + (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &processName}, + (FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &prettyName} ); } - ffStrbufDestroy(&name); + ffStrbufDestroy(&processName); + ffStrbufDestroy(&prettyName); }