Files
fastfetch/src/modules/wm.c
T

60 lines
1.5 KiB
C
Raw Normal View History

2021-03-05 21:38:35 +01:00
#include "fastfetch.h"
#include <dirent.h>
void ffPrintWM(FFinstance* instance)
{
DIR* proc = opendir("/proc/");
if(proc == NULL)
{
2021-04-03 11:39:59 +02:00
ffPrintError(instance, &instance->config.wmKey, "WM", "opendir(\"/proc/\") == NULL");
2021-03-05 21:38:35 +01:00
return;
}
struct dirent* dirent;
2021-03-28 20:36:49 +02:00
FF_STRBUF_CREATE(processName);
FF_STRBUF_CREATE(prettyName);
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);
2021-03-28 20:36:49 +02:00
ffGetFileContent(path, &processName);
if(ffStrbufIgnCaseCompS(&processName, "kwin_wayland") == 0 || ffStrbufIgnCaseCompS(&processName, "kwin_x11") == 0)
ffStrbufSetS(&prettyName, "KWin");
2021-03-05 21:38:35 +01:00
2021-03-28 20:36:49 +02:00
if(prettyName.length > 0)
2021-03-05 21:38:35 +01:00
break;
}
closedir(proc);
2021-04-03 21:51:50 +02:00
if(prettyName.length == 0)
2021-03-19 20:57:07 +01:00
{
2021-04-03 21:51:50 +02:00
ffPrintError(instance, &instance->config.wmKey, "WM", "No process name matches the name of known display managers");
return;
}
2021-04-03 21:51:50 +02:00
if(instance->config.wmFormat.length == 0)
{
2021-04-03 11:39:59 +02:00
ffPrintLogoAndKey(instance, &instance->config.wmKey, "WM");
2021-03-28 20:36:49 +02:00
ffStrbufPutTo(&prettyName, stdout);
2021-03-05 21:38:35 +01:00
}
else
{
2021-04-03 11:39:59 +02:00
ffPrintFormatString(instance, &instance->config.wmKey, "WM", &instance->config.wmFormat, 2,
2021-03-28 20:36:49 +02:00
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &processName},
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &prettyName}
2021-03-19 20:57:07 +01:00
);
2021-03-05 21:38:35 +01:00
}
2021-03-19 20:57:07 +01:00
2021-03-28 20:36:49 +02:00
ffStrbufDestroy(&processName);
ffStrbufDestroy(&prettyName);
2021-03-27 18:14:19 +01:00
}