From 6c612cbd9a283a77b07437d8d3447ce3f50f068e Mon Sep 17 00:00:00 2001
From: DarN <82701459+DarNCelsius@users.noreply.github.com>
Date: Sun, 25 Apr 2021 21:18:56 +0200
Subject: [PATCH 1/6] Added additional WM Theme support
Supports LXQt, LXDE and Openbox
---
src/modules/wmtheme.c | 77 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 77 insertions(+)
diff --git a/src/modules/wmtheme.c b/src/modules/wmtheme.c
index 8dc71419a..58a9eebcb 100644
--- a/src/modules/wmtheme.c
+++ b/src/modules/wmtheme.c
@@ -1,4 +1,6 @@
#include "fastfetch.h"
+#include "string.h"
+#include "util/FFstrbuf.h"
#define FF_WMTHEME_MODULE_NAME "WM Theme"
#define FF_WMTHEME_NUM_FORMAT_ARGS 1
@@ -33,6 +35,79 @@ static void printKWin(FFinstance* instance)
printWMTheme(instance, theme);
}
+void ffGetOBThemeName(FFinstance* instance, const char* fName, char* buffer)
+{
+ FFstrbuf absolutePath, themeStrbuf;
+ ffStrbufInitA(&absolutePath, 64);
+ ffStrbufAppendS(&absolutePath, instance->state.passwd->pw_dir);
+ ffStrbufAppendS(&absolutePath, fName);
+ ffStrbufInitA(&themeStrbuf, 256);
+
+ char* line = NULL;
+ size_t len = 0;
+
+ FILE* file = fopen(absolutePath.chars, "r");
+ if(file == NULL)
+ return; // handle errors in higher functions
+
+ while (getline(&line, &len, file) != -1)
+ {
+ if (strstr(line, "") != 0)
+ break;
+ }
+ while (getline(&line, &len, file) != -1)
+ {
+ if (strstr(line, "") != 0)
+ {
+ const char* delStrs[] = {"", ""};
+
+ ffStrbufAppendS(&themeStrbuf, line);
+ ffStrbufRemoveStringsA(&themeStrbuf, 2, delStrs);
+ ffStrbufTrimRight(&themeStrbuf, '\n');
+ ffStrbufTrim(&themeStrbuf, ' ');
+
+ strcpy(buffer, themeStrbuf.chars);
+ }
+ else if (strstr(line, "") != 0)
+ break;
+ break;
+ }
+
+ fclose(file);
+ if(line != NULL)
+ free(line);
+
+ ffStrbufDestroy(&absolutePath);
+ ffStrbufDestroy(&themeStrbuf);
+}
+
+static void printOpenbox(FFinstance* instance)
+{
+ char relPath[64];
+ char theme[256];
+ theme[0] = '\0';
+
+ const char* deName = getenv("XDG_SESSION_DESKTOP");
+
+ if (strcmp(deName, (const char*)"LXQt Desktop") == 0)
+ strcpy(relPath, "/.config/openbox/lxqt-rc.xml");
+ else if(strcmp(deName, (const char*)"LXDE") == 0)
+ strcpy(relPath, "/.config/openbox/lxde-rc.xml");
+ else
+ strcpy(relPath, "/.config/openbox/rc.xml");
+
+ ffGetOBThemeName(instance, relPath, theme);
+
+ if(theme[0] == '\0')
+ {
+ ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find theme name in \"%s\"", relPath);
+ return;
+ }
+
+ printWMTheme(instance, theme);
+}
+
+
void ffPrintWMTheme(FFinstance* instance)
{
const FFWMResult* result = ffCalculateWM(instance);
@@ -45,6 +120,8 @@ void ffPrintWMTheme(FFinstance* instance)
if(ffStrbufIgnCaseCompS(&result->prettyName, "KWin") == 0)
printKWin(instance);
+ else if(ffStrbufIgnCaseCompS(&result->prettyName, "Openbox") == 0)
+ printOpenbox(instance);
else
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Unknown WM: %s", result->prettyName.chars);
}
From 41dc49f170479a1157c4cfacad3e9a83ca5e4bea Mon Sep 17 00:00:00 2001
From: DarN <82701459+DarNCelsius@users.noreply.github.com>
Date: Mon, 26 Apr 2021 17:27:12 +0200
Subject: [PATCH 2/6] Update wmtheme.c
---
src/modules/wmtheme.c | 79 +++++++++++++++++++------------------------
1 file changed, 35 insertions(+), 44 deletions(-)
diff --git a/src/modules/wmtheme.c b/src/modules/wmtheme.c
index 58a9eebcb..a9f000505 100644
--- a/src/modules/wmtheme.c
+++ b/src/modules/wmtheme.c
@@ -1,6 +1,5 @@
#include "fastfetch.h"
-#include "string.h"
-#include "util/FFstrbuf.h"
+#include
#define FF_WMTHEME_MODULE_NAME "WM Theme"
#define FF_WMTHEME_NUM_FORMAT_ARGS 1
@@ -35,13 +34,22 @@ static void printKWin(FFinstance* instance)
printWMTheme(instance, theme);
}
-void ffGetOBThemeName(FFinstance* instance, const char* fName, char* buffer)
+static void printOpenbox(FFinstance* instance)
{
- FFstrbuf absolutePath, themeStrbuf;
+ FFstrbuf absolutePath, theme;
ffStrbufInitA(&absolutePath, 64);
+ ffStrbufInitA(&theme, 256);
ffStrbufAppendS(&absolutePath, instance->state.passwd->pw_dir);
- ffStrbufAppendS(&absolutePath, fName);
- ffStrbufInitA(&themeStrbuf, 256);
+ ffStrbufAppendC(&absolutePath, '/');
+
+ const char* deName = ffGetSessionDesktop();
+
+ if(strcmp(deName, (const char*)"LXQt") == 0)
+ ffStrbufAppendS(&absolutePath, ".config/openbox/lxqt-rc.xml");
+ else if(strcmp(deName, (const char*)"LXDE") == 0)
+ ffStrbufAppendS(&absolutePath, ".config/openbox/lxde-rc.xml");
+ else
+ ffStrbufAppendS(&absolutePath, ".config/openbox/rc.xml");
char* line = NULL;
size_t len = 0;
@@ -50,63 +58,46 @@ void ffGetOBThemeName(FFinstance* instance, const char* fName, char* buffer)
if(file == NULL)
return; // handle errors in higher functions
- while (getline(&line, &len, file) != -1)
+ while(getline(&line, &len, file) != -1)
{
- if (strstr(line, "") != 0)
+ if(strstr(line, "") != 0)
break;
}
- while (getline(&line, &len, file) != -1)
+ while(getline(&line, &len, file) != -1)
{
- if (strstr(line, "") != 0)
+ if(strstr(line, "") != 0)
{
const char* delStrs[] = {"", ""};
- ffStrbufAppendS(&themeStrbuf, line);
- ffStrbufRemoveStringsA(&themeStrbuf, 2, delStrs);
- ffStrbufTrimRight(&themeStrbuf, '\n');
- ffStrbufTrim(&themeStrbuf, ' ');
-
- strcpy(buffer, themeStrbuf.chars);
+ ffStrbufAppendS(&theme, line);
+ ffStrbufRemoveStringsA(&theme, 2, delStrs);
+ ffStrbufTrimRight(&theme, '\n');
+ ffStrbufTrim(&theme, ' ');
}
- else if (strstr(line, "") != 0)
+ else if(strstr(line, "") != 0) // sanity check
break;
break;
}
fclose(file);
- if(line != NULL)
+ if(line != NULL) {
free(line);
-
- ffStrbufDestroy(&absolutePath);
- ffStrbufDestroy(&themeStrbuf);
-}
-
-static void printOpenbox(FFinstance* instance)
-{
- char relPath[64];
- char theme[256];
- theme[0] = '\0';
-
- const char* deName = getenv("XDG_SESSION_DESKTOP");
-
- if (strcmp(deName, (const char*)"LXQt Desktop") == 0)
- strcpy(relPath, "/.config/openbox/lxqt-rc.xml");
- else if(strcmp(deName, (const char*)"LXDE") == 0)
- strcpy(relPath, "/.config/openbox/lxde-rc.xml");
- else
- strcpy(relPath, "/.config/openbox/rc.xml");
-
- ffGetOBThemeName(instance, relPath, theme);
-
- if(theme[0] == '\0')
+ }
+ if(theme.length == 0)
{
- ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find theme name in \"%s\"", relPath);
+ ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find theme name in \"%s\"", absolutePath.chars);
+
+ ffStrbufDestroy(&absolutePath);
+ ffStrbufDestroy(&theme);
+
return;
}
- printWMTheme(instance, theme);
-}
+ printWMTheme(instance, theme.chars);
+ ffStrbufDestroy(&absolutePath);
+ ffStrbufDestroy(&theme);
+}
void ffPrintWMTheme(FFinstance* instance)
{
From 6bcf3bab7c13a84e7c1e52b106272fee4acb39c4 Mon Sep 17 00:00:00 2001
From: DarN <82701459+DarNCelsius@users.noreply.github.com>
Date: Mon, 26 Apr 2021 17:39:05 +0200
Subject: [PATCH 3/6] Cleaned up whitespace
---
src/modules/wmtheme.c | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/src/modules/wmtheme.c b/src/modules/wmtheme.c
index a9f000505..a34afaefc 100644
--- a/src/modules/wmtheme.c
+++ b/src/modules/wmtheme.c
@@ -36,20 +36,20 @@ static void printKWin(FFinstance* instance)
static void printOpenbox(FFinstance* instance)
{
- FFstrbuf absolutePath, theme;
+ FFstrbuf absolutePath, theme;
ffStrbufInitA(&absolutePath, 64);
ffStrbufInitA(&theme, 256);
ffStrbufAppendS(&absolutePath, instance->state.passwd->pw_dir);
ffStrbufAppendC(&absolutePath, '/');
- const char* deName = ffGetSessionDesktop();
+ const char* deName = ffGetSessionDesktop();
- if(strcmp(deName, (const char*)"LXQt") == 0)
- ffStrbufAppendS(&absolutePath, ".config/openbox/lxqt-rc.xml");
- else if(strcmp(deName, (const char*)"LXDE") == 0)
- ffStrbufAppendS(&absolutePath, ".config/openbox/lxde-rc.xml");
- else
- ffStrbufAppendS(&absolutePath, ".config/openbox/rc.xml");
+ if(strcmp(deName, (const char*)"LXQt") == 0)
+ ffStrbufAppendS(&absolutePath, ".config/openbox/lxqt-rc.xml");
+ else if(strcmp(deName, (const char*)"LXDE") == 0)
+ ffStrbufAppendS(&absolutePath, ".config/openbox/lxde-rc.xml");
+ else
+ ffStrbufAppendS(&absolutePath, ".config/openbox/rc.xml");
char* line = NULL;
size_t len = 0;
@@ -83,17 +83,17 @@ static void printOpenbox(FFinstance* instance)
if(line != NULL) {
free(line);
}
- if(theme.length == 0)
- {
- ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find theme name in \"%s\"", absolutePath.chars);
+ if(theme.length == 0)
+ {
+ ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find theme name in \"%s\"", absolutePath.chars);
ffStrbufDestroy(&absolutePath);
ffStrbufDestroy(&theme);
-
- return;
- }
+
+ return;
+ }
- printWMTheme(instance, theme.chars);
+ printWMTheme(instance, theme.chars);
ffStrbufDestroy(&absolutePath);
ffStrbufDestroy(&theme);
From a4d4b666793d9ab94cd932c439bbe4a60cb0adf8 Mon Sep 17 00:00:00 2001
From: DarN <82701459+DarNCelsius@users.noreply.github.com>
Date: Mon, 26 Apr 2021 20:47:32 +0200
Subject: [PATCH 4/6] Implemented suggested changes
---
src/modules/wmtheme.c | 56 +++++++++++++++++++++----------------------
1 file changed, 28 insertions(+), 28 deletions(-)
diff --git a/src/modules/wmtheme.c b/src/modules/wmtheme.c
index a34afaefc..a7ded49f4 100644
--- a/src/modules/wmtheme.c
+++ b/src/modules/wmtheme.c
@@ -44,9 +44,9 @@ static void printOpenbox(FFinstance* instance)
const char* deName = ffGetSessionDesktop();
- if(strcmp(deName, (const char*)"LXQt") == 0)
+ if(strcasecmp(deName, (const char*)"LXQt") == 0)
ffStrbufAppendS(&absolutePath, ".config/openbox/lxqt-rc.xml");
- else if(strcmp(deName, (const char*)"LXDE") == 0)
+ else if(strcasecmp(deName, (const char*)"LXDE") == 0)
ffStrbufAppendS(&absolutePath, ".config/openbox/lxde-rc.xml");
else
ffStrbufAppendS(&absolutePath, ".config/openbox/rc.xml");
@@ -55,48 +55,48 @@ static void printOpenbox(FFinstance* instance)
size_t len = 0;
FILE* file = fopen(absolutePath.chars, "r");
- if(file == NULL)
- return; // handle errors in higher functions
-
- while(getline(&line, &len, file) != -1)
+ if(file != NULL)
{
- if(strstr(line, "") != 0)
- break;
- }
- while(getline(&line, &len, file) != -1)
- {
- if(strstr(line, "") != 0)
+ while(getline(&line, &len, file) != -1)
{
- const char* delStrs[] = {"", ""};
-
- ffStrbufAppendS(&theme, line);
- ffStrbufRemoveStringsA(&theme, 2, delStrs);
- ffStrbufTrimRight(&theme, '\n');
- ffStrbufTrim(&theme, ' ');
+ if(strstr(line, "") != 0)
+ break;
}
- else if(strstr(line, "") != 0) // sanity check
- break;
- break;
- }
-
- fclose(file);
- if(line != NULL) {
- free(line);
+ while(getline(&line, &len, file) != -1)
+ {
+ if(strstr(line, "") != 0)
+ {
+ ffStrbufAppendS(&theme, line);
+ ffStrbufRemoveStrings(&theme, 2, "", "");
+ ffStrbufTrimRight(&theme, '\n');
+ ffStrbufTrim(&theme, ' ');
+ break;
+ }
+ else if(strstr(line, "") != 0) // sanity check
+ break;
+ }
+ if(line != NULL)
+ free(line);
+
+ fclose(file);
}
+ else
+ ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't open \"%s\"", absolutePath.chars);
+
if(theme.length == 0)
{
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find theme name in \"%s\"", absolutePath.chars);
- ffStrbufDestroy(&absolutePath);
ffStrbufDestroy(&theme);
+ ffStrbufDestroy(&absolutePath);
return;
}
printWMTheme(instance, theme.chars);
- ffStrbufDestroy(&absolutePath);
ffStrbufDestroy(&theme);
+ ffStrbufDestroy(&absolutePath);
}
void ffPrintWMTheme(FFinstance* instance)
From dbc576862ec1ee2d070f4ae2a0d63d94263bb373 Mon Sep 17 00:00:00 2001
From: DarN <82701459+DarNCelsius@users.noreply.github.com>
Date: Mon, 26 Apr 2021 21:46:57 +0200
Subject: [PATCH 5/6] Made corrections
Something like this?
---
src/modules/wmtheme.c | 66 +++++++++++++++++++++----------------------
1 file changed, 32 insertions(+), 34 deletions(-)
diff --git a/src/modules/wmtheme.c b/src/modules/wmtheme.c
index a7ded49f4..ed9312741 100644
--- a/src/modules/wmtheme.c
+++ b/src/modules/wmtheme.c
@@ -1,4 +1,5 @@
#include "fastfetch.h"
+#include "util/FFstrbuf.h"
#include
#define FF_WMTHEME_MODULE_NAME "WM Theme"
@@ -38,7 +39,6 @@ static void printOpenbox(FFinstance* instance)
{
FFstrbuf absolutePath, theme;
ffStrbufInitA(&absolutePath, 64);
- ffStrbufInitA(&theme, 256);
ffStrbufAppendS(&absolutePath, instance->state.passwd->pw_dir);
ffStrbufAppendC(&absolutePath, '/');
@@ -55,45 +55,43 @@ static void printOpenbox(FFinstance* instance)
size_t len = 0;
FILE* file = fopen(absolutePath.chars, "r");
- if(file != NULL)
+ if(file == NULL)
{
- while(getline(&line, &len, file) != -1)
- {
- if(strstr(line, "") != 0)
- break;
- }
- while(getline(&line, &len, file) != -1)
- {
- if(strstr(line, "") != 0)
- {
- ffStrbufAppendS(&theme, line);
- ffStrbufRemoveStrings(&theme, 2, "", "");
- ffStrbufTrimRight(&theme, '\n');
- ffStrbufTrim(&theme, ' ');
- break;
- }
- else if(strstr(line, "") != 0) // sanity check
- break;
- }
- if(line != NULL)
- free(line);
-
- fclose(file);
- }
- else
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't open \"%s\"", absolutePath.chars);
-
- if(theme.length == 0)
- {
- ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find theme name in \"%s\"", absolutePath.chars);
-
- ffStrbufDestroy(&theme);
ffStrbufDestroy(&absolutePath);
-
+
return;
}
+
+ while(getline(&line, &len, file) != -1)
+ {
+ if(strstr(line, "") != 0)
+ break;
+ }
+ while(getline(&line, &len, file) != -1)
+ {
+ if(strstr(line, "") != 0)
+ {
+ ffStrbufInitA(&theme, 256);
+ ffStrbufAppendS(&theme, line);
+ ffStrbufRemoveStrings(&theme, 2, "", "");
+ ffStrbufTrimRight(&theme, '\n');
+ ffStrbufTrim(&theme, ' ');
+ break;
+ }
+ else if(strstr(line, "") != 0) // sanity check
+ break;
+ }
+ if(line != NULL)
+ free(line);
- printWMTheme(instance, theme.chars);
+ fclose(file);
+
+
+ if(theme.length == 0)
+ ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find theme name in \"%s\"", absolutePath.chars);
+ else
+ printWMTheme(instance, theme.chars);
ffStrbufDestroy(&theme);
ffStrbufDestroy(&absolutePath);
From dd709461a59b74d547488ea0c4b32793e84664f8 Mon Sep 17 00:00:00 2001
From: DarN <82701459+DarNCelsius@users.noreply.github.com>
Date: Mon, 26 Apr 2021 21:49:12 +0200
Subject: [PATCH 6/6] Small correction
Something is adding this include automatically...
---
src/modules/wmtheme.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/src/modules/wmtheme.c b/src/modules/wmtheme.c
index ed9312741..fc83ff075 100644
--- a/src/modules/wmtheme.c
+++ b/src/modules/wmtheme.c
@@ -1,5 +1,4 @@
#include "fastfetch.h"
-#include "util/FFstrbuf.h"
#include
#define FF_WMTHEME_MODULE_NAME "WM Theme"