mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
basic Window Manager detection
This commit is contained in:
@@ -40,6 +40,7 @@ set(SRCS
|
||||
src/modules/shell.c
|
||||
src/modules/resolution.c
|
||||
src/modules/desktopenvironment.c
|
||||
src/modules/wm.c
|
||||
src/modules/theme.c
|
||||
src/modules/icons.c
|
||||
src/modules/font.c
|
||||
|
||||
+4
-2
@@ -8,7 +8,7 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#define FASTFETCH_DEFAULT_STRUCTURE "Title:Seperator:OS:Host:Kernel:Uptime:Packages:Shell:Resolution:DE:Theme:Icons:Font:Terminal:CPU:GPU:Memory:Disk:Battery:Locale:Break:Colors"
|
||||
#define FASTFETCH_DEFAULT_STRUCTURE "Title:Seperator:OS:Host:Kernel:Uptime:Packages:Shell:Resolution:DE:WM:Theme:Icons:Font:Terminal:CPU:GPU:Memory:Disk:Battery:Locale:Break:Colors"
|
||||
|
||||
#define FASTFETCH_DEFAULT_CONFIG \
|
||||
"## Fastfetch configuration\n" \
|
||||
@@ -75,7 +75,7 @@ static void printHelp()
|
||||
" --battery-technology <?value>: Show the technology of the battery, if possible\n"
|
||||
" --battery-capacity <?value>: Show the capacity of the battery, if possible\n"
|
||||
" --battery-status <?value>: Show the status of the battery, if possible\n"
|
||||
" --battery-formart <format>: Provide the printf format string for battery output (+)\n"
|
||||
" --battery-format <format>: Provide the printf format string for battery output (+)\n"
|
||||
"\n"
|
||||
"If an value starts with an ?, it is optional. \"true\" will be used if not set.\n"
|
||||
"An (+) at the end indicates that more help can be printed with --help <option>\n"
|
||||
@@ -161,6 +161,8 @@ static void parseStructureCommand(FFinstance* instance, FFdata* data, const char
|
||||
ffPrintResolution(instance);
|
||||
else if(strcasecmp(line, "desktopenvironment") == 0 || strcasecmp(line, "de") == 0)
|
||||
ffPrintDesktopEnvironment(instance);
|
||||
else if(strcasecmp(line, "windowmanager") == 0 || strcasecmp(line, "wm") == 0)
|
||||
ffPrintWM(instance);
|
||||
else if(strcasecmp(line, "theme") == 0)
|
||||
ffPrintTheme(instance);
|
||||
else if(strcasecmp(line, "icons") == 0)
|
||||
|
||||
@@ -100,6 +100,7 @@ void ffPrintPackages(FFinstance* instance);
|
||||
void ffPrintShell(FFinstance* instance);
|
||||
void ffPrintResolution(FFinstance* instance);
|
||||
void ffPrintDesktopEnvironment(FFinstance* instance);
|
||||
void ffPrintWM(FFinstance* instance);
|
||||
void ffPrintTheme(FFinstance* instance);
|
||||
void ffPrintIcons(FFinstance* instance);
|
||||
void ffPrintFont(FFinstance* instance);
|
||||
|
||||
@@ -23,6 +23,7 @@ int main(int argc, char** argv)
|
||||
ffPrintShell(&instance);
|
||||
ffPrintResolution(&instance);
|
||||
ffPrintDesktopEnvironment(&instance);
|
||||
ffPrintWM(&instance);
|
||||
ffPrintTheme(&instance);
|
||||
ffPrintIcons(&instance);
|
||||
ffPrintFont(&instance);
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
static void parseProcessName(const char* name, char* buffer)
|
||||
{
|
||||
if(strcasecmp(name, "kwin_wayland") == 0)
|
||||
strcpy(buffer, "KWin (Wayland)");
|
||||
else if(strcasecmp(name, "kwin_x11") == 0)
|
||||
strcpy(buffer, "KWin (X11)");
|
||||
}
|
||||
|
||||
void ffPrintWM(FFinstance* instance)
|
||||
{
|
||||
DIR* proc = opendir("/proc/");
|
||||
if(proc == NULL)
|
||||
{
|
||||
ffPrintError(instance, "WM", "opendir(\"/proc/\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
struct dirent* dirent;
|
||||
|
||||
char name[32];
|
||||
name[0] = '\0';
|
||||
|
||||
while((dirent = readdir(proc)) != NULL)
|
||||
{
|
||||
if(dirent->d_type != DT_DIR)
|
||||
continue;
|
||||
|
||||
char path[20];
|
||||
sprintf(path, "/proc/%.8s/comm", dirent->d_name);
|
||||
|
||||
char comm[17]; //MAX_COMM_LENGTH is 17 + null terminator
|
||||
ffGetFileContent(path, comm, sizeof(comm));
|
||||
|
||||
if(comm[0] == '\0')
|
||||
continue;
|
||||
|
||||
parseProcessName(comm, name);
|
||||
|
||||
if(name[0] != '\0')
|
||||
break;
|
||||
}
|
||||
|
||||
closedir(proc);
|
||||
|
||||
if(name[0] == '\0')
|
||||
{
|
||||
ffPrintError(instance, "WM", "No process name matches the name of known display managers");
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintLogoAndKey(instance, "WM");
|
||||
puts(name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user