mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
wm theme detection for kde plasma
This commit is contained in:
@@ -47,7 +47,7 @@ static void getTerminalName(FFinstance* instance, const char* pid, FFstrbuf* exe
|
||||
ffStrbufSetS(processName, name);
|
||||
}
|
||||
|
||||
void ffGetTerminal(FFinstance* instance, FFstrbuf** exeNamePtr, FFstrbuf** processNamePtr, FFstrbuf** errorPtr)
|
||||
void ffCalculateTerminal(FFinstance* instance, FFstrbuf** exeNamePtr, FFstrbuf** processNamePtr, FFstrbuf** errorPtr)
|
||||
{
|
||||
static FFstrbuf exeName;
|
||||
static FFstrbuf processName;
|
||||
@@ -65,16 +65,17 @@ void ffGetTerminal(FFinstance* instance, FFstrbuf** exeNamePtr, FFstrbuf** proce
|
||||
|
||||
if(init)
|
||||
return;
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&exeName);
|
||||
ffStrbufInit(&processName);
|
||||
ffStrbufInit(&error);
|
||||
|
||||
char ppid[256];
|
||||
sprintf(ppid, "%i", getppid());
|
||||
|
||||
getTerminalName(instance, ppid, &exeName, &processName, &error);
|
||||
|
||||
init = true;
|
||||
}
|
||||
|
||||
void ffPrintTerminal(FFinstance* instance)
|
||||
@@ -83,7 +84,7 @@ void ffPrintTerminal(FFinstance* instance)
|
||||
FFstrbuf* processName;
|
||||
FFstrbuf* error;
|
||||
|
||||
ffGetTerminal(instance, &exeName, &processName, &error);
|
||||
ffCalculateTerminal(instance, &exeName, &processName, &error);
|
||||
|
||||
if(error->length > 0)
|
||||
{
|
||||
|
||||
@@ -54,29 +54,19 @@ static void printTTY(FFinstance* instance)
|
||||
|
||||
void ffPrintTerminalFont(FFinstance* instance)
|
||||
{
|
||||
FFstrbuf* procName;
|
||||
FFstrbuf* error;
|
||||
ffGetTerminal(instance, NULL, &procName, &error);
|
||||
FFstrbuf* terminalExeName;
|
||||
ffCalculateTerminal(instance, &terminalExeName, NULL, NULL);
|
||||
|
||||
if(error->length > 0)
|
||||
if(terminalExeName->length == 0)
|
||||
{
|
||||
if(instance->config.termFontFormat.length == 0)
|
||||
ffPrintError(instance, &instance->config.termFontKey, "Terminal Font", "Terminal Font needs successfull terminal detection");
|
||||
else
|
||||
printTerminalFont(instance, "");
|
||||
|
||||
ffPrintError(instance, &instance->config.termFontKey, "Terminal Font", "Terminal font needs successfull terminal detection");
|
||||
return;
|
||||
}
|
||||
|
||||
if(ffStrbufIgnCaseCompS(procName, "konsole") == 0)
|
||||
if(ffStrbufIgnCaseCompS(terminalExeName, "konsole") == 0)
|
||||
printKonsole(instance);
|
||||
else if(ffStrbufIgnCaseCompS(procName, "login") == 0)
|
||||
else if(ffStrbufIgnCaseCompS(terminalExeName, "login") == 0)
|
||||
printTTY(instance);
|
||||
else
|
||||
{
|
||||
if(instance->config.termFontFormat.length > 0)
|
||||
printTerminalFont(instance, "");
|
||||
else
|
||||
ffPrintError(instance, &instance->config.termFontKey, "Terminal Font", "Unknown terminal: %s", error->chars);
|
||||
}
|
||||
ffPrintError(instance, &instance->config.termFontKey, "Terminal Font", "Unknown terminal: %s", terminalExeName->chars);
|
||||
}
|
||||
|
||||
+43
-12
@@ -2,20 +2,39 @@
|
||||
|
||||
#include <dirent.h>
|
||||
|
||||
void ffPrintWM(FFinstance* instance)
|
||||
void ffCalculateWM(FFinstance* instance, FFstrbuf** prettyNamePtr, FFstrbuf** processNamePtr, FFstrbuf** errorPtr)
|
||||
{
|
||||
static FFstrbuf prettyName;
|
||||
static FFstrbuf processName;
|
||||
static FFstrbuf error;
|
||||
static bool init = false;
|
||||
|
||||
if(prettyNamePtr != NULL)
|
||||
*prettyNamePtr = &prettyName;
|
||||
|
||||
if(processNamePtr != NULL)
|
||||
*processNamePtr = &processName;
|
||||
|
||||
if(errorPtr != NULL)
|
||||
*errorPtr = &error;
|
||||
|
||||
if(init)
|
||||
return;
|
||||
init = true;
|
||||
|
||||
ffStrbufInit(&prettyName);
|
||||
ffStrbufInit(&processName);
|
||||
ffStrbufInit(&error);
|
||||
|
||||
DIR* proc = opendir("/proc/");
|
||||
if(proc == NULL)
|
||||
{
|
||||
ffPrintError(instance, &instance->config.wmKey, "WM", "opendir(\"/proc/\") == NULL");
|
||||
ffStrbufSetS(&error, "opendir(\"/proc/\") == NULL");
|
||||
return;
|
||||
}
|
||||
|
||||
struct dirent* dirent;
|
||||
|
||||
FF_STRBUF_CREATE(processName);
|
||||
FF_STRBUF_CREATE(prettyName);
|
||||
|
||||
while((dirent = readdir(proc)) != NULL)
|
||||
{
|
||||
if(dirent->d_type != DT_DIR)
|
||||
@@ -37,23 +56,35 @@ void ffPrintWM(FFinstance* instance)
|
||||
|
||||
if(prettyName.length == 0)
|
||||
{
|
||||
ffPrintError(instance, &instance->config.wmKey, "WM", "No process name matches the name of known display managers");
|
||||
ffStrbufSetS(&error, "No process name matches the name of known display managers");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void ffPrintWM(FFinstance* instance)
|
||||
{
|
||||
FFstrbuf* prettyName;
|
||||
FFstrbuf* processName;
|
||||
FFstrbuf* error;
|
||||
|
||||
ffCalculateWM(instance, &prettyName, &processName, &error);
|
||||
|
||||
if(error->length > 0)
|
||||
{
|
||||
ffPrintError(instance, &instance->config.wmKey, "WM", error->chars);
|
||||
return;
|
||||
}
|
||||
|
||||
if(instance->config.wmFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, &instance->config.wmKey, "WM");
|
||||
ffStrbufPutTo(&prettyName, stdout);
|
||||
ffStrbufPutTo(prettyName, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, &instance->config.wmKey, "WM", &instance->config.wmFormat, 2,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &processName},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, &prettyName}
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, processName},
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRBUF, prettyName}
|
||||
);
|
||||
}
|
||||
|
||||
ffStrbufDestroy(&processName);
|
||||
ffStrbufDestroy(&prettyName);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
#include "fastfetch.h"
|
||||
|
||||
static void printWMTheme(FFinstance* instance, const char* theme)
|
||||
{
|
||||
if(instance->config.wmThemeFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, &instance->config.wmThemeKey, "WM Theme");
|
||||
puts(theme);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormatString(instance, &instance->config.wmThemeKey, "WM Theme", &instance->config.wmThemeFormat, 1,
|
||||
(FFformatarg){FF_FORMAT_ARG_TYPE_STRING, theme}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
static void printKWin(FFinstance* instance)
|
||||
{
|
||||
char theme[256];
|
||||
theme[0] = '\0';
|
||||
ffParsePropFileHome(instance, ".config/kwinrc", "theme=%s", theme);
|
||||
|
||||
if(theme[0] == '\0')
|
||||
{
|
||||
ffPrintError(instance, &instance->config.wmThemeKey, "WM Theme", "Couldn't find \"theme=\" in \".config/kwinrc\"");
|
||||
return;
|
||||
}
|
||||
|
||||
printWMTheme(instance, theme);
|
||||
}
|
||||
|
||||
void ffPrintWMTheme(FFinstance* instance)
|
||||
{
|
||||
FFstrbuf* wmName;
|
||||
ffCalculateWM(instance, &wmName, NULL, NULL);
|
||||
|
||||
if(wmName->length == 0)
|
||||
{
|
||||
ffPrintError(instance, &instance->config.wmThemeKey, "WM Theme", "WM Theme needs sucessfull wm detection");
|
||||
return;
|
||||
}
|
||||
|
||||
if(ffStrbufIgnCaseCompS(wmName, "KWin") == 0)
|
||||
printKWin(instance);
|
||||
else
|
||||
ffPrintError(instance, &instance->config.wmThemeKey, "WM Theme", "Unknown WM: %s", wmName->chars);
|
||||
}
|
||||
Reference in New Issue
Block a user