Files
fastfetch/src/modules/wm.c
T

71 lines
1.5 KiB
C
Raw Normal View History

2021-03-05 21:38:35 +01:00
#include "fastfetch.h"
#include <dirent.h>
2021-03-19 20:57:07 +01:00
static bool parseProcessName(FFstrbuf* name)
2021-03-05 21:38:35 +01:00
{
2021-03-19 20:57:07 +01:00
if(ffStrbufIgnCaseCompS(name, "kwin_wayland") == 0 || ffStrbufIgnCaseCompS(name, "kwin_x11") == 0)
ffStrbufSetS(name, "KWin");
else
return false;
return true;
2021-03-05 21:38:35 +01:00
}
void ffPrintWM(FFinstance* instance)
{
DIR* proc = opendir("/proc/");
if(proc == NULL)
{
ffPrintError(instance, "WM", "opendir(\"/proc/\") == NULL");
return;
}
struct dirent* dirent;
FF_STRBUF_CREATE(name);
2021-03-19 20:57:07 +01:00
bool found = false;
2021-03-05 21:38:35 +01:00
while((dirent = readdir(proc)) != NULL)
{
if(dirent->d_type != DT_DIR)
continue;
char path[20];
sprintf(path, "/proc/%.8s/comm", dirent->d_name);
ffGetFileContent(path, &name);
2021-03-05 21:38:35 +01:00
2021-03-19 20:57:07 +01:00
if((found = parseProcessName(&name)))
2021-03-05 21:38:35 +01:00
break;
}
closedir(proc);
2021-03-19 20:57:07 +01:00
if(!found)
2021-03-05 21:38:35 +01:00
{
ffPrintError(instance, "WM", "No process name matches the name of known display managers");
2021-03-19 20:57:07 +01:00
return;
}
if(ffStrbufIsEmpty(&instance->config.wmFormat))
{
ffPrintLogoAndKey(instance, "WM");
2021-03-22 20:02:32 +01:00
ffStrbufPutTo(&name, stdout);
2021-03-05 21:38:35 +01:00
}
else
{
FF_STRBUF_CREATE(wm);
2021-03-19 20:57:07 +01:00
ffParseFormatString(&wm, &instance->config.wmFormat, 1,
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &name}
);
2021-03-05 21:38:35 +01:00
ffPrintLogoAndKey(instance, "WM");
2021-03-22 20:02:32 +01:00
ffStrbufPutTo(&wm, stdout);
2021-03-19 20:57:07 +01:00
ffStrbufDestroy(&wm);
2021-03-05 21:38:35 +01:00
}
2021-03-19 20:57:07 +01:00
ffStrbufDestroy(&name);
2021-03-05 21:38:35 +01:00
}