mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
wm theme detection for kde plasma
This commit is contained in:
@@ -47,6 +47,7 @@ set(SRCS
|
||||
src/modules/resolution.c
|
||||
src/modules/de.c
|
||||
src/modules/wm.c
|
||||
src/modules/wmtheme.c
|
||||
src/modules/theme.c
|
||||
src/modules/icons.c
|
||||
src/modules/font.c
|
||||
|
||||
@@ -144,6 +144,8 @@ __fastfetch_completion()
|
||||
"--de-key"
|
||||
"--wm-format"
|
||||
"--wm-key"
|
||||
"--wm-theme-format"
|
||||
"--wm-theme-key"
|
||||
"--theme-format"
|
||||
"--theme-key"
|
||||
"--icons-format"
|
||||
|
||||
@@ -47,6 +47,8 @@ void ffDefaultConfig(FFconfig* config)
|
||||
ffStrbufInitA(&config->deKey, 1);
|
||||
ffStrbufInitA(&config->wmFormat, 1);
|
||||
ffStrbufInitA(&config->wmKey, 1);
|
||||
ffStrbufInitA(&config->wmThemeFormat, 1);
|
||||
ffStrbufInitA(&config->wmThemeKey, 1);
|
||||
ffStrbufInitA(&config->themeFormat, 1);
|
||||
ffStrbufInitA(&config->themeKey, 1);
|
||||
ffStrbufInitA(&config->iconsFormat, 1);
|
||||
|
||||
+33
-18
@@ -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:WM:Theme:Icons:Font:Terminal:TerminalFont:CPU:GPU:Memory:Disk:Battery:Locale:Break:Colors"
|
||||
#define FASTFETCH_DEFAULT_STRUCTURE "Title:Seperator:OS:Host:Kernel:Uptime:Packages:Shell:Resolution:DE:WM:WMTheme:Theme:Icons:Font:Terminal:TerminalFont:CPU:GPU:Memory:Disk:Battery:Locale:Break:Colors"
|
||||
|
||||
#define FASTFETCH_DEFAULT_CONFIG \
|
||||
"# Fastfetch configuration\n" \
|
||||
@@ -68,6 +68,7 @@ static inline void printHelp()
|
||||
" --resolution-format <format>\n"
|
||||
" --de-format <format>\n"
|
||||
" --wm-format <format>\n"
|
||||
" --wm-theme-format <format>\n"
|
||||
" --theme-format <format>\n"
|
||||
" --icons-format <format>\n"
|
||||
" --font-format <format>\n"
|
||||
@@ -84,23 +85,24 @@ static inline void printHelp()
|
||||
" --os-key <key>\n"
|
||||
" --host-key <key>\n"
|
||||
" --kernel-key <key>\n"
|
||||
" --uptime-format <key>\n"
|
||||
" --packages-format <key>\n"
|
||||
" --shell-format <key>\n"
|
||||
" --resolution-format <key>\n"
|
||||
" --de-format <key>\n"
|
||||
" --wm-format <key>\n"
|
||||
" --theme-format <key>\n"
|
||||
" --icons-format <key>\n"
|
||||
" --font-format <key>\n"
|
||||
" --terminal-format <key>\n"
|
||||
" --terminal-font-format <key>\n"
|
||||
" --cpu-format <key>\n"
|
||||
" --gpu-format <key>: takes the gpu index as format argument\n"
|
||||
" --memory-format <key>\n"
|
||||
" --disk-format <key>: takes the mount path as format argument\n"
|
||||
" --battery-format <key>: takes the battery index as format argument\n"
|
||||
" --locale-format <key>\n"
|
||||
" --uptime-key <key>\n"
|
||||
" --packages-key <key>\n"
|
||||
" --shell-key <key>\n"
|
||||
" --resolution-key <key>\n"
|
||||
" --de-key <key>\n"
|
||||
" --wm-key <key>\n"
|
||||
" --wm-theme-key <key>\n"
|
||||
" --theme-key <key>\n"
|
||||
" --icons-key <key>\n"
|
||||
" --font-key <key>\n"
|
||||
" --terminal-key <key>\n"
|
||||
" --terminal-font-key <key>\n"
|
||||
" --cpu-key <key>\n"
|
||||
" --gpu-key <key>: takes the gpu index as format argument\n"
|
||||
" --memory-key <key>\n"
|
||||
" --disk-key <key>: takes the mount path as format argument\n"
|
||||
" --battery-key <key>: takes the battery index as format argument\n"
|
||||
" --locale-key <key>\n"
|
||||
"\n"
|
||||
"Library optins: Set the path of a library to load\n"
|
||||
" --lib-PCI <path>\n"
|
||||
@@ -184,6 +186,7 @@ static inline void printAvailableModules()
|
||||
"Title\n"
|
||||
"Uptime\n"
|
||||
"WM\n"
|
||||
"WMTheme\n"
|
||||
"\n"
|
||||
"+ Additional defined by --set"
|
||||
);
|
||||
@@ -293,6 +296,12 @@ static inline void printCommandHelp(const char* command)
|
||||
"WM pretty name"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "wm-theme-format") == 0)
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("wm-theme", "{}", 1,
|
||||
"WM theme name"
|
||||
);
|
||||
}
|
||||
else if(strcasecmp(command, "theme-format") == 0)
|
||||
{
|
||||
constructAndPrintCommandHelpFormat("theme", "{} [Plasma], {5}", 5,
|
||||
@@ -565,6 +574,10 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
optionParseString(key, value, &instance->config.wmFormat);
|
||||
else if(strcasecmp(key, "--wm-key") == 0)
|
||||
optionParseString(key, value, &instance->config.wmKey);
|
||||
else if(strcasecmp(key, "--wm-theme-format") == 0)
|
||||
optionParseString(key, value, &instance->config.wmThemeFormat);
|
||||
else if(strcasecmp(key, "--wm-theme-key") == 0)
|
||||
optionParseString(key, value, &instance->config.wmThemeKey);
|
||||
else if(strcasecmp(key, "--theme-format") == 0)
|
||||
optionParseString(key, value, &instance->config.themeFormat);
|
||||
else if(strcasecmp(key, "--theme-key") == 0)
|
||||
@@ -788,6 +801,8 @@ static void parseStructureCommand(FFinstance* instance, FFdata* data, const char
|
||||
ffPrintWM(instance);
|
||||
else if(strcasecmp(line, "theme") == 0)
|
||||
ffPrintTheme(instance);
|
||||
else if(strcasecmp(line, "wmtheme") == 0)
|
||||
ffPrintWMTheme(instance);
|
||||
else if(strcasecmp(line, "icons") == 0)
|
||||
ffPrintIcons(instance);
|
||||
else if(strcasecmp(line, "font") == 0)
|
||||
|
||||
+5
-1
@@ -64,6 +64,8 @@ typedef struct FFconfig
|
||||
FFstrbuf deKey;
|
||||
FFstrbuf wmFormat;
|
||||
FFstrbuf wmKey;
|
||||
FFstrbuf wmThemeFormat;
|
||||
FFstrbuf wmThemeKey;
|
||||
FFstrbuf themeFormat;
|
||||
FFstrbuf themeKey;
|
||||
FFstrbuf iconsFormat;
|
||||
@@ -157,7 +159,8 @@ void ffPrintLogos(bool color);
|
||||
|
||||
//Module functions
|
||||
|
||||
void ffGetTerminal(FFinstance* instance, FFstrbuf** exeName, FFstrbuf** processName, FFstrbuf** error);
|
||||
void ffCalculateTerminal(FFinstance* instance, FFstrbuf** exeNamePtr, FFstrbuf** processNamePtr, FFstrbuf** errorPtr);
|
||||
void ffCalculateWM(FFinstance* instance, FFstrbuf** prettyNamePtr, FFstrbuf** processNamePtr, FFstrbuf** errorPtr);
|
||||
|
||||
void ffPrintCustom(FFinstance* instance, const char* key, const char* value);
|
||||
void ffPrintBreak(FFinstance* instance);
|
||||
@@ -172,6 +175,7 @@ void ffPrintShell(FFinstance* instance);
|
||||
void ffPrintResolution(FFinstance* instance);
|
||||
void ffPrintDesktopEnvironment(FFinstance* instance);
|
||||
void ffPrintWM(FFinstance* instance);
|
||||
void ffPrintWMTheme(FFinstance* instance);
|
||||
void ffPrintTheme(FFinstance* instance);
|
||||
void ffPrintIcons(FFinstance* instance);
|
||||
void ffPrintFont(FFinstance* instance);
|
||||
|
||||
@@ -22,6 +22,7 @@ int main(int argc, char** argv)
|
||||
ffPrintResolution(&instance);
|
||||
ffPrintDesktopEnvironment(&instance);
|
||||
ffPrintWM(&instance);
|
||||
ffPrintWMTheme(&instance);
|
||||
ffPrintTheme(&instance);
|
||||
ffPrintIcons(&instance);
|
||||
ffPrintFont(&instance);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -390,6 +390,7 @@ void ffStrbufSubstrAfter(FFstrbuf* strbuf, uint32_t index)
|
||||
|
||||
memmove(strbuf->chars, strbuf->chars + index + 1, strbuf->length - index - 1);
|
||||
strbuf->length -= (index + 1);
|
||||
strbuf->chars[strbuf->length] = '\0';
|
||||
}
|
||||
|
||||
void ffStrbufSubstrAfterLastC(FFstrbuf* strbuf, const char c)
|
||||
|
||||
@@ -44,6 +44,7 @@ int main(int argc, char** argv)
|
||||
FASTFETCH_TEST_PERFORMANCE(ffPrintResolution(&instance))
|
||||
FASTFETCH_TEST_PERFORMANCE(ffPrintDesktopEnvironment(&instance))
|
||||
FASTFETCH_TEST_PERFORMANCE(ffPrintWM(&instance))
|
||||
FASTFETCH_TEST_PERFORMANCE(ffPrintWMTheme(&instance))
|
||||
FASTFETCH_TEST_PERFORMANCE(ffPrintTheme(&instance))
|
||||
FASTFETCH_TEST_PERFORMANCE(ffPrintIcons(&instance))
|
||||
FASTFETCH_TEST_PERFORMANCE(ffPrintFont(&instance))
|
||||
|
||||
Reference in New Issue
Block a user