From d8bb36f119ceb39d2f4241e359f6005c347dffe9 Mon Sep 17 00:00:00 2001 From: xzvf Date: Wed, 15 Jun 2022 16:14:46 +0200 Subject: [PATCH 01/55] Add CPU package temperature to CPU module. This is done by looking for a specified thermal zone in /sys/class/thermal/thermal_zone*/ . Unfortunately there is no better way to find the temperature, then to check all registered zones. This still needs to be extended to support other hardware, right now only x86 CPUs and Raspberry pi are tested. Maybe the FF_CPU_THERMAL_ZONES array could be user configurable, but I could not figure out how to add an array as a config parameter. --- DEVELOPMENT.md | 2 +- src/fastfetch.c | 3 ++- src/modules/cpu.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 68 insertions(+), 3 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index 7002e39ec..b814868fa 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -12,7 +12,7 @@ Here i just add things that are easy to forget. - `libffprint`: contains the printing functions, logos, format etc - `fastfetch` and `flashfetch`: Executables, that initialize the config of libffprint. Fist one at runtime, second one at compile time - [ ] Better OS output for all possible combinations of /etc/os-release variables. -- [ ] Expose temperatures to CPU format string +- [X] Expose temperatures to CPU format string - [ ] Expose temperatures to GPU format string - [ ] Find wayland compositor by looking at \${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY:-wayland-0} - [ ] Make LocalIP module more configurable diff --git a/src/fastfetch.c b/src/fastfetch.c index f148dbce0..c819da278 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -236,7 +236,7 @@ static inline void printCommandHelp(const char* command) } else if(strcasecmp(command, "cpu-format") == 0) { - constructAndPrintCommandHelpFormat("cpu", "{2} ({7}) @ {14}GHz", 14, + constructAndPrintCommandHelpFormat("cpu", "{2} ({7}) @ {15}GHz ({8}°C)", 15, "CPU name", "Prettified CPU name", "CPU Vendor name (Vendor ID)", @@ -244,6 +244,7 @@ static inline void printCommandHelp(const char* command) "CPU logical core count configured", "CPU physical core count", "Always set core count", + "CPU package temperature", "frequency bios limit", "frequency scaling max", "frequency scaling min", diff --git a/src/modules/cpu.c b/src/modules/cpu.c index ffbcf3c43..0b898c6b5 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -1,9 +1,16 @@ #include "fastfetch.h" #include +#include #define FF_CPU_MODULE_NAME "CPU" -#define FF_CPU_NUM_FORMAT_ARGS 14 +#define FF_CPU_NUM_FORMAT_ARGS 15 + +// TODO: possibly add a config option for this +char *FF_CPU_THERMAL_ZONES[] = { + "x86_pkg_temp", // x86 CPU package temperature + "cpu-thermal" // Raspberry Pi CPU temperature (possibly other ARM platforms aswell) +}; static double parseHz(FFstrbuf* content) { @@ -104,6 +111,59 @@ void ffPrintCPU(FFinstance* instance) if(numProcs <= 1) numProcs = physicalCores; + double cpuPackageTemp = __DBL_MAX__; + // enumerate thermal zones until we either find the x86_pkg_temp zone or we run out of zones. + // NOTE: This should generally run just a couple times (~10 iterations), but maybe we should put this behind allowSlowOperations? + for (int tzIndex = 0;; tzIndex++) + { + char path[64]; + snprintf(path, sizeof(path), "/sys/class/thermal/thermal_zone%d/type", tzIndex); + + FFstrbuf fileContents; + ffStrbufInit(&fileContents); + + if (!ffGetFileContent(path, &fileContents)) + { + // this termal zone does not exist + ffStrbufDestroy(&fileContents); + break; + } + + bool isTargetTZ = false; + for(size_t i = 0; i < sizeof(FF_CPU_THERMAL_ZONES) / sizeof(FF_CPU_THERMAL_ZONES[0]); i++) + { + if (strncmp(fileContents.chars, FF_CPU_THERMAL_ZONES[i], fileContents.length) == 0) { + isTargetTZ = true; + break; + } + } + if(isTargetTZ) + { + snprintf(path, sizeof(path), "/sys/class/thermal/thermal_zone%d/temp", tzIndex); + ffStrbufInit(&fileContents); + if (!ffGetFileContent(path, &fileContents)) + { + ffStrbufDestroy(&fileContents); + break; + } + // The temperature is encoded in millicelsius, meaning "49000" is 49C + // NOTE: for strtol errno MUST be manually reset (see manpage) + errno = 0; + long sensorValue = strtol(fileContents.chars, NULL, 10); + if (!errno) + cpuPackageTemp = (float)sensorValue / 1000.0f; // convert to celsius + ffStrbufDestroy(&fileContents); + break; + } + ffStrbufDestroy(&fileContents); + + } + + if (cpuPackageTemp == __DBL_MAX__) + { + ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, "Could not find a CPU thermal zone"); + } + double ghz = biosLimit; if(ghz == 0) ghz = scalingMaxFreq; @@ -163,6 +223,9 @@ void ffPrintCPU(FFinstance* instance) if(ghz > 0) ffStrbufAppendF(&cpu, " @ %.9gGHz", ghz); + + if (cpuPackageTemp != __DBL_MAX__) + ffStrbufAppendF(&cpu, " (%g°C)", cpuPackageTemp); ffPrintAndWriteToCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpuKey, &cpu, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &name}, @@ -172,6 +235,7 @@ void ffPrintCPU(FFinstance* instance) {FF_FORMAT_ARG_TYPE_INT, &numProcsAvailable}, {FF_FORMAT_ARG_TYPE_INT, &physicalCores}, {FF_FORMAT_ARG_TYPE_INT, &numProcs}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &cpuPackageTemp}, {FF_FORMAT_ARG_TYPE_DOUBLE, &biosLimit}, {FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMaxFreq}, {FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMinFreq}, From 5b030de20aa6b95b17b1ba31768bb92e2b1066f0 Mon Sep 17 00:00:00 2001 From: xzvf Date: Wed, 15 Jun 2022 16:28:07 +0200 Subject: [PATCH 02/55] Quality of life improvement: make run.sh not run ff, if the build fails --- run.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/run.sh b/run.sh index 77dc1d661..e4004c120 100755 --- a/run.sh +++ b/run.sh @@ -1,4 +1,9 @@ #!/bin/env sh + +# make the script exit if any of the commands fail, +# making fastfetch not run if the build failed. +set -e + mkdir -p build/ cd build/ cmake .. From bccd1cf960581045cb0e9681cba199286eda5ce0 Mon Sep 17 00:00:00 2001 From: xzvf Date: Thu, 16 Jun 2022 12:54:28 +0200 Subject: [PATCH 03/55] Merge pull request #1 from LinusDierheimer/master build temps file --- CMakeLists.txt | 1 + src/detection/temps.c | 5 +---- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 16f28e5a4..2bfb476c2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -161,6 +161,7 @@ add_library(libfastfetch OBJECT src/detection/vulkan.c src/detection/media.c src/detection/datetime.c + src/detection/temps.c src/detection/displayserver/displayServer.c src/detection/displayserver/wayland.c src/detection/displayserver/xcb.c diff --git a/src/detection/temps.c b/src/detection/temps.c index 485e0b79e..4fcdc5827 100644 --- a/src/detection/temps.c +++ b/src/detection/temps.c @@ -7,10 +7,7 @@ static bool isTempFile(const char* name) { return - name[0] == 't' && - name[1] == 'e' && - name[2] == 'm' && - name[3] == 'p' && + strncmp(name, "temp", 4) == 0 && name[4] >= '0' && name[4] <= '9' && strncmp(name + 5, "_input", 6) == 0; From dcaeab7e9657485ac3893f88fdc4095656478f2b Mon Sep 17 00:00:00 2001 From: xzvf Date: Thu, 16 Jun 2022 13:13:36 +0200 Subject: [PATCH 04/55] Rewrite to use ffDetectTemps. --- src/fastfetch.c | 2 +- src/modules/cpu.c | 77 +++++++++++------------------------------------ 2 files changed, 19 insertions(+), 60 deletions(-) diff --git a/src/fastfetch.c b/src/fastfetch.c index c819da278..241feb17a 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -236,7 +236,7 @@ static inline void printCommandHelp(const char* command) } else if(strcasecmp(command, "cpu-format") == 0) { - constructAndPrintCommandHelpFormat("cpu", "{2} ({7}) @ {15}GHz ({8}°C)", 15, + constructAndPrintCommandHelpFormat("cpu", "{2} ({7}) @ {15}GHz", 15, "CPU name", "Prettified CPU name", "CPU Vendor name (Vendor ID)", diff --git a/src/modules/cpu.c b/src/modules/cpu.c index 0b898c6b5..61f23ad29 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -6,13 +6,16 @@ #define FF_CPU_MODULE_NAME "CPU" #define FF_CPU_NUM_FORMAT_ARGS 15 -// TODO: possibly add a config option for this -char *FF_CPU_THERMAL_ZONES[] = { - "x86_pkg_temp", // x86 CPU package temperature - "cpu-thermal" // Raspberry Pi CPU temperature (possibly other ARM platforms aswell) -}; -static double parseHz(FFstrbuf* content) +static long parseLong(const FFstrbuf* content) { + long value; + if(content->length == 0 || (sscanf(content->chars, "%li", &value) != 1)) + return -1; + return value; + +} + +static double parseHz(const FFstrbuf* content) { if(content->length == 0) return 0; @@ -111,57 +114,16 @@ void ffPrintCPU(FFinstance* instance) if(numProcs <= 1) numProcs = physicalCores; - double cpuPackageTemp = __DBL_MAX__; - // enumerate thermal zones until we either find the x86_pkg_temp zone or we run out of zones. - // NOTE: This should generally run just a couple times (~10 iterations), but maybe we should put this behind allowSlowOperations? - for (int tzIndex = 0;; tzIndex++) - { - char path[64]; - snprintf(path, sizeof(path), "/sys/class/thermal/thermal_zone%d/type", tzIndex); - FFstrbuf fileContents; - ffStrbufInit(&fileContents); - - if (!ffGetFileContent(path, &fileContents)) - { - // this termal zone does not exist - ffStrbufDestroy(&fileContents); + const FFTempsResult *temps = ffDetectTemps(&instance); + double cpuTemp = 0.0/0.0; + for(uint32_t i = 0; i< temps->values.length; i++) { + FFTempValue *v = ffListGet(&temps->values, i); + if(ffStrbufFirstIndexS(&v->name, "cpu") == v->name.length + && ffStrbufCompS(&v->name, "k10temp") != 0 + && ffStrbufCompS(&v->name, "coretemp") != 0) break; - } - - bool isTargetTZ = false; - for(size_t i = 0; i < sizeof(FF_CPU_THERMAL_ZONES) / sizeof(FF_CPU_THERMAL_ZONES[0]); i++) - { - if (strncmp(fileContents.chars, FF_CPU_THERMAL_ZONES[i], fileContents.length) == 0) { - isTargetTZ = true; - break; - } - } - if(isTargetTZ) - { - snprintf(path, sizeof(path), "/sys/class/thermal/thermal_zone%d/temp", tzIndex); - ffStrbufInit(&fileContents); - if (!ffGetFileContent(path, &fileContents)) - { - ffStrbufDestroy(&fileContents); - break; - } - // The temperature is encoded in millicelsius, meaning "49000" is 49C - // NOTE: for strtol errno MUST be manually reset (see manpage) - errno = 0; - long sensorValue = strtol(fileContents.chars, NULL, 10); - if (!errno) - cpuPackageTemp = (float)sensorValue / 1000.0f; // convert to celsius - ffStrbufDestroy(&fileContents); - break; - } - ffStrbufDestroy(&fileContents); - - } - - if (cpuPackageTemp == __DBL_MAX__) - { - ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, "Could not find a CPU thermal zone"); + cpuTemp = (double) parseLong(&v->value) / 1000.0f; } double ghz = biosLimit; @@ -223,9 +185,6 @@ void ffPrintCPU(FFinstance* instance) if(ghz > 0) ffStrbufAppendF(&cpu, " @ %.9gGHz", ghz); - - if (cpuPackageTemp != __DBL_MAX__) - ffStrbufAppendF(&cpu, " (%g°C)", cpuPackageTemp); ffPrintAndWriteToCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpuKey, &cpu, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &name}, @@ -235,7 +194,7 @@ void ffPrintCPU(FFinstance* instance) {FF_FORMAT_ARG_TYPE_INT, &numProcsAvailable}, {FF_FORMAT_ARG_TYPE_INT, &physicalCores}, {FF_FORMAT_ARG_TYPE_INT, &numProcs}, - {FF_FORMAT_ARG_TYPE_DOUBLE, &cpuPackageTemp}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &cpuTemp}, {FF_FORMAT_ARG_TYPE_DOUBLE, &biosLimit}, {FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMaxFreq}, {FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMinFreq}, From c491c119888e2b721189200c13bb0e0c788edc3f Mon Sep 17 00:00:00 2001 From: xzvf Date: Thu, 16 Jun 2022 13:15:48 +0200 Subject: [PATCH 05/55] update DEVELOPMENT.md --- DEVELOPMENT.md | 1 - 1 file changed, 1 deletion(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index b814868fa..a1984236c 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -12,7 +12,6 @@ Here i just add things that are easy to forget. - `libffprint`: contains the printing functions, logos, format etc - `fastfetch` and `flashfetch`: Executables, that initialize the config of libffprint. Fist one at runtime, second one at compile time - [ ] Better OS output for all possible combinations of /etc/os-release variables. -- [X] Expose temperatures to CPU format string - [ ] Expose temperatures to GPU format string - [ ] Find wayland compositor by looking at \${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY:-wayland-0} - [ ] Make LocalIP module more configurable From ea53833466494c4c672deb0542ee00f875a855c6 Mon Sep 17 00:00:00 2001 From: xzvf Date: Thu, 16 Jun 2022 13:18:38 +0200 Subject: [PATCH 06/55] Remove unnecessary checks for content->length --- src/modules/cpu.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/modules/cpu.c b/src/modules/cpu.c index 61f23ad29..b24d54b07 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -7,9 +7,10 @@ #define FF_CPU_NUM_FORMAT_ARGS 15 -static long parseLong(const FFstrbuf* content) { +static long parseLong(const FFstrbuf* content) +{ long value; - if(content->length == 0 || (sscanf(content->chars, "%li", &value) != 1)) + if(sscanf(content->chars, "%li", &value) != 1) return -1; return value; @@ -17,9 +18,6 @@ static long parseLong(const FFstrbuf* content) { static double parseHz(const FFstrbuf* content) { - if(content->length == 0) - return 0; - double herz; if(sscanf(content->chars, "%lf", &herz) != 1) return 0; @@ -117,7 +115,8 @@ void ffPrintCPU(FFinstance* instance) const FFTempsResult *temps = ffDetectTemps(&instance); double cpuTemp = 0.0/0.0; - for(uint32_t i = 0; i< temps->values.length; i++) { + for(uint32_t i = 0; i< temps->values.length; i++) + { FFTempValue *v = ffListGet(&temps->values, i); if(ffStrbufFirstIndexS(&v->name, "cpu") == v->name.length && ffStrbufCompS(&v->name, "k10temp") != 0 From 1eff343733be14205ff53319d2e9c2f4ca8efa19 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 16 Jun 2022 13:36:00 +0200 Subject: [PATCH 07/55] Finish exposing temperatur to cpu format --- presets/verbose | 2 +- src/modules/cpu.c | 37 +++++++++++++++++++------------------ 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/presets/verbose b/presets/verbose index 9694e4f6b..a6f4b307d 100644 --- a/presets/verbose +++ b/presets/verbose @@ -17,7 +17,7 @@ --cursor-format "Theme: {}; Size: {}" --terminal-format "Process: {}; Path: {}; Exe: {}" --terminal-font-format "Raw: {}; Name: {}; Size: {}; Styles: {}; Pretty: {}" ---cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; bios: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}" +--cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; bios: {}; temperatur: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}" --cpu-usage-format "Percentage: {}" --gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}" --memory-format "Used: {}; Total: {}; Percentage: {}" diff --git a/src/modules/cpu.c b/src/modules/cpu.c index b24d54b07..1d66d6b0d 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -6,17 +6,16 @@ #define FF_CPU_MODULE_NAME "CPU" #define FF_CPU_NUM_FORMAT_ARGS 15 - static long parseLong(const FFstrbuf* content) { long value; if(sscanf(content->chars, "%li", &value) != 1) return -1; - return value; + return value; } -static double parseHz(const FFstrbuf* content) +static double parseDouble(const FFstrbuf* content) { double herz; if(sscanf(content->chars, "%lf", &herz) != 1) @@ -34,7 +33,7 @@ static double getGhz(const char* policyFile, const char* cpuFile) if(content.length == 0) ffGetFileContent(cpuFile, &content); - double herz = parseHz(&content); + double herz = parseDouble(&content); ffStrbufDestroy(&content); @@ -89,7 +88,7 @@ void ffPrintCPU(FFinstance* instance) fclose(cpuinfo); - double procGhz = parseHz(&procGhzString) / 1000.0; //to GHz + double procGhz = parseDouble(&procGhzString) / 1000.0; //to GHz ffStrbufDestroy(&procGhzString); double biosLimit = getGhz("/sys/devices/system/cpu/cpufreq/policy0/bios_limit", "/sys/devices/system/cpu/cpu0/cpufreq/bios_limit"); @@ -112,19 +111,6 @@ void ffPrintCPU(FFinstance* instance) if(numProcs <= 1) numProcs = physicalCores; - - const FFTempsResult *temps = ffDetectTemps(&instance); - double cpuTemp = 0.0/0.0; - for(uint32_t i = 0; i< temps->values.length; i++) - { - FFTempValue *v = ffListGet(&temps->values, i); - if(ffStrbufFirstIndexS(&v->name, "cpu") == v->name.length - && ffStrbufCompS(&v->name, "k10temp") != 0 - && ffStrbufCompS(&v->name, "coretemp") != 0) - break; - cpuTemp = (double) parseLong(&v->value) / 1000.0f; - } - double ghz = biosLimit; if(ghz == 0) ghz = scalingMaxFreq; @@ -164,6 +150,21 @@ void ffPrintCPU(FFinstance* instance) ffStrbufSubstrBeforeFirstC(&namePretty, '@'); //Cut the speed output in the name as we append our own ffStrbufTrimRight(&namePretty, ' '); //If we removed the @ in previous step there was most likely a space before it + const FFTempsResult *temps = ffDetectTemps(&instance); + double cpuTemp = 0.0/0.0; //NaN + + for(uint32_t i = 0; i< temps->values.length; i++) + { + FFTempValue *v = ffListGet(&temps->values, i); + if( + ffStrbufFirstIndexS(&v->name, "cpu") == v->name.length && + ffStrbufCompS(&v->name, "k10temp") != 0 && + ffStrbufCompS(&v->name, "coretemp") != 0 + ) break; + + cpuTemp = (double) parseLong(&v->value) / 1000.0; + } + FFstrbuf cpu; ffStrbufInitA(&cpu, 128); From 85a36ae7efc4f9c45ba52000b15f04b29bda9ff8 Mon Sep 17 00:00:00 2001 From: Samisafool Date: Thu, 16 Jun 2022 17:10:59 +0530 Subject: [PATCH 08/55] fix spelling of temperature --- presets/verbose | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/presets/verbose b/presets/verbose index a6f4b307d..6c8b92a13 100644 --- a/presets/verbose +++ b/presets/verbose @@ -17,7 +17,7 @@ --cursor-format "Theme: {}; Size: {}" --terminal-format "Process: {}; Path: {}; Exe: {}" --terminal-font-format "Raw: {}; Name: {}; Size: {}; Styles: {}; Pretty: {}" ---cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; bios: {}; temperatur: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}" +--cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; bios: {}; temperature: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}" --cpu-usage-format "Percentage: {}" --gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}" --memory-format "Used: {}; Total: {}; Percentage: {}" From 481affa50abe8990f6200b576b1c941c56946f54 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 16 Jun 2022 14:39:01 +0200 Subject: [PATCH 09/55] Fix cpu temp detection --- presets/verbose | 2 +- src/common/format.c | 1 + src/modules/cpu.c | 20 +++++++++++--------- 3 files changed, 13 insertions(+), 10 deletions(-) diff --git a/presets/verbose b/presets/verbose index 6c8b92a13..c45314905 100644 --- a/presets/verbose +++ b/presets/verbose @@ -17,7 +17,7 @@ --cursor-format "Theme: {}; Size: {}" --terminal-format "Process: {}; Path: {}; Exe: {}" --terminal-font-format "Raw: {}; Name: {}; Size: {}; Styles: {}; Pretty: {}" ---cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; bios: {}; temperature: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}" +--cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; temperature: {}; bios: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}" --cpu-usage-format "Percentage: {}" --gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}" --memory-format "Used: {}; Total: {}; Percentage: {}" diff --git a/src/common/format.c b/src/common/format.c index dd1d39038..d2077ff78 100644 --- a/src/common/format.c +++ b/src/common/format.c @@ -72,6 +72,7 @@ static inline bool formatArgSet(const FFformatarg* arg) { return arg->value != NULL && ( (arg->type == FF_FORMAT_ARG_TYPE_DOUBLE && *(double*)arg->value > 0) || + (arg->type == FF_FORMAT_ARG_TYPE_DOUBLE && *(double*)arg->value == *(double*)arg->value) || //NaN (arg->type == FF_FORMAT_ARG_TYPE_INT && *(int*)arg->value > 0) || (arg->type == FF_FORMAT_ARG_TYPE_STRBUF && ((FFstrbuf*)arg->value)->length > 0) || (arg->type == FF_FORMAT_ARG_TYPE_STRING && *(const char*)arg->value != '\0') || diff --git a/src/modules/cpu.c b/src/modules/cpu.c index 1d66d6b0d..86e4ef3f6 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -150,19 +150,21 @@ void ffPrintCPU(FFinstance* instance) ffStrbufSubstrBeforeFirstC(&namePretty, '@'); //Cut the speed output in the name as we append our own ffStrbufTrimRight(&namePretty, ' '); //If we removed the @ in previous step there was most likely a space before it - const FFTempsResult *temps = ffDetectTemps(&instance); + const FFTempsResult *temps = ffDetectTemps(instance); double cpuTemp = 0.0/0.0; //NaN - for(uint32_t i = 0; i< temps->values.length; i++) + for(uint32_t i = 0; i < temps->values.length; i++) { - FFTempValue *v = ffListGet(&temps->values, i); - if( - ffStrbufFirstIndexS(&v->name, "cpu") == v->name.length && - ffStrbufCompS(&v->name, "k10temp") != 0 && - ffStrbufCompS(&v->name, "coretemp") != 0 - ) break; + FFTempValue* value = ffListGet(&temps->values, i); - cpuTemp = (double) parseLong(&v->value) / 1000.0; + if( + ffStrbufFirstIndexS(&value->name, "cpu") < value->name.length || + ffStrbufCompS(&value->name, "k10temp") == 0 || + ffStrbufCompS(&value->name, "coretemp") == 0 + ) { + cpuTemp = (double) parseLong(&value->value) / 1000.0; + break; + } } FFstrbuf cpu; From 5e96ba838437a1ea66b1ff6ab0e7ca2f0685ab9c Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 16 Jun 2022 14:55:02 +0200 Subject: [PATCH 10/55] Fix cpu temp detection the second --- src/modules/cpu.c | 51 +++++++++++++++++++++------------------------ src/util/FFstrbuf.c | 9 ++++++++ src/util/FFstrbuf.h | 2 ++ 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/src/modules/cpu.c b/src/modules/cpu.c index 86e4ef3f6..be1b5bfdf 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -6,24 +6,6 @@ #define FF_CPU_MODULE_NAME "CPU" #define FF_CPU_NUM_FORMAT_ARGS 15 -static long parseLong(const FFstrbuf* content) -{ - long value; - if(sscanf(content->chars, "%li", &value) != 1) - return -1; - - return value; -} - -static double parseDouble(const FFstrbuf* content) -{ - double herz; - if(sscanf(content->chars, "%lf", &herz) != 1) - return 0; - - return herz; -} - static double getGhz(const char* policyFile, const char* cpuFile) { FFstrbuf content; @@ -33,10 +15,14 @@ static double getGhz(const char* policyFile, const char* cpuFile) if(content.length == 0) ffGetFileContent(cpuFile, &content); - double herz = parseDouble(&content); + double herz = ffStrbufToDouble(&content); ffStrbufDestroy(&content); + //ffStrbufToDouble failed + if(herz != herz) + return 0; + herz /= 1000.0; //to MHz return herz / 1000.0; //to GHz } @@ -88,7 +74,12 @@ void ffPrintCPU(FFinstance* instance) fclose(cpuinfo); - double procGhz = parseDouble(&procGhzString) / 1000.0; //to GHz + double procGhz = ffStrbufToDouble(&procGhzString); + if(procGhz != procGhz) + procGhz = 0; //NaN + else + procGhz /= 1000.0; //To GHz + ffStrbufDestroy(&procGhzString); double biosLimit = getGhz("/sys/devices/system/cpu/cpufreq/policy0/bios_limit", "/sys/devices/system/cpu/cpu0/cpufreq/bios_limit"); @@ -158,13 +149,19 @@ void ffPrintCPU(FFinstance* instance) FFTempValue* value = ffListGet(&temps->values, i); if( - ffStrbufFirstIndexS(&value->name, "cpu") < value->name.length || - ffStrbufCompS(&value->name, "k10temp") == 0 || - ffStrbufCompS(&value->name, "coretemp") == 0 - ) { - cpuTemp = (double) parseLong(&value->value) / 1000.0; - break; - } + ffStrbufFirstIndexS(&value->name, "cpu") == value->name.length && + ffStrbufCompS(&value->name, "k10temp") != 0 && + ffStrbufCompS(&value->name, "coretemp") != 0 + ) continue; + + double temp = ffStrbufToDouble(&value->value); + + //NaN + if(temp != temp) + continue; + + cpuTemp = temp / 1000.0; + break; } FFstrbuf cpu; diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index 92d33be4f..354847063 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -526,6 +526,15 @@ void ffStrbufPutTo(const FFstrbuf* strbuf, FILE* file) fputc('\n', file); } +double ffStrbufToDouble(const FFstrbuf* strbuf) +{ + double value; + if(sscanf(strbuf->chars, "%lf", &value) != 1) + return 0.0 / 0.0; //NaN + + return value; +} + void ffStrbufDestroy(FFstrbuf* strbuf) { free(strbuf->chars); diff --git a/src/util/FFstrbuf.h b/src/util/FFstrbuf.h index 076c4e467..1cd076fec 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -93,6 +93,8 @@ bool ffStrbufRemoveIgnCaseEndS(FFstrbuf* strbuf, const char* end); void ffStrbufWriteTo(const FFstrbuf* strbuf, FILE* file); void ffStrbufPutTo(const FFstrbuf* strbuf, FILE* file); +double ffStrbufToDouble(const FFstrbuf* strbuf); + void ffStrbufDestroy(FFstrbuf* strbuf); #endif From 36964d6b1d429cc9b647e512679d5195b2199d6a Mon Sep 17 00:00:00 2001 From: draumaz Date: Thu, 16 Jun 2022 21:02:20 -0700 Subject: [PATCH 11/55] Initial Alpine addition --- src/logo/builtin.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 0360d7b2f..2ae33227b 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -43,6 +43,38 @@ static const FFlogo* getLogoNone() FF_LOGO_RETURN } +static const FFlogo* getLogoAlpine() +{ + FF_LOGO_INIT + FF_LOGO_NAMES("alpine", "alpinelinux", "alpine-linux") + FF_LOGO_LINES( + " .hddddddddddddddddddddddh.\n" + " :dddddddddddddddddddddddddd:\n" + " /dddddddddddddddddddddddddddd/\n" + " +dddddddddddddddddddddddddddddd+\n" + " `sdddddddddddddddddddddddddddddddds`\n" + " `ydddddddddddd++hdddddddddddddddddddy`\n" + ".hddddddddddd+` `+ddddh:-sdddddddddddh. \n" + "hdddddddddd+` `+y: .sddddddddddh\n" + "ddddddddh+` `//` `.` -sddddddddd\n" + "ddddddh+` `/hddh/` `:s- -sddddddd\n" + "ddddh+` `/+/dddddh/` `+s- -sddddd\n" + "ddd+` `/o` :dddddddh/` `oy- .yddd\n" + "hdddyo+ohddyosdddddddddho+oydddy++ohdddh\n" + ".hddddddddddddddddddddddddddddddddddddh.\n" + " `yddddddddddddddddddddddddddddddddddy`\n" + " `sdddddddddddddddddddddddddddddddds`\n" + " +dddddddddddddddddddddddddddddd+\n" + " /dddddddddddddddddddddddddddd/\n" + " :dddddddddddddddddddddddddd:\n" + " .hddddddddddddddddddddddh."; + ) + FF_LOGO_COLORS( + "34" //blue + ) + FF_LOGO_RETURN +} + static const FFlogo* getLogoAndroid() { FF_LOGO_INIT From 517d80eadced7a0a02afaeb0fe25ef971a3a3cde Mon Sep 17 00:00:00 2001 From: draumaz Date: Thu, 16 Jun 2022 21:03:39 -0700 Subject: [PATCH 12/55] update getAll function --- src/logo/builtin.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 2ae33227b..8a1a4e78e 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -1466,6 +1466,7 @@ GetLogoMethod* ffLogoBuiltinGetAll() static GetLogoMethod logoMethods[] = { ffLogoBuiltinGetUnknown, getLogoNone, + getLogoAlpine, getLogoAndroid, getLogoAndroidSmall, getLogoArch, From bb897f03f09870b67289de8ad5a0ca0760b44364 Mon Sep 17 00:00:00 2001 From: draumaz Date: Thu, 16 Jun 2022 21:08:39 -0700 Subject: [PATCH 13/55] add small logo --- src/logo/builtin.c | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 8a1a4e78e..e5373e988 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -75,6 +75,24 @@ static const FFlogo* getLogoAlpine() FF_LOGO_RETURN } +static const FFlogo* getLogoAlpineSmall() +{ + FF_LOGO_INIT + FF_LOGO_NAMES("alpine_small", "alpine-linux-small") + FF_LOGO_LINES( + " /\\ /\\n" + " // \\ \\n" + " // \\ \\n" + "/// \\ \\n" + "// \\ \\n" + " \\n" + ) + FF_LOGO_COLORS( + "34" //blue + ) + FF_LOGO_RETURN +} + static const FFlogo* getLogoAndroid() { FF_LOGO_INIT @@ -1467,6 +1485,7 @@ GetLogoMethod* ffLogoBuiltinGetAll() ffLogoBuiltinGetUnknown, getLogoNone, getLogoAlpine, + getLogoAlpineSmall, getLogoAndroid, getLogoAndroidSmall, getLogoArch, From b150e8d106bedd78af807e338f7fa3483730ff9d Mon Sep 17 00:00:00 2001 From: draumaz Date: Thu, 16 Jun 2022 21:10:23 -0700 Subject: [PATCH 14/55] whoops --- src/logo/builtin.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/logo/builtin.c b/src/logo/builtin.c index e5373e988..7d74ddbfd 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -80,11 +80,11 @@ static const FFlogo* getLogoAlpineSmall() FF_LOGO_INIT FF_LOGO_NAMES("alpine_small", "alpine-linux-small") FF_LOGO_LINES( - " /\\ /\\n" - " // \\ \\n" - " // \\ \\n" - "/// \\ \\n" - "// \\ \\n" + " /\\ /\\\n" + " // \\ \\\n" + " // \\ \\\n" + "/// \\ \\\n" + "// \\ \\\n" " \\n" ) FF_LOGO_COLORS( From c80f8cf42221cde4a9bccededdd98026cd36aec3 Mon Sep 17 00:00:00 2001 From: draumaz Date: Thu, 16 Jun 2022 21:11:14 -0700 Subject: [PATCH 15/55] further fixes --- src/logo/builtin.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/logo/builtin.c b/src/logo/builtin.c index 7d74ddbfd..ca2524734 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -85,7 +85,7 @@ static const FFlogo* getLogoAlpineSmall() " // \\ \\\n" "/// \\ \\\n" "// \\ \\\n" - " \\n" + " \\" ) FF_LOGO_COLORS( "34" //blue From 6e3e7172247b0c5955184956df19ceb8e48c869f Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Fri, 17 Jun 2022 18:15:36 +0200 Subject: [PATCH 16/55] ---error options --- src/common/caching.c | 28 ++-- src/common/format.c | 34 +---- src/common/init.c | 109 ++++++---------- src/common/printing.c | 92 ++++++++----- src/data/config.txt | 38 ++++++ src/data/help.txt | 80 ++---------- src/data/help_format.txt | 6 - src/fastfetch.c | 256 +++++++++++++++++++++++-------------- src/fastfetch.h | 125 ++++++++---------- src/modules/battery.c | 12 +- src/modules/cpu.c | 8 +- src/modules/cpuUsage.c | 8 +- src/modules/cursor.c | 16 +-- src/modules/date.c | 6 +- src/modules/datetime.c | 10 +- src/modules/de.c | 10 +- src/modules/disk.c | 16 +-- src/modules/font.c | 12 +- src/modules/gpu.c | 8 +- src/modules/host.c | 6 +- src/modules/icons.c | 12 +- src/modules/kernel.c | 6 +- src/modules/locale.c | 6 +- src/modules/localip.c | 25 ++-- src/modules/memory.c | 10 +- src/modules/opencl.c | 8 +- src/modules/opengl.c | 8 +- src/modules/os.c | 8 +- src/modules/packages.c | 8 +- src/modules/player.c | 8 +- src/modules/processes.c | 6 +- src/modules/publicip.c | 8 +- src/modules/resolution.c | 8 +- src/modules/shell.c | 8 +- src/modules/song.c | 8 +- src/modules/terminal.c | 8 +- src/modules/terminalfont.c | 28 ++-- src/modules/theme.c | 10 +- src/modules/time.c | 6 +- src/modules/uptime.c | 6 +- src/modules/vulkan.c | 8 +- src/modules/wm.c | 8 +- src/modules/wmtheme.c | 28 ++-- 43 files changed, 551 insertions(+), 568 deletions(-) diff --git a/src/common/caching.c b/src/common/caching.c index e5e95ba8d..804cac2c0 100644 --- a/src/common/caching.c +++ b/src/common/caching.c @@ -77,7 +77,7 @@ void ffCacheClose(FFcache* cache) fclose(cache->split); } -static bool printCachedValue(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat) +static bool printCachedValue(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs) { FFstrbuf content; ffStrbufInitA(&content, 512); @@ -95,7 +95,7 @@ static bool printCachedValue(FFinstance* instance, const char* moduleName, const { uint32_t nullByteIndex = ffStrbufNextIndexC(&content, startIndex, '\0'); uint8_t moduleIndex = (moduleCounter == 1 && nullByteIndex == content.length) ? 0 : moduleCounter; - ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat); + ffPrintLogoAndKey(instance, moduleName, moduleIndex, &moduleArgs->key); puts(content.chars + startIndex); startIndex = nullByteIndex + 1; ++moduleCounter; @@ -106,7 +106,7 @@ static bool printCachedValue(FFinstance* instance, const char* moduleName, const return moduleCounter > 1; } -static bool printCachedFormat(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numArgs) +static bool printCachedFormat(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, uint32_t numArgs) { FFstrbuf content; ffStrbufInitA(&content, 512); @@ -134,7 +134,7 @@ static bool printCachedFormat(FFinstance* instance, const char* moduleName, cons if(argumentCounter == numArgs) { uint8_t moduleIndex = (moduleCounter == 1 && nullByteIndex == content.length) ? 0 : moduleCounter; - ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, formatString, NULL, numArgs, arguments); + ffPrintFormat(instance, moduleName, moduleIndex, moduleArgs, numArgs, arguments); ++moduleCounter; argumentCounter = 0; } @@ -148,27 +148,27 @@ static bool printCachedFormat(FFinstance* instance, const char* moduleName, cons return moduleCounter > 1; } -bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numArgs) +bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, uint32_t numArgs) { if(instance->config.recache) return false; - if(formatString == NULL || formatString->length == 0) - return printCachedValue(instance, moduleName, customKeyFormat); + if(moduleArgs->outputFormat.length == 0) + return printCachedValue(instance, moduleName, moduleArgs); else - return printCachedFormat(instance, moduleName, customKeyFormat, formatString, numArgs); + return printCachedFormat(instance, moduleName, moduleArgs, numArgs); } -void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, FFcache* cache, const FFstrbuf* value, const FFstrbuf* formatString, uint32_t numArgs, const FFformatarg* arguments) +void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFcache* cache, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments) { - if(formatString == NULL || formatString->length == 0) + if(moduleArgs->outputFormat.length == 0) { - ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat); + ffPrintLogoAndKey(instance, moduleName, moduleIndex, &moduleArgs->key); ffStrbufPutTo(value, stdout); } else { - ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, formatString, NULL, numArgs, arguments); + ffPrintFormat(instance, moduleName, moduleIndex, moduleArgs, numArgs, arguments); } if(cache->value != NULL) @@ -191,10 +191,10 @@ void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8 } } -void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* value, const FFstrbuf* formatString, uint32_t numArgs, const FFformatarg* arguments) +void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments) { FFcache cache; ffCacheOpenWrite(instance, moduleName, &cache); - ffPrintAndAppendToCache(instance, moduleName, 0, customKeyFormat, &cache, value, formatString, numArgs, arguments); + ffPrintAndAppendToCache(instance, moduleName, 0, moduleArgs, &cache, value, numArgs, arguments); ffCacheClose(&cache); } diff --git a/src/common/format.c b/src/common/format.c index d2077ff78..e3a912469 100644 --- a/src/common/format.c +++ b/src/common/format.c @@ -32,15 +32,6 @@ void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg) } } -static inline bool placeholderValueIsForError(const FFstrbuf* placeholderValue) -{ - return - ffStrbufIgnCaseCompS(placeholderValue, "e") == 0 || - ffStrbufIgnCaseCompS(placeholderValue, "error") == 0 || - ffStrbufIgnCaseCompS(placeholderValue, "0") == 0 - ; -} - static inline uint32_t getArgumentIndex(const FFstrbuf* placeholderValue) { uint32_t result = UINT32_MAX; @@ -82,7 +73,7 @@ static inline bool formatArgSet(const FFformatarg* arg) ); } -void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFstrbuf* error, uint32_t numArgs, const FFformatarg* arguments) +void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t numArgs, const FFformatarg* arguments) { uint32_t argCounter = 0; @@ -129,13 +120,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFst while(i < formatstr->length && formatstr->chars[i] != '}') ffStrbufAppendC(&placeholderValue, formatstr->chars[i++]); - // test for error, if so print it - if(placeholderValueIsForError(&placeholderValue)) { - ffStrbufAppend(buffer, error); - ffStrbufDestroy(&placeholderValue); - continue; - } - // test if for stop, if so break the loop if(placeholderValue.length == 1 && placeholderValue.chars[0] == '-') { @@ -187,14 +171,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFst { ffStrbufSubstrAfter(&placeholderValue, 0); - // continue if an error is set - if(placeholderValueIsForError(&placeholderValue) && error != NULL && error->length > 0) - { - ++numOpenIfs; - ffStrbufDestroy(&placeholderValue); - continue; - } - uint32_t index = getArgumentIndex(&placeholderValue); // testing for an invalid index @@ -224,14 +200,6 @@ void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFst { ffStrbufSubstrAfter(&placeholderValue, 0); - //continue if an error os not set - if(placeholderValueIsForError(&placeholderValue) && (error == NULL || error->length == 0)) - { - ++numOpenNotIfs; - ffStrbufDestroy(&placeholderValue); - continue; - } - uint32_t index = getArgumentIndex(&placeholderValue); // testing for an invalid index diff --git a/src/common/init.c b/src/common/init.c index 607a389a3..27ba23f86 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -102,6 +102,13 @@ static void initState(FFstate* state) initCacheDir(state); } +static void initModuleArg(FFModuleArgs* args) +{ + ffStrbufInitA(&args->key, 0); + ffStrbufInitA(&args->outputFormat, 0); + ffStrbufInitA(&args->errorFormat, 0); +} + static void defaultConfig(FFinstance* instance) { ffStrbufInit(&instance->config.logoSource); @@ -128,74 +135,40 @@ static void defaultConfig(FFinstance* instance) instance->config.glType = FF_GL_TYPE_AUTO; instance->config.pipe = false; - ffStrbufInitA(&instance->config.osFormat, 0); - ffStrbufInitA(&instance->config.osKey, 0); - ffStrbufInitA(&instance->config.hostFormat, 0); - ffStrbufInitA(&instance->config.hostKey, 0); - ffStrbufInitA(&instance->config.kernelFormat, 0); - ffStrbufInitA(&instance->config.kernelKey, 0); - ffStrbufInitA(&instance->config.uptimeFormat, 0); - ffStrbufInitA(&instance->config.uptimeKey, 0); - ffStrbufInitA(&instance->config.processesFormat, 0); - ffStrbufInitA(&instance->config.processesKey, 0); - ffStrbufInitA(&instance->config.packagesFormat, 0); - ffStrbufInitA(&instance->config.packagesKey, 0); - ffStrbufInitA(&instance->config.shellFormat, 0); - ffStrbufInitA(&instance->config.shellKey, 0); - ffStrbufInitA(&instance->config.resolutionFormat, 0); - ffStrbufInitA(&instance->config.resolutionKey, 0); - ffStrbufInitA(&instance->config.deFormat, 0); - ffStrbufInitA(&instance->config.deKey, 0); - ffStrbufInitA(&instance->config.wmFormat, 0); - ffStrbufInitA(&instance->config.wmKey, 0); - ffStrbufInitA(&instance->config.wmThemeFormat, 0); - ffStrbufInitA(&instance->config.wmThemeKey, 0); - ffStrbufInitA(&instance->config.themeFormat, 0); - ffStrbufInitA(&instance->config.themeKey, 0); - ffStrbufInitA(&instance->config.iconsFormat, 0); - ffStrbufInitA(&instance->config.iconsKey, 0); - ffStrbufInitA(&instance->config.fontFormat, 0); - ffStrbufInitA(&instance->config.fontKey, 0); - ffStrbufInitA(&instance->config.cursorKey, 0); - ffStrbufInitA(&instance->config.cursorFormat, 0); - ffStrbufInitA(&instance->config.terminalFormat, 0); - ffStrbufInitA(&instance->config.terminalKey, 0); - ffStrbufInitA(&instance->config.termFontFormat, 0); - ffStrbufInitA(&instance->config.termFontKey, 0); - ffStrbufInitA(&instance->config.cpuFormat, 0); - ffStrbufInitA(&instance->config.cpuKey, 0); - ffStrbufInitA(&instance->config.cpuUsageFormat, 0); - ffStrbufInitA(&instance->config.cpuUsageKey, 0); - ffStrbufInitA(&instance->config.gpuFormat, 0); - ffStrbufInitA(&instance->config.gpuKey, 0); - ffStrbufInitA(&instance->config.memoryFormat, 0); - ffStrbufInitA(&instance->config.memoryKey, 0); - ffStrbufInitA(&instance->config.diskFormat, 0); - ffStrbufInitA(&instance->config.diskKey, 0); - ffStrbufInitA(&instance->config.batteryFormat, 0); - ffStrbufInitA(&instance->config.batteryKey, 0); - ffStrbufInitA(&instance->config.localeFormat, 0); - ffStrbufInitA(&instance->config.localeKey, 0); - ffStrbufInitA(&instance->config.localIpKey, 0); - ffStrbufInitA(&instance->config.localIpFormat, 0); - ffStrbufInitA(&instance->config.publicIpKey, 0); - ffStrbufInitA(&instance->config.publicIpFormat, 0); - ffStrbufInitA(&instance->config.playerKey, 0); - ffStrbufInitA(&instance->config.playerFormat, 0); - ffStrbufInitA(&instance->config.songKey, 0); - ffStrbufInitA(&instance->config.songFormat, 0); - ffStrbufInitA(&instance->config.dateTimeKey, 0); - ffStrbufInitA(&instance->config.dateTimeFormat, 0); - ffStrbufInitA(&instance->config.dateKey, 0); - ffStrbufInitA(&instance->config.dateFormat, 0); - ffStrbufInitA(&instance->config.timeKey, 0); - ffStrbufInitA(&instance->config.timeFormat, 0); - ffStrbufInitA(&instance->config.vulkanKey, 0); - ffStrbufInitA(&instance->config.vulkanFormat, 0); - ffStrbufInitA(&instance->config.openGLKey, 0); - ffStrbufInitA(&instance->config.openGLFormat, 0); - ffStrbufInitA(&instance->config.openCLKey, 0); - ffStrbufInitA(&instance->config.openCLFormat, 0); + initModuleArg(&instance->config.os); + initModuleArg(&instance->config.host); + initModuleArg(&instance->config.kernel); + initModuleArg(&instance->config.uptime); + initModuleArg(&instance->config.processes); + initModuleArg(&instance->config.packages); + initModuleArg(&instance->config.shell); + initModuleArg(&instance->config.resolution); + initModuleArg(&instance->config.de); + initModuleArg(&instance->config.wm); + initModuleArg(&instance->config.wmTheme); + initModuleArg(&instance->config.theme); + initModuleArg(&instance->config.icons); + initModuleArg(&instance->config.font); + initModuleArg(&instance->config.cursor); + initModuleArg(&instance->config.terminal); + initModuleArg(&instance->config.terminalFont); + initModuleArg(&instance->config.cpu); + initModuleArg(&instance->config.cpuUsage); + initModuleArg(&instance->config.gpu); + initModuleArg(&instance->config.memory); + initModuleArg(&instance->config.disk); + initModuleArg(&instance->config.battery); + initModuleArg(&instance->config.locale); + initModuleArg(&instance->config.localIP); + initModuleArg(&instance->config.publicIP); + initModuleArg(&instance->config.player); + initModuleArg(&instance->config.song); + initModuleArg(&instance->config.dateTime); + initModuleArg(&instance->config.date); + initModuleArg(&instance->config.time); + initModuleArg(&instance->config.vulkan); + initModuleArg(&instance->config.openGL); + initModuleArg(&instance->config.openCL); ffStrbufInitA(&instance->config.libPCI, 0); ffStrbufInitA(&instance->config.libVulkan, 0); diff --git a/src/common/printing.c b/src/common/printing.c index f09a5dc7a..0ed701344 100644 --- a/src/common/printing.c +++ b/src/common/printing.c @@ -10,6 +10,7 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod ffPrintColor(&instance->config.mainColor); } + //NULL check is required for modules with custom keys, e.g. disk with the folder path if(customKeyFormat == NULL || customKeyFormat->length == 0) { fputs(moduleName, stdout); @@ -21,7 +22,7 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod { FFstrbuf key; ffStrbufInit(&key); - ffParseFormatString(&key, customKeyFormat, NULL, 1, (FFformatarg[]){ + ffParseFormatString(&key, customKeyFormat, 1, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_UINT8, &moduleIndex} }); ffStrbufWriteTo(&key, stdout); @@ -37,44 +38,12 @@ void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t mod fputs(FASTFETCH_TEXT_MODIFIER_RESET, stdout); } -void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numFormatArgs, const char* message, ...) -{ - if(!instance->config.showErrors) - return; - - va_list arguments; - va_start(arguments, message); - - if(formatString == NULL || formatString->length == 0) - { - ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat); - fputs(FASTFETCH_TEXT_MODIFIER_ERROR, stdout); - vprintf(message, arguments); - puts(FASTFETCH_TEXT_MODIFIER_RESET); - } - else - { - FF_STRBUF_CREATE(error); - ffStrbufAppendVF(&error, message, arguments); - - // calloc sets all to 0 and FF_FORMAT_ARG_TYPE_NULL also has value 0 so we don't need to explictly set it - FFformatarg* nullArgs = calloc(numFormatArgs, sizeof(FFformatarg)); - - ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, formatString, &error, numFormatArgs, nullArgs); - - free(nullArgs); - ffStrbufDestroy(&error); - } - - va_end(arguments); -} - -void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, const FFstrbuf* error, uint32_t numArgs, const FFformatarg* arguments) +void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments) { FFstrbuf buffer; ffStrbufInitA(&buffer, 256); - ffParseFormatString(&buffer, formatString, error, numArgs, arguments); + ffParseFormatString(&buffer, format, numArgs, arguments); if(buffer.length > 0) { @@ -85,6 +54,59 @@ void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t m ffStrbufDestroy(&buffer); } +void ffPrintFormat(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments) +{ + ffPrintFormatString(instance, moduleName, moduleIndex, &moduleArgs->key, &moduleArgs->outputFormat, numArgs, arguments); +} + +static void printError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customErrorFormat, const char* message, va_list arguments) +{ + bool hasCustomErrorFormat = customErrorFormat != NULL && customErrorFormat->length > 0; + if(!hasCustomErrorFormat && !instance->config.showErrors) + return; + + if(hasCustomErrorFormat) + { + FFstrbuf error; + ffStrbufInit(&error); + ffStrbufAppendVF(&error, message, arguments); + + ffPrintFormatString(instance, moduleName, moduleIndex, customKeyFormat, customErrorFormat, 1, (FFformatarg[]) { + {FF_FORMAT_ARG_TYPE_STRBUF, &error} + }); + + ffStrbufDestroy(&error); + } + else + { + ffPrintLogoAndKey(instance, moduleName, moduleIndex, customKeyFormat); + + if(!instance->config.pipe) + fputs(FASTFETCH_TEXT_MODIFIER_ERROR, stdout); + + vprintf(message, arguments); + + if(!instance->config.pipe) + puts(FASTFETCH_TEXT_MODIFIER_RESET); + } +} + +void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customErrorFormat, const char* message, ...) +{ + va_list arguments; + va_start(arguments, message); + printError(instance, moduleName, moduleIndex, customKeyFormat, customErrorFormat, message, arguments); + va_end(arguments); +} + +void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...) +{ + va_list arguments; + va_start(arguments, message); + printError(instance, moduleName, moduleIndex, &moduleArgs->key, &moduleArgs->errorFormat, message, arguments); + va_end(arguments); +} + void ffPrintColor(const FFstrbuf* colorValue) { //If the color is not set, this would reset in \033[m, which resets everything. diff --git a/src/data/config.txt b/src/data/config.txt index 97acb8052..db0d7145c 100644 --- a/src/data/config.txt +++ b/src/data/config.txt @@ -237,6 +237,44 @@ #--opengl-format #--opencl-format +# Error options: +# Sets the format string to use if an error occured +# For information on format strings, see "fastfetch --help format". +# Each of them take the error as first and only argument. +# If one of them is set, the module will appear, even if --show-errors is not given. +#--os-error +#--host-error +#--kernel-error +#--uptime-error +#--processes-error +#--packages-error +#--shell-error +#--resolution-error +#--de-error +#--wm-error +#--wm-theme-error +#--theme-error +#--icons-error +#--font-error +#--cursor-error +#--terminal-error +#--terminal-font-error +#--cpu-error +#--cpu-usage-error +#--gpu-error +#--memory-error +#--disk-error +#--battery-error +#--locale-error +#--local-ip-error +#--public-ip-error +#--player-error +#--song-error +#--datetime-error +#--vulkan-error +#--opengl-error +#--opencl-error + # Library options: # Sets an user specific path to a library to load. # Must be a valid path to a library. diff --git a/src/data/help.txt b/src/data/help.txt index cc51455e1..73b99aa67 100644 --- a/src/data/help.txt +++ b/src/data/help.txt @@ -46,77 +46,17 @@ Display options: --disable-linewrap : weather to disable linewrap during the run --hide-cursor : weather to hide the cursor during the run -Format options: Provide the format string for custom output. Use fastfetch --help *-format for specific help. - --os-format - --host-format - --kernel-format - --uptime-format - --processes-format - --packages-format - --shell-format - --resolution-format - --de-format - --wm-format - --wm-theme-format - --theme-format - --icons-format - --font-format - --cursor-format - --terminal-format - --terminal-font-format - --cpu-format - --cpu-usage-format - --gpu-format - --memory-format - --disk-format - --battery-format - --locale-format - --local-ip-format - --public-ip-format - --player-format - --song-format - --datetime-format - --time-format - --date-format - --vulkan-format - --opengl-format - --opencl-format +General module options: + ---format : Sets the format string to use for each specific module. + To see how a format string works, use fastfetch --help format. + To see help about a specific format string, use fastfetch --help -format. -Key options: Provide a custom key for an output - --os-key - --host-key - --kernel-key - --uptime-key - --processes-key - --packages-key - --shell-key - --resolution-key : takes the resolution index as argument - --de-key - --wm-key - --wm-theme-key - --theme-key - --icons-key - --font-key - --cursor-key - --terminal-key - --terminal-font-key - --cpu-key - --cpu-usage-key - --gpu-key : takes the gpu index as format argument - --memory-key - --disk-key : takes the mount path as format argument - --battery-key : takes the battery index as format argument - --locale-key - --local-ip-key : takes the name of this network interface as format argument - --public-ip-key - --player-key - --song-key - --datetime-key - --time-key - --date-key - --vulkan-key - --opengl-key - --opencl-key + ---key : Sets the key to use for each specific module. + For modules which print multiple lines, the string is parsed as a format string with the index as first character. + + ---error : Sets the error format string to use for each specific module. + The error is given as the first and only argument. + Setting this for a module will cause it to appear, even if --show-errors is not given. Library options: Set the path of a library to load --lib-PCI diff --git a/src/data/help_format.txt b/src/data/help_format.txt index 6fc160477..87a4b1cc2 100644 --- a/src/data/help_format.txt +++ b/src/data/help_format.txt @@ -19,24 +19,18 @@ If a "{?}" is found without an opener, it is printed as is. To only print something if a variable is not set, do the same as with if, just replace every '?' with a '!'. For example to print a fallback for a second value if it is not set, use "{?2}{2}{?}{/2}Second value fallback{/}" -There is a special variable set if an error occured during detection. You can access it with "{e}", "{error}" o -You can use ifs and not ifs with it like with an index. For example use "{?e}some text{?}", to print a text if an - To stop formatting at any point in the format string, use "{-}". -For example to print an error instead of the normal output if it occured, prefix the format string with "{?e}{e}{- To print something with color, start a placeholder with a '#' and then the linux terminal color encoding. "\\033[" at the start, and an 'm' at the end is automatically added, so don't do that. A "{#}" is equivalent to a "{#0}" and resets everything to normal. For example to print something pink and underline, use "{#4;35}...{#}". -If not in a format string, fastfetch wraps errors with "{#1;31}error{#}", so you might want to do that to if you Information about what the numbers mean can be found here: https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_(Sele Which escape codes are supported and how they look is defined by your terminal. If a format string evaluates to an empty value, the whole line in the output will be discarded. You can therefore use --host-format " " to disable host output. Note that --host-format "" would evaluate as not set, and therefore use the built-in host format -This can be used to print nothing if an error occured: prefix the format string with "{?e}{-}{?}...". Format string is also the way to go to set a fixed value - just use one without placeholders. For example when running in headless mode, you could use "--resolution-format "Preferred". diff --git a/src/fastfetch.c b/src/fastfetch.c index 241feb17a..58e39d9dd 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -889,146 +889,210 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con ffValuestoreSet(&data->valuestore, value, separator + 1); } - //////////////////////// - //Format + Key options// - //////////////////////// + //////////////////////////////// + //Format + Key + Error options// + //////////////////////////////// - else if(strcasecmp(key, "--os-format") == 0) - optionParseString(key, value, &instance->config.osFormat); else if(strcasecmp(key, "--os-key") == 0) - optionParseString(key, value, &instance->config.osKey); - else if(strcasecmp(key, "--host-format") == 0) - optionParseString(key, value, &instance->config.hostFormat); + optionParseString(key, value, &instance->config.os.key); + else if(strcasecmp(key, "--os-format") == 0) + optionParseString(key, value, &instance->config.os.outputFormat); + else if(strcasecmp(key, "--os-error") == 0) + optionParseString(key, value, &instance->config.os.errorFormat); else if(strcasecmp(key, "--host-key") == 0) - optionParseString(key, value, &instance->config.hostKey); - else if(strcasecmp(key, "--kernel-format") == 0) - optionParseString(key, value, &instance->config.kernelFormat); + optionParseString(key, value, &instance->config.host.key); + else if(strcasecmp(key, "--host-format") == 0) + optionParseString(key, value, &instance->config.host.outputFormat); + else if(strcasecmp(key, "--host-error") == 0) + optionParseString(key, value, &instance->config.host.errorFormat); else if(strcasecmp(key, "--kernel-key") == 0) - optionParseString(key, value, &instance->config.kernelKey); - else if(strcasecmp(key, "--uptime-format") == 0) - optionParseString(key, value, &instance->config.uptimeFormat); + optionParseString(key, value, &instance->config.kernel.key); + else if(strcasecmp(key, "--kernel-format") == 0) + optionParseString(key, value, &instance->config.kernel.outputFormat); + else if(strcasecmp(key, "--kernel-error") == 0) + optionParseString(key, value, &instance->config.kernel.errorFormat); else if(strcasecmp(key, "--uptime-key") == 0) - optionParseString(key, value, &instance->config.uptimeKey); - else if(strcasecmp(key, "--processes-format") == 0) - optionParseString(key, value, &instance->config.processesFormat); + optionParseString(key, value, &instance->config.uptime.key); + else if(strcasecmp(key, "--uptime-format") == 0) + optionParseString(key, value, &instance->config.uptime.outputFormat); + else if(strcasecmp(key, "--uptime-error") == 0) + optionParseString(key, value, &instance->config.uptime.errorFormat); else if(strcasecmp(key, "--processes-key") == 0) - optionParseString(key, value, &instance->config.processesKey); - else if(strcasecmp(key, "--packages-format") == 0) - optionParseString(key, value, &instance->config.packagesFormat); + optionParseString(key, value, &instance->config.processes.key); + else if(strcasecmp(key, "--processes-format") == 0) + optionParseString(key, value, &instance->config.processes.outputFormat); + else if(strcasecmp(key, "--processes-error") == 0) + optionParseString(key, value, &instance->config.processes.errorFormat); else if(strcasecmp(key, "--packages-key") == 0) - optionParseString(key, value, &instance->config.packagesKey); - else if(strcasecmp(key, "--shell-format") == 0) - optionParseString(key, value, &instance->config.shellFormat); + optionParseString(key, value, &instance->config.packages.key); + else if(strcasecmp(key, "--packages-format") == 0) + optionParseString(key, value, &instance->config.packages.outputFormat); + else if(strcasecmp(key, "--packages-error") == 0) + optionParseString(key, value, &instance->config.packages.errorFormat); else if(strcasecmp(key, "--shell-key") == 0) - optionParseString(key, value, &instance->config.shellKey); - else if(strcasecmp(key, "--resolution-format") == 0) - optionParseString(key, value, &instance->config.resolutionFormat); + optionParseString(key, value, &instance->config.shell.key); + else if(strcasecmp(key, "--shell-format") == 0) + optionParseString(key, value, &instance->config.shell.outputFormat); + else if(strcasecmp(key, "--shell-error") == 0) + optionParseString(key, value, &instance->config.shell.errorFormat); else if(strcasecmp(key, "--resolution-key") == 0) - optionParseString(key, value, &instance->config.resolutionKey); - else if(strcasecmp(key, "--de-format") == 0) - optionParseString(key, value, &instance->config.deFormat); + optionParseString(key, value, &instance->config.resolution.key); + else if(strcasecmp(key, "--resolution-format") == 0) + optionParseString(key, value, &instance->config.resolution.outputFormat); + else if(strcasecmp(key, "--resolution-error") == 0) + optionParseString(key, value, &instance->config.resolution.errorFormat); else if(strcasecmp(key, "--de-key") == 0) - optionParseString(key, value, &instance->config.deKey); - else if(strcasecmp(key, "--wm-format") == 0) - optionParseString(key, value, &instance->config.wmFormat); + optionParseString(key, value, &instance->config.de.key); + else if(strcasecmp(key, "--de-format") == 0) + optionParseString(key, value, &instance->config.de.outputFormat); + else if(strcasecmp(key, "--de-error") == 0) + optionParseString(key, value, &instance->config.de.errorFormat); 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); + optionParseString(key, value, &instance->config.wm.key); + else if(strcasecmp(key, "--wm-format") == 0) + optionParseString(key, value, &instance->config.wm.outputFormat); + else if(strcasecmp(key, "--wm-error") == 0) + optionParseString(key, value, &instance->config.wm.errorFormat); 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); + optionParseString(key, value, &instance->config.wmTheme.key); + else if(strcasecmp(key, "--wm-theme-format") == 0) + optionParseString(key, value, &instance->config.wmTheme.outputFormat); + else if(strcasecmp(key, "--wm-theme-error") == 0) + optionParseString(key, value, &instance->config.wmTheme.errorFormat); else if(strcasecmp(key, "--theme-key") == 0) - optionParseString(key, value, &instance->config.themeKey); - else if(strcasecmp(key, "--icons-format") == 0) - optionParseString(key, value, &instance->config.iconsFormat); + optionParseString(key, value, &instance->config.theme.key); + else if(strcasecmp(key, "--theme-format") == 0) + optionParseString(key, value, &instance->config.theme.outputFormat); + else if(strcasecmp(key, "--theme-error") == 0) + optionParseString(key, value, &instance->config.theme.errorFormat); else if(strcasecmp(key, "--icons-key") == 0) - optionParseString(key, value, &instance->config.iconsKey); - else if(strcasecmp(key, "--font-format") == 0) - optionParseString(key, value, &instance->config.fontFormat); + optionParseString(key, value, &instance->config.icons.key); + else if(strcasecmp(key, "--icons-format") == 0) + optionParseString(key, value, &instance->config.icons.outputFormat); + else if(strcasecmp(key, "--icons-error") == 0) + optionParseString(key, value, &instance->config.icons.errorFormat); else if(strcasecmp(key, "--font-key") == 0) - optionParseString(key, value, &instance->config.fontKey); + optionParseString(key, value, &instance->config.font.key); + else if(strcasecmp(key, "--font-format") == 0) + optionParseString(key, value, &instance->config.font.outputFormat); + else if(strcasecmp(key, "--font-error") == 0) + optionParseString(key, value, &instance->config.font.errorFormat); else if(strcasecmp(key, "--cursor-key") == 0) - optionParseString(key, value, &instance->config.cursorKey); + optionParseString(key, value, &instance->config.cursor.key); else if(strcasecmp(key, "--cursor-format") == 0) - optionParseString(key, value, &instance->config.cursorFormat); - else if(strcasecmp(key, "--terminal-format") == 0) - optionParseString(key, value, &instance->config.terminalFormat); + optionParseString(key, value, &instance->config.cursor.outputFormat); + else if(strcasecmp(key, "--cursor-error") == 0) + optionParseString(key, value, &instance->config.cursor.errorFormat); else if(strcasecmp(key, "--terminal-key") == 0) - optionParseString(key, value, &instance->config.terminalKey); - else if(strcasecmp(key, "--terminal-font-format") == 0) - optionParseString(key, value, &instance->config.termFontFormat); + optionParseString(key, value, &instance->config.terminal.key); + else if(strcasecmp(key, "--terminal-format") == 0) + optionParseString(key, value, &instance->config.terminal.outputFormat); + else if(strcasecmp(key, "--terminal-error") == 0) + optionParseString(key, value, &instance->config.terminal.errorFormat); else if(strcasecmp(key, "--terminal-font-key") == 0) - optionParseString(key, value, &instance->config.termFontKey); - else if(strcasecmp(key, "--cpu-format") == 0) - optionParseString(key, value, &instance->config.cpuFormat); - else if(strcasecmp(key, "--cpu-usage-format") == 0) - optionParseString(key, value, &instance->config.cpuUsageFormat); + optionParseString(key, value, &instance->config.terminalFont.key); + else if(strcasecmp(key, "--terminal-font-format") == 0) + optionParseString(key, value, &instance->config.terminalFont.outputFormat); + else if(strcasecmp(key, "--terminal-font-error") == 0) + optionParseString(key, value, &instance->config.terminalFont.errorFormat); else if(strcasecmp(key, "--cpu-key") == 0) - optionParseString(key, value, &instance->config.cpuKey); + optionParseString(key, value, &instance->config.cpu.key); + else if(strcasecmp(key, "--cpu-format") == 0) + optionParseString(key, value, &instance->config.cpu.outputFormat); + else if(strcasecmp(key, "--cpu-error") == 0) + optionParseString(key, value, &instance->config.cpu.errorFormat); else if(strcasecmp(key, "--cpu-usage-key") == 0) - optionParseString(key, value, &instance->config.cpuUsageKey); - else if(strcasecmp(key, "--gpu-format") == 0) - optionParseString(key, value, &instance->config.gpuFormat); + optionParseString(key, value, &instance->config.cpuUsage.key); + else if(strcasecmp(key, "--cpu-usage-format") == 0) + optionParseString(key, value, &instance->config.cpuUsage.outputFormat); + else if(strcasecmp(key, "--cpu-usage-error") == 0) + optionParseString(key, value, &instance->config.cpuUsage.errorFormat); else if(strcasecmp(key, "--gpu-key") == 0) - optionParseString(key, value, &instance->config.gpuKey); - else if(strcasecmp(key, "--memory-format") == 0) - optionParseString(key, value, &instance->config.memoryFormat); + optionParseString(key, value, &instance->config.gpu.key); else if(strcasecmp(key, "--memory-key") == 0) - optionParseString(key, value, &instance->config.memoryKey); - else if(strcasecmp(key, "--disk-format") == 0) - optionParseString(key, value, &instance->config.diskFormat); + optionParseString(key, value, &instance->config.memory.key); + else if(strcasecmp(key, "--memory-format") == 0) + optionParseString(key, value, &instance->config.memory.outputFormat); + else if(strcasecmp(key, "--memory-error") == 0) + optionParseString(key, value, &instance->config.memory.errorFormat); else if(strcasecmp(key, "--disk-key") == 0) - optionParseString(key, value, &instance->config.diskKey); - else if(strcasecmp(key, "--battery-format") == 0) - optionParseString(key, value, &instance->config.batteryFormat); + optionParseString(key, value, &instance->config.disk.key); + else if(strcasecmp(key, "--disk-format") == 0) + optionParseString(key, value, &instance->config.disk.outputFormat); + else if(strcasecmp(key, "--disk-error") == 0) + optionParseString(key, value, &instance->config.disk.errorFormat); else if(strcasecmp(key, "--battery-key") == 0) - optionParseString(key, value, &instance->config.batteryKey); - else if(strcasecmp(key, "--locale-format") == 0) - optionParseString(key, value, &instance->config.localeFormat); + optionParseString(key, value, &instance->config.battery.key); + else if(strcasecmp(key, "--battery-format") == 0) + optionParseString(key, value, &instance->config.battery.outputFormat); + else if(strcasecmp(key, "--battery-error") == 0) + optionParseString(key, value, &instance->config.battery.errorFormat); else if(strcasecmp(key, "--locale-key") == 0) - optionParseString(key, value, &instance->config.localeKey); + optionParseString(key, value, &instance->config.locale.key); + else if(strcasecmp(key, "--locale-format") == 0) + optionParseString(key, value, &instance->config.locale.outputFormat); + else if(strcasecmp(key, "--locale-error") == 0) + optionParseString(key, value, &instance->config.locale.errorFormat); else if(strcasecmp(key, "--local-ip-key") == 0) - optionParseString(key, value, &instance->config.localIpKey); + optionParseString(key, value, &instance->config.localIP.key); else if(strcasecmp(key, "--local-ip-format") == 0) - optionParseString(key, value, &instance->config.localIpFormat); + optionParseString(key, value, &instance->config.localIP.outputFormat); + else if(strcasecmp(key, "--local-ip-error") == 0) + optionParseString(key, value, &instance->config.localIP.errorFormat); else if(strcasecmp(key, "--public-ip-key") == 0) - optionParseString(key, value, &instance->config.publicIpKey); + optionParseString(key, value, &instance->config.publicIP.key); else if(strcasecmp(key, "--public-ip-format") == 0) - optionParseString(key, value, &instance->config.publicIpFormat); + optionParseString(key, value, &instance->config.publicIP.outputFormat); + else if(strcasecmp(key, "--public-ip-error") == 0) + optionParseString(key, value, &instance->config.publicIP.errorFormat); else if(strcasecmp(key, "--player-key") == 0) - optionParseString(key, value, &instance->config.playerKey); + optionParseString(key, value, &instance->config.player.key); else if(strcasecmp(key, "--player-format") == 0) - optionParseString(key, value, &instance->config.playerFormat); + optionParseString(key, value, &instance->config.player.outputFormat); + else if(strcasecmp(key, "--player-error") == 0) + optionParseString(key, value, &instance->config.player.errorFormat); else if(strcasecmp(key, "--song-key") == 0) - optionParseString(key, value, &instance->config.songKey); + optionParseString(key, value, &instance->config.song.key); else if(strcasecmp(key, "--song-format") == 0) - optionParseString(key, value, &instance->config.songFormat); - else if(strcasecmp(key, "--datetime-key") == 0) - optionParseString(key, value, &instance->config.dateTimeKey); - else if(strcasecmp(key, "--datetime-format") == 0) - optionParseString(key, value, &instance->config.dateTimeFormat); + optionParseString(key, value, &instance->config.song.outputFormat); + else if(strcasecmp(key, "--song-error") == 0) + optionParseString(key, value, &instance->config.song.errorFormat); + else if(strcasecmp(key, "--date-time-key") == 0) + optionParseString(key, value, &instance->config.dateTime.key); + else if(strcasecmp(key, "--date-time-format") == 0) + optionParseString(key, value, &instance->config.dateTime.outputFormat); + else if(strcasecmp(key, "--date-time-error") == 0) + optionParseString(key, value, &instance->config.dateTime.errorFormat); else if(strcasecmp(key, "--date-key") == 0) - optionParseString(key, value, &instance->config.dateKey); + optionParseString(key, value, &instance->config.date.key); else if(strcasecmp(key, "--date-format") == 0) - optionParseString(key, value, &instance->config.dateFormat); + optionParseString(key, value, &instance->config.date.outputFormat); + else if(strcasecmp(key, "--date-error") == 0) + optionParseString(key, value, &instance->config.date.errorFormat); else if(strcasecmp(key, "--time-key") == 0) - optionParseString(key, value, &instance->config.timeKey); + optionParseString(key, value, &instance->config.time.key); else if(strcasecmp(key, "--time-format") == 0) - optionParseString(key, value, &instance->config.timeFormat); + optionParseString(key, value, &instance->config.time.outputFormat); + else if(strcasecmp(key, "--time-error") == 0) + optionParseString(key, value, &instance->config.time.errorFormat); else if(strcasecmp(key, "--vulkan-key") == 0) - optionParseString(key, value, &instance->config.vulkanKey); + optionParseString(key, value, &instance->config.vulkan.key); else if(strcasecmp(key, "--vulkan-format") == 0) - optionParseString(key, value, &instance->config.vulkanFormat); + optionParseString(key, value, &instance->config.vulkan.outputFormat); + else if(strcasecmp(key, "--vulkan-error") == 0) + optionParseString(key, value, &instance->config.vulkan.errorFormat); else if(strcasecmp(key, "--opengl-key") == 0) - optionParseString(key, value, &instance->config.openGLKey); + optionParseString(key, value, &instance->config.openGL.key); else if(strcasecmp(key, "--opengl-format") == 0) - optionParseString(key, value, &instance->config.openGLFormat); + optionParseString(key, value, &instance->config.openGL.outputFormat); + else if(strcasecmp(key, "--opengl-error") == 0) + optionParseString(key, value, &instance->config.openGL.errorFormat); else if(strcasecmp(key, "--opencl-key") == 0) - optionParseString(key, value, &instance->config.openCLKey); + optionParseString(key, value, &instance->config.openCL.key); else if(strcasecmp(key, "--opencl-format") == 0) - optionParseString(key, value, &instance->config.openCLFormat); + optionParseString(key, value, &instance->config.openCL.outputFormat); + else if(strcasecmp(key, "--opencl-error") == 0) + optionParseString(key, value, &instance->config.openCL.errorFormat); /////////////////// //Library options// diff --git a/src/fastfetch.h b/src/fastfetch.h index 9b814c658..265b93ae1 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -50,6 +50,13 @@ typedef enum FFGLType FF_GL_TYPE_OSMESA } FFGLType; +typedef struct FFModuleArgs +{ + FFstrbuf key; + FFstrbuf outputFormat; + FFstrbuf errorFormat; +} FFModuleArgs; + typedef struct FFconfig { FFstrbuf logoSource; @@ -74,74 +81,40 @@ typedef struct FFconfig FFGLType glType; bool pipe; //disables logo and all escape sequences - FFstrbuf osFormat; - FFstrbuf osKey; - FFstrbuf hostFormat; - FFstrbuf hostKey; - FFstrbuf kernelFormat; - FFstrbuf kernelKey; - FFstrbuf uptimeFormat; - FFstrbuf uptimeKey; - FFstrbuf processesFormat; - FFstrbuf processesKey; - FFstrbuf packagesFormat; - FFstrbuf packagesKey; - FFstrbuf shellFormat; - FFstrbuf shellKey; - FFstrbuf resolutionFormat; - FFstrbuf resolutionKey; - FFstrbuf deFormat; - FFstrbuf deKey; - FFstrbuf wmFormat; - FFstrbuf wmKey; - FFstrbuf wmThemeFormat; - FFstrbuf wmThemeKey; - FFstrbuf themeFormat; - FFstrbuf themeKey; - FFstrbuf iconsFormat; - FFstrbuf iconsKey; - FFstrbuf fontFormat; - FFstrbuf fontKey; - FFstrbuf cursorFormat; - FFstrbuf cursorKey; - FFstrbuf terminalFormat; - FFstrbuf terminalKey; - FFstrbuf termFontFormat; - FFstrbuf termFontKey; - FFstrbuf cpuFormat; - FFstrbuf cpuKey; - FFstrbuf cpuUsageFormat; - FFstrbuf cpuUsageKey; - FFstrbuf gpuFormat; - FFstrbuf gpuKey; - FFstrbuf memoryFormat; - FFstrbuf memoryKey; - FFstrbuf diskFormat; - FFstrbuf diskKey; - FFstrbuf batteryFormat; - FFstrbuf batteryKey; - FFstrbuf localeFormat; - FFstrbuf localeKey; - FFstrbuf localIpKey; - FFstrbuf localIpFormat; - FFstrbuf publicIpKey; - FFstrbuf publicIpFormat; - FFstrbuf playerKey; - FFstrbuf playerFormat; - FFstrbuf songKey; - FFstrbuf songFormat; - FFstrbuf dateTimeKey; - FFstrbuf dateTimeFormat; - FFstrbuf dateKey; - FFstrbuf dateFormat; - FFstrbuf timeKey; - FFstrbuf timeFormat; - FFstrbuf vulkanKey; - FFstrbuf vulkanFormat; - FFstrbuf openGLKey; - FFstrbuf openGLFormat; - FFstrbuf openCLKey; - FFstrbuf openCLFormat; + FFModuleArgs os; + FFModuleArgs host; + FFModuleArgs kernel; + FFModuleArgs uptime; + FFModuleArgs processes; + FFModuleArgs packages; + FFModuleArgs shell; + FFModuleArgs resolution; + FFModuleArgs de; + FFModuleArgs wm; + FFModuleArgs wmTheme; + FFModuleArgs theme; + FFModuleArgs icons; + FFModuleArgs font; + FFModuleArgs cursor; + FFModuleArgs terminal; + FFModuleArgs terminalFont; + FFModuleArgs cpu; + FFModuleArgs cpuUsage; + FFModuleArgs gpu; + FFModuleArgs memory; + FFModuleArgs disk; + FFModuleArgs battery; + FFModuleArgs locale; + FFModuleArgs localIP; + FFModuleArgs publicIP; + FFModuleArgs player; + FFModuleArgs song; + FFModuleArgs dateTime; + FFModuleArgs date; + FFModuleArgs time; + FFModuleArgs vulkan; + FFModuleArgs openGL; + FFModuleArgs openCL; FFstrbuf libPCI; FFstrbuf libVulkan; @@ -457,8 +430,10 @@ void ffGetTerminalResponse(const char* request, const char* format, ...); //common/printing.c void ffPrintLogoAndKey(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat); -void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numFormatArgs, const char* message, ...); -void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, const FFstrbuf* error, uint32_t numArgs, const FFformatarg* arguments); +void ffPrintFormatString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* format, uint32_t numArgs, const FFformatarg* arguments); +void ffPrintFormat(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, uint32_t numArgs, const FFformatarg* arguments); +void ffPrintErrorString(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, const FFstrbuf* customErrorFormat, const char* message, ...); +void ffPrintError(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, const char* message, ...); void ffPrintColor(const FFstrbuf* colorValue); void ffPrintCharTimes(char c, uint32_t times); @@ -468,9 +443,9 @@ void ffCacheValidate(FFinstance* instance); void ffCacheOpenWrite(FFinstance* instance, const char* moduleName, FFcache* cache); void ffCacheClose(FFcache* cache); -bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* formatString, uint32_t numArgs); -void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFstrbuf* customKeyFormat, FFcache* cache, const FFstrbuf* value, const FFstrbuf* formatString, uint32_t numArgs, const FFformatarg* arguments); -void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFstrbuf* customKeyFormat, const FFstrbuf* value, const FFstrbuf* formatString, uint32_t numArgs, const FFformatarg* arguments); +bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, uint32_t numArgs); +void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFcache* cache, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments); +void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments); //common/properties.c bool ffParsePropLine(const char* line, const char* start, FFstrbuf* buffer); @@ -490,7 +465,7 @@ void ffFontDestroy(FFfont* font); //common/format.c void ffFormatAppendFormatArg(FFstrbuf* buffer, const FFformatarg* formatarg); -void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, const FFstrbuf* error, uint32_t numArgs, const FFformatarg* arguments); +void ffParseFormatString(FFstrbuf* buffer, const FFstrbuf* formatstr, uint32_t numArgs, const FFformatarg* arguments); //common/parsing.c bool ffStrSet(const char* str); @@ -573,7 +548,7 @@ const FFVulkanResult* ffDetectVulkan(const FFinstance* instance); //Common const FFTitleResult* ffDetectTitle(FFinstance* instance); -void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFstrbuf* key, const FFstrbuf* format); +void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs); //Printing diff --git a/src/modules/battery.c b/src/modules/battery.c index 1b7847d9c..b0745c03a 100644 --- a/src/modules/battery.c +++ b/src/modules/battery.c @@ -3,6 +3,8 @@ #include #include +#include + #define FF_BATTERY_MODULE_NAME "Battery" #define FF_BATTERY_NUM_FORMAT_ARGS 5 @@ -85,9 +87,9 @@ static void parseBattery(FFstrbuf* dir, FFlist* results) static void printBattery(FFinstance* instance, const BatteryResult* result, uint8_t index) { - if(instance->config.batteryFormat.length == 0) + if(instance->config.battery.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.batteryKey); + ffPrintLogoAndKey(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.battery.key); bool showStatus = result->status.length > 0 && @@ -114,7 +116,7 @@ static void printBattery(FFinstance* instance, const BatteryResult* result, uint } else { - ffPrintFormatString(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.batteryKey, &instance->config.batteryFormat, NULL, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_BATTERY_MODULE_NAME, index, &instance->config.battery, FF_BATTERY_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->manufacturer}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->modelName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->technology}, @@ -144,7 +146,7 @@ void ffPrintBattery(FFinstance* instance) DIR* dirp = opendir(baseDir.chars); if(dirp == NULL) { - ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.batteryKey, &instance->config.batteryFormat, FF_BATTERY_NUM_FORMAT_ARGS, "opendir(\"%s\") == NULL", baseDir.chars); + ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.battery, "opendir(\"%s\") == NULL", baseDir.chars); ffStrbufDestroy(&baseDir); return; } @@ -175,7 +177,7 @@ void ffPrintBattery(FFinstance* instance) } if(results.length == 0) - ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.batteryKey, &instance->config.batteryFormat, FF_BATTERY_NUM_FORMAT_ARGS, "%s doesn't contain any battery folder", baseDir.chars); + ffPrintError(instance, FF_BATTERY_MODULE_NAME, 0, &instance->config.battery, "%s doesn't contain any battery folder", baseDir.chars); ffListDestroy(&results); ffStrbufDestroy(&baseDir); diff --git a/src/modules/cpu.c b/src/modules/cpu.c index be1b5bfdf..f1684ebb1 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -29,13 +29,13 @@ static double getGhz(const char* policyFile, const char* cpuFile) void ffPrintCPU(FFinstance* instance) { - if(ffPrintFromCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS)) + if(ffPrintFromCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpu, FF_CPU_NUM_FORMAT_ARGS)) return; FILE* cpuinfo = fopen("/proc/cpuinfo", "r"); if(cpuinfo == NULL) { - ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, "fopen(\"""/proc/cpuinfo\", \"r\") == NULL"); + ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpu, "fopen(\"""/proc/cpuinfo\", \"r\") == NULL"); return; } @@ -122,7 +122,7 @@ void ffPrintCPU(FFinstance* instance) ) { ffStrbufDestroy(&name); ffStrbufDestroy(&vendor); - ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpuKey, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, "No CPU info found in /proc/cpuinfo"); + ffPrintError(instance, FF_CPU_MODULE_NAME, 0, &instance->config.cpu, "No CPU info found in /proc/cpuinfo"); return; } @@ -185,7 +185,7 @@ void ffPrintCPU(FFinstance* instance) if(ghz > 0) ffStrbufAppendF(&cpu, " @ %.9gGHz", ghz); - ffPrintAndWriteToCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpuKey, &cpu, &instance->config.cpuFormat, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintAndWriteToCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpu, &cpu, FF_CPU_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &name}, {FF_FORMAT_ARG_TYPE_STRBUF, &namePretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &vendor}, diff --git a/src/modules/cpuUsage.c b/src/modules/cpuUsage.c index 8f98ea84a..854abae58 100644 --- a/src/modules/cpuUsage.c +++ b/src/modules/cpuUsage.c @@ -12,7 +12,7 @@ void ffPrintCPUUsage(FFinstance* instance) FILE* procStat = fopen("/proc/stat", "r"); if(procStat == NULL) { - ffPrintError(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsageKey, &instance->config.cpuUsageFormat, FF_CPU_USAGE_NUM_FORMAT_ARGS, "fopen(\"""/proc/stat\", \"r\") == NULL"); + ffPrintError(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpu, "fopen(\"""/proc/stat\", \"r\") == NULL"); return; } if (fscanf(procStat, "cpu%ld%ld%ld%ld%ld%ld%ld", &user, &nice, &system, &idle, &iowait, &irq, &softirq) < 0) goto exit; @@ -31,15 +31,15 @@ void ffPrintCPUUsage(FFinstance* instance) long totalOverPeriod = totalJiffies2 - totalJiffies1; double cpuPercent = (double)workOverPeriod / (double)totalOverPeriod * 100; - if(instance->config.cpuUsageFormat.length == 0) + if(instance->config.cpuUsage.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsageKey); + ffPrintLogoAndKey(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsage.key); printf("%.2lf%%\n", cpuPercent); } else { - ffPrintFormatString(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsageKey, &instance->config.cpuUsageFormat, NULL, FF_CPU_USAGE_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_CPU_USAGE_MODULE_NAME, 0, &instance->config.cpuUsage, FF_CPU_USAGE_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_DOUBLE, &cpuPercent} }); } diff --git a/src/modules/cursor.c b/src/modules/cursor.c index 9665a82be..8d1e191d1 100644 --- a/src/modules/cursor.c +++ b/src/modules/cursor.c @@ -12,9 +12,9 @@ static void printCursor(FFinstance* instance, FFstrbuf* cursorTheme, const FFstr if(cursorTheme->length == 0) ffStrbufAppendS(cursorTheme, "default"); - if(instance->config.cursorFormat.length == 0) + if(instance->config.cursor.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey); + ffPrintLogoAndKey(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor.key); ffStrbufWriteTo(cursorTheme, stdout); if(cursorSize != NULL && cursorSize->length > 0) @@ -28,7 +28,7 @@ static void printCursor(FFinstance* instance, FFstrbuf* cursorTheme, const FFstr } else { - ffPrintFormatString(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, NULL, FF_CURSOR_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, FF_CURSOR_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, cursorTheme}, {FF_FORMAT_ARG_TYPE_STRBUF, cursorSize} }); @@ -47,7 +47,7 @@ static void printCursorGTK(FFinstance* instance) if(gtk->cursor.length == 0) { - ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Couldn't detect GTK Cursor"); + ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Couldn't detect GTK Cursor"); return; } @@ -69,7 +69,7 @@ static void printCursorXFCE(FFinstance* instance) if(cursorTheme.length == 0) { - ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Couldn't find xfce cursor in xfconf (xsettings::/Gtk/CursorThemeName)"); + ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Couldn't find xfce cursor in xfconf (xsettings::/Gtk/CursorThemeName)"); return; } @@ -105,7 +105,7 @@ static void printCursorFromConfigFile(FFinstance* instance, const char* relative } if(cursorTheme.length == 0) - ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Couldn't find cursor in %s", relativeFilePath); + ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Couldn't find cursor in %s", relativeFilePath); else printCursor(instance, &cursorTheme, &cursorSize); @@ -185,7 +185,7 @@ static bool printCursorFromEnv(FFinstance* instance) void ffPrintCursor(FFinstance* instance) { #ifdef __ANDROID__ - ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Cursor detection is not supported on Android"); + ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Cursor detection is not supported on Android"); return; #endif @@ -193,7 +193,7 @@ void ffPrintCursor(FFinstance* instance) if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0) { - ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursorKey, &instance->config.cursorFormat, FF_CURSOR_NUM_FORMAT_ARGS, "Cursor isn't supported in TTY"); + ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Cursor isn't supported in TTY"); return; } diff --git a/src/modules/date.c b/src/modules/date.c index 075acf7eb..f232ef4d1 100644 --- a/src/modules/date.c +++ b/src/modules/date.c @@ -4,14 +4,14 @@ void ffPrintDate(FFinstance* instance) { - if(instance->config.dateFormat.length > 0) + if(instance->config.date.outputFormat.length > 0) { - ffPrintDateTimeFormat(instance, FF_DATE_MODULE_NAME, &instance->config.dateKey, &instance->config.dateFormat); + ffPrintDateTimeFormat(instance, FF_DATE_MODULE_NAME, &instance->config.date); return; } const FFDateTimeResult* datetime = ffDetectDateTime(instance); - ffPrintLogoAndKey(instance, FF_DATE_MODULE_NAME, 0, &instance->config.dateKey); + ffPrintLogoAndKey(instance, FF_DATE_MODULE_NAME, 0, &instance->config.date.key); //yyyy-mm-dd printf("%u-%s-%u\n", datetime->year, datetime->monthPretty.chars, datetime->dayInMonth); diff --git a/src/modules/datetime.c b/src/modules/datetime.c index dad574e32..bd6a7c278 100644 --- a/src/modules/datetime.c +++ b/src/modules/datetime.c @@ -3,10 +3,10 @@ #define FF_DATETIME_MODULE_NAME "Date & Time" #define FF_DATETIME_NUM_FORMAT_ARGS 20 -void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFstrbuf* key, const FFstrbuf* format) +void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs) { const FFDateTimeResult* result = ffDetectDateTime(instance); - ffPrintFormatString(instance, moduleName, 0, key, format, NULL, FF_DATETIME_NUM_FORMAT_ARGS, (FFformatarg[]) { + ffPrintFormat(instance, moduleName, 0, moduleArgs, FF_DATETIME_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_UINT16, &result->year}, {FF_FORMAT_ARG_TYPE_UINT8, &result->yearShort}, {FF_FORMAT_ARG_TYPE_UINT8, &result->month}, @@ -32,14 +32,14 @@ void ffPrintDateTimeFormat(FFinstance* instance, const char* moduleName, const F void ffPrintDateTime(FFinstance* instance) { - if(instance->config.dateTimeFormat.length > 0) + if(instance->config.dateTime.outputFormat.length > 0) { - ffPrintDateTimeFormat(instance, FF_DATETIME_MODULE_NAME, &instance->config.dateTimeKey, &instance->config.dateTimeFormat); + ffPrintDateTimeFormat(instance, FF_DATETIME_MODULE_NAME, &instance->config.dateTime); return; } const FFDateTimeResult* datetime = ffDetectDateTime(instance); - ffPrintLogoAndKey(instance, FF_DATETIME_MODULE_NAME, 0, &instance->config.dateTimeKey); + ffPrintLogoAndKey(instance, FF_DATETIME_MODULE_NAME, 0, &instance->config.dateTime.key); //yyyy-mm-dd hh:mm:ss printf("%u-%s-%u %s:%s:%s\n", datetime->year, datetime->monthPretty.chars, datetime->dayInMonth, datetime->hourPretty.chars, datetime->minutePretty.chars, datetime->secondPretty.chars); diff --git a/src/modules/de.c b/src/modules/de.c index 47a95da91..05374afbd 100644 --- a/src/modules/de.c +++ b/src/modules/de.c @@ -8,7 +8,7 @@ void ffPrintDesktopEnvironment(FFinstance* instance) { #ifdef __ANDROID__ - ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.deKey, &instance->config.deFormat, FF_DE_NUM_FORMAT_ARGS, "DE detection is not supported on Android"); + ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.de "DE detection is not supported on Android"); return; #endif @@ -16,13 +16,13 @@ void ffPrintDesktopEnvironment(FFinstance* instance) if(result->dePrettyName.length == 0) { - ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.deKey, &instance->config.deFormat, FF_DE_NUM_FORMAT_ARGS, "No DE found"); + ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.de, "No DE found"); return; } - if(instance->config.deFormat.length == 0) + if(instance->config.de.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_DE_MODULE_NAME, 0, &instance->config.deKey); + ffPrintLogoAndKey(instance, FF_DE_MODULE_NAME, 0, &instance->config.de.key); ffStrbufWriteTo(&result->dePrettyName, stdout); @@ -36,7 +36,7 @@ void ffPrintDesktopEnvironment(FFinstance* instance) } else { - ffPrintFormatString(instance, FF_DE_MODULE_NAME, 0, &instance->config.deKey, &instance->config.deFormat, NULL, FF_DE_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_DE_MODULE_NAME, 0, &instance->config.de, FF_DE_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->deProcessName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->dePrettyName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->deVersion} diff --git a/src/modules/disk.c b/src/modules/disk.c index 4515d051d..a2bf7814b 100644 --- a/src/modules/disk.c +++ b/src/modules/disk.c @@ -7,7 +7,7 @@ static void getKey(FFinstance* instance, FFstrbuf* key, const char* folderPath, bool showFolderPath) { - if(instance->config.diskKey.length == 0) + if(instance->config.disk.key.length == 0) { if(showFolderPath) ffStrbufAppendF(key, FF_DISK_MODULE_NAME" (%s)", folderPath); @@ -16,7 +16,7 @@ static void getKey(FFinstance* instance, FFstrbuf* key, const char* folderPath, } else { - ffParseFormatString(key, &instance->config.diskKey, NULL, 1, (FFformatarg[]){ + ffParseFormatString(key, &instance->config.disk.key, 1, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRING, folderPath} }); } @@ -33,14 +33,14 @@ static void printStatvfs(FFinstance* instance, FFstrbuf* key, struct statvfs* fs uint32_t files = (uint32_t) (fs->f_files - fs->f_ffree); - if(instance->config.diskFormat.length == 0) + if(instance->config.disk.outputFormat.length == 0) { ffPrintLogoAndKey(instance, key->chars, 0, NULL); printf("%uGiB / %uGiB (%u%%)\n", used, total, percentage); } else { - ffPrintFormatString(instance, key->chars, 0, NULL, &instance->config.diskFormat, NULL, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormatString(instance, key->chars, 0, NULL, &instance->config.disk.outputFormat, FF_DISK_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_UINT, &used}, {FF_FORMAT_ARG_TYPE_UINT, &total}, {FF_FORMAT_ARG_TYPE_UINT, &files}, @@ -64,9 +64,9 @@ static void printFolder(FFinstance* instance, const char* folderPath) struct statvfs fs; int ret = statvfs(folderPath, &fs); - if(ret != 0 && instance->config.diskFormat.length == 0) + if(ret != 0 && instance->config.disk.outputFormat.length == 0) { - ffPrintError(instance, key.chars, 0, NULL, &instance->config.diskFormat, FF_DISK_NUM_FORMAT_ARGS, "statvfs(\"%s\", &fs) != 0 (%i)", folderPath, ret); + ffPrintErrorString(instance, key.chars, 0, NULL, &instance->config.disk.errorFormat, "statvfs(\"%s\", &fs) != 0 (%i)", folderPath, ret); ffStrbufDestroy(&key); return; } @@ -89,7 +89,7 @@ void ffPrintDisk(FFinstance* instance) { FF_STRBUF_CREATE(key); getKey(instance, &key, "", false); - ffPrintError(instance, key.chars, 0, NULL, &instance->config.diskFormat, FF_DISK_NUM_FORMAT_ARGS, "statvfs failed for both / and " FASTFETCH_TARGET_DIR_HOME); + ffPrintErrorString(instance, key.chars, 0, NULL, &instance->config.disk.errorFormat, "statvfs failed for both / and " FASTFETCH_TARGET_DIR_HOME); ffStrbufDestroy(&key); return; } @@ -108,7 +108,7 @@ void ffPrintDisk(FFinstance* instance) { FF_STRBUF_CREATE(key); getKey(instance, &key, "", false); - ffPrintError(instance, key.chars, 0, NULL, &instance->config.diskFormat, FF_DISK_NUM_FORMAT_ARGS, "Custom disk folders string doesn't contain any folders"); + ffPrintErrorString(instance, key.chars, 0, NULL, &instance->config.disk.errorFormat, "Custom disk folders string doesn't contain any folders"); ffStrbufDestroy(&key); return; } diff --git a/src/modules/font.c b/src/modules/font.c index 28b54f8c3..173aa0569 100644 --- a/src/modules/font.c +++ b/src/modules/font.c @@ -6,7 +6,7 @@ void ffPrintFont(FFinstance* instance) { #ifdef __ANDROID__ - ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_FONT_NUM_FORMAT_ARGS, "Font detection is not supported on Android"); + ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "Font detection is not supported on Android"); return; #endif @@ -14,7 +14,7 @@ void ffPrintFont(FFinstance* instance) if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0) { - ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_FONT_NUM_FORMAT_ARGS, "Font isn't supported in TTY"); + ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "Font isn't supported in TTY"); return; } @@ -25,7 +25,7 @@ void ffPrintFont(FFinstance* instance) if(plasmaRaw->length == 0 && gtk2Raw->length == 0 && gtk3Raw->length == 0 && gtk4Raw->length == 0) { - ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_FONT_NUM_FORMAT_ARGS, "No fonts found"); + ffPrintError(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, "No fonts found"); return; } @@ -45,9 +45,9 @@ void ffPrintFont(FFinstance* instance) ffStrbufInitA(>k, 64); ffParseGTK(>k, >k2.pretty, >k3.pretty, >k4.pretty); - if(instance->config.fontFormat.length == 0) + if(instance->config.font.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey); + ffPrintLogoAndKey(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font.key); if(plasma.pretty.length > 0) { ffStrbufWriteTo(&plasma.pretty, stdout); @@ -60,7 +60,7 @@ void ffPrintFont(FFinstance* instance) } else { - ffPrintFormatString(instance, FF_FONT_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, NULL, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_FONT_MODULE_NAME, 0, &instance->config.font, FF_FONT_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, plasmaRaw}, {FF_FORMAT_ARG_TYPE_STRBUF, &plasma.name}, {FF_FORMAT_ARG_TYPE_STRBUF, &plasma.size}, diff --git a/src/modules/gpu.c b/src/modules/gpu.c index 05506109b..9cc079426 100644 --- a/src/modules/gpu.c +++ b/src/modules/gpu.c @@ -33,7 +33,7 @@ static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, ffStrbufAppend(&gpu, &namePretty); - ffPrintAndAppendToCache(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpuKey, cache, &gpu, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintAndAppendToCache(instance, FF_GPU_MODULE_NAME, index, &instance->config.gpu, cache, &gpu, FF_GPU_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->vendor}, {FF_FORMAT_ARG_TYPE_STRING, vendorPretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->name}, @@ -129,7 +129,7 @@ static bool pciPrintGPUs(FFinstance* instance) ffStrbufRecalculateLength(&result->name); ffStrbufInit(&result->driver); - if(instance->config.gpuFormat.length > 0) //We only need it for the format string, so don't detect it if it isn't needed + if(instance->config.gpu.outputFormat.length > 0) //We only need it for the format string, so don't detect it if it isn't needed pciGetDriver(dev, &result->driver, ffpci_get_param); }; } @@ -163,7 +163,7 @@ static bool vulkanPrintGPUs(FFinstance* instance) void ffPrintGPU(FFinstance* instance) { - if(ffPrintFromCache(instance, FF_GPU_MODULE_NAME, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS)) + if(ffPrintFromCache(instance, FF_GPU_MODULE_NAME, &instance->config.gpu, FF_GPU_NUM_FORMAT_ARGS)) return; #ifdef FF_HAVE_LIBPCI @@ -174,5 +174,5 @@ void ffPrintGPU(FFinstance* instance) if(vulkanPrintGPUs(instance)) return; - ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpuKey, &instance->config.gpuFormat, FF_GPU_NUM_FORMAT_ARGS, "No GPUs found."); + ffPrintError(instance, FF_GPU_MODULE_NAME, 0, &instance->config.gpu, "No GPUs found."); } diff --git a/src/modules/host.c b/src/modules/host.c index e5d6f2ab1..092e51176 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -44,7 +44,7 @@ static void getHostValue(const char* devicesPath, const char* classPath, FFstrbu void ffPrintHost(FFinstance* instance) { - if(ffPrintFromCache(instance, FF_HOST_MODULE_NAME, &instance->config.hostKey, &instance->config.hostFormat, FF_HOST_NUM_FORMAT_ARGS)) + if(ffPrintFromCache(instance, FF_HOST_MODULE_NAME, &instance->config.host, FF_HOST_NUM_FORMAT_ARGS)) return; FFstrbuf product_family; @@ -96,7 +96,7 @@ void ffPrintHost(FFinstance* instance) { ffStrbufDestroy(&product_family); ffStrbufDestroy(&product_name); - ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &instance->config.hostKey, &instance->config.hostFormat, FF_HOST_NUM_FORMAT_ARGS, "neither product_family nor product_name is set by O.E.M."); + ffPrintError(instance, FF_HOST_MODULE_NAME, 0, &instance->config.host, "neither product_family nor product_name is set by O.E.M."); return; } @@ -141,7 +141,7 @@ void ffPrintHost(FFinstance* instance) ffStrbufAppend(&host, &product_version); } - ffPrintAndWriteToCache(instance, FF_HOST_MODULE_NAME, &instance->config.hostKey, &host, &instance->config.hostFormat, FF_HOST_NUM_FORMAT_ARGS, (FFformatarg[]) { + ffPrintAndWriteToCache(instance, FF_HOST_MODULE_NAME, &instance->config.host, &host, FF_HOST_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &product_family}, {FF_FORMAT_ARG_TYPE_STRBUF, &product_name}, {FF_FORMAT_ARG_TYPE_STRBUF, &product_version}, diff --git a/src/modules/icons.c b/src/modules/icons.c index fd299f8a0..d1908a6c4 100644 --- a/src/modules/icons.c +++ b/src/modules/icons.c @@ -6,7 +6,7 @@ void ffPrintIcons(FFinstance* instance) { #ifdef __ANDROID__ - ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.iconsKey, &instance->config.iconsFormat, FF_ICONS_NUM_FORMAT_ARGS, "Icons detection is not supported on Android"); + ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons, "Icons detection is not supported on Android"); return; #endif @@ -14,7 +14,7 @@ void ffPrintIcons(FFinstance* instance) if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0) { - ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_ICONS_NUM_FORMAT_ARGS, "Icons aren't supported in TTY"); + ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons, "Icons aren't supported in TTY"); return; } @@ -25,16 +25,16 @@ void ffPrintIcons(FFinstance* instance) if(plasma->length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0) { - ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.iconsKey, &instance->config.iconsFormat, FF_ICONS_NUM_FORMAT_ARGS, "No icons could be found"); + ffPrintError(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons, "No icons could be found"); return; } FF_STRBUF_CREATE(gtkPretty); ffParseGTK(>kPretty, gtk2, gtk3, gtk4); - if(instance->config.iconsFormat.length == 0) + if(instance->config.icons.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.iconsKey); + ffPrintLogoAndKey(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons.key); if(plasma->length > 0) { @@ -49,7 +49,7 @@ void ffPrintIcons(FFinstance* instance) } else { - ffPrintFormatString(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.iconsKey, &instance->config.iconsFormat, NULL, FF_ICONS_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_ICONS_MODULE_NAME, 0, &instance->config.icons, FF_ICONS_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, plasma}, {FF_FORMAT_ARG_TYPE_STRBUF, gtk2}, {FF_FORMAT_ARG_TYPE_STRBUF, gtk3}, diff --git a/src/modules/kernel.c b/src/modules/kernel.c index 867284690..9b66b665d 100644 --- a/src/modules/kernel.c +++ b/src/modules/kernel.c @@ -5,14 +5,14 @@ void ffPrintKernel(FFinstance* instance) { - if(instance->config.kernelFormat.length == 0) + if(instance->config.kernel.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernelKey); + ffPrintLogoAndKey(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernel.key); puts(instance->state.utsname.release); } else { - ffPrintFormatString(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernelKey, &instance->config.kernelFormat, NULL, FF_KERNEL_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_KERNEL_MODULE_NAME, 0, &instance->config.kernel, FF_KERNEL_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.sysname}, {FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.release}, {FF_FORMAT_ARG_TYPE_STRING, instance->state.utsname.version} diff --git a/src/modules/locale.c b/src/modules/locale.c index 1c2fd6bf1..c226ddd31 100644 --- a/src/modules/locale.c +++ b/src/modules/locale.c @@ -22,7 +22,7 @@ static void getLocaleFromEnv(FFstrbuf* locale) void ffPrintLocale(FFinstance* instance) { - if(ffPrintFromCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.localeKey, &instance->config.localeFormat, FF_LOCALE_NUM_FORMAT_ARGS)) + if(ffPrintFromCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.locale, FF_LOCALE_NUM_FORMAT_ARGS)) return; FFstrbuf locale; @@ -45,11 +45,11 @@ void ffPrintLocale(FFinstance* instance) if(locale.length == 0) { - ffPrintError(instance, FF_LOCALE_MODULE_NAME, 0, &instance->config.localeKey, &instance->config.localeFormat, FF_LOCALE_NUM_FORMAT_ARGS, "No locale found"); + ffPrintError(instance, FF_LOCALE_MODULE_NAME, 0, &instance->config.locale, "No locale found"); return; } - ffPrintAndWriteToCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.localeKey, &locale, &instance->config.localeFormat, FF_LOCALE_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintAndWriteToCache(instance, FF_LOCALE_MODULE_NAME, &instance->config.locale, &locale, FF_LOCALE_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &locale} }); diff --git a/src/modules/localip.c b/src/modules/localip.c index e32e61d09..f5590376d 100644 --- a/src/modules/localip.c +++ b/src/modules/localip.c @@ -11,21 +11,28 @@ static void printValue(FFinstance* instance, const char* ifaName, const char* addressBuffer) { - FF_STRBUF_CREATE(key); + FFstrbuf key; + ffStrbufInit(&key); - if (instance->config.localIpKey.length == 0) { + if (instance->config.localIP.key.length == 0) + { ffStrbufAppendF(&key, FF_LOCALIP_MODULE_NAME " (%s)", ifaName); - } else { - ffParseFormatString(&key, &instance->config.localIpKey, NULL, 1, (FFformatarg[]){ + } + else + { + ffParseFormatString(&key, &instance->config.localIP.key, 1, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRING, ifaName} }); } - if (instance->config.localIpFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_LOCALIP_MODULE_NAME, 0, &key); + if (instance->config.localIP.outputFormat.length == 0) + { + ffPrintLogoAndKey(instance, key.chars, 0, NULL); puts(addressBuffer); - } else { - ffPrintFormatString(instance, FF_LOCALIP_MODULE_NAME, 0, &key, &instance->config.localIpFormat, NULL, FF_LOCALIP_NUM_FORMAT_ARGS, (FFformatarg[]){ + } + else + { + ffPrintFormatString(instance, key.chars, 0, NULL, &instance->config.localIP.outputFormat, FF_LOCALIP_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRING, addressBuffer} }); } @@ -38,7 +45,7 @@ void ffPrintLocalIp(FFinstance* instance) struct ifaddrs* ifAddrStruct = NULL; int ret = getifaddrs(&ifAddrStruct); if (ret < 0) { - ffPrintError(instance, FF_LOCALIP_MODULE_NAME, 0, &instance->config.localIpKey, &instance->config.localIpFormat, FF_LOCALIP_NUM_FORMAT_ARGS, "getifaddrs(&ifAddrStruct) < 0 (%i)", ret); + ffPrintError(instance, FF_LOCALIP_MODULE_NAME, 0, &instance->config.localIP, "getifaddrs(&ifAddrStruct) < 0 (%i)", ret); return; } diff --git a/src/modules/memory.c b/src/modules/memory.c index 4e9ce6515..dd6ff0771 100644 --- a/src/modules/memory.c +++ b/src/modules/memory.c @@ -8,7 +8,7 @@ void ffPrintMemory(FFinstance* instance) { FILE* meminfo = fopen("/proc/meminfo", "r"); if(meminfo == NULL) { - ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, FF_MEMORY_NUM_FORMAT_ARGS, "fopen(\"""/proc/meminfo\", \"r\") == NULL"); + ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, "fopen(\"""/proc/meminfo\", \"r\") == NULL"); return; } @@ -42,18 +42,18 @@ void ffPrintMemory(FFinstance* instance) if(used_mem == 0 && total_mem == 0 && percentage == 0) { - ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, FF_MEMORY_NUM_FORMAT_ARGS, "/proc/meminfo could't be parsed"); + ffPrintError(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, "/proc/meminfo could't be parsed"); return; } - if(instance->config.memoryFormat.length == 0) + if(instance->config.memory.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey); + ffPrintLogoAndKey(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory.key); printf("%uMiB / %uMiB (%u%%)\n", used_mem, total_mem, percentage); } else { - ffPrintFormatString(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memoryKey, &instance->config.memoryFormat, NULL, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_MEMORY_MODULE_NAME, 0, &instance->config.memory, FF_MEMORY_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_UINT, &used_mem}, {FF_FORMAT_ARG_TYPE_UINT, &total_mem}, {FF_FORMAT_ARG_TYPE_UINT8, &percentage} diff --git a/src/modules/opencl.c b/src/modules/opencl.c index 212b36771..a64964a17 100644 --- a/src/modules/opencl.c +++ b/src/modules/opencl.c @@ -44,14 +44,14 @@ static const char* openCLHandelData(FFinstance* instance, OpenCLData* data) char vendor[32]; data->ffclGetDeviceInfo(deviceID, CL_DEVICE_VENDOR, sizeof(vendor), vendor, NULL); - if(instance->config.openCLFormat.length == 0) + if(instance->config.openCL.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCLKey); + ffPrintLogoAndKey(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCL.key); puts(version); } else { - ffPrintFormatString(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCLKey, &instance->config.openCLFormat, NULL, FF_OPENCL_NUM_FORMAT_ARGS, (FFformatarg[]) { + ffPrintFormat(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCL, FF_OPENCL_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRING, version}, {FF_FORMAT_ARG_TYPE_STRING, device}, {FF_FORMAT_ARG_TYPE_STRING, vendor} @@ -87,5 +87,5 @@ void ffPrintOpenCL(FFinstance* instance) #endif if(error != NULL) - ffPrintError(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCLKey, &instance->config.openCLFormat, FF_OPENCL_NUM_FORMAT_ARGS, error); + ffPrintError(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCL, error); } diff --git a/src/modules/opengl.c b/src/modules/opengl.c index 873bab2e5..88e2768b2 100644 --- a/src/modules/opengl.c +++ b/src/modules/opengl.c @@ -27,14 +27,14 @@ static const char* glHandlePrint(FFinstance* instance, const GLData* data) const char* vendor = (const char*) data->ffglGetString(GL_VENDOR); const char* slv = (const char*) data->ffglGetString(GL_SHADING_LANGUAGE_VERSION); - if(instance->config.openGLFormat.length == 0) + if(instance->config.openGL.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGLKey); + ffPrintLogoAndKey(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGL.key); puts(version); } else { - ffPrintFormatString(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGLKey, &instance->config.openGLFormat, NULL, FF_OPENGL_NUM_FORMAT_ARGS, (FFformatarg[]) { + ffPrintFormat(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGL, FF_OPENGL_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRING, version}, {FF_FORMAT_ARG_TYPE_STRING, renderer}, {FF_FORMAT_ARG_TYPE_STRING, vendor}, @@ -388,5 +388,5 @@ void ffPrintOpenGL(FFinstance* instance) #endif if(error != NULL) - ffPrintError(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGLKey, &instance->config.openGLFormat, FF_OPENGL_NUM_FORMAT_ARGS, error); + ffPrintError(instance, FF_OPENGL_MODULE_NAME, 0, &instance->config.openGL, error); } diff --git a/src/modules/os.c b/src/modules/os.c index 2e721fd05..0cbe41c27 100644 --- a/src/modules/os.c +++ b/src/modules/os.c @@ -9,7 +9,7 @@ void ffPrintOS(FFinstance* instance) if(result->name.length == 0 && result->prettyName.length == 0) { - ffPrintError(instance, FF_OS_MODULE_NAME, 0, &instance->config.osKey, &instance->config.osFormat, FF_OS_NUM_FORMAT_ARGS, "Could not detect OS"); + ffPrintError(instance, FF_OS_MODULE_NAME, 0, &instance->config.os, "Could not detect OS"); return; } @@ -66,14 +66,14 @@ void ffPrintOS(FFinstance* instance) ffStrbufAppendC(&os, ']'); } - if(instance->config.osFormat.length == 0) + if(instance->config.os.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_OS_MODULE_NAME, 0, &instance->config.osKey); + ffPrintLogoAndKey(instance, FF_OS_MODULE_NAME, 0, &instance->config.os.key); ffStrbufPutTo(&os, stdout); } else { - ffPrintFormatString(instance, FF_OS_MODULE_NAME, 0, &instance->config.osKey, &instance->config.osFormat, NULL, FF_OS_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_OS_MODULE_NAME, 0, &instance->config.os, FF_OS_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->systemName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->name}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->prettyName}, diff --git a/src/modules/packages.c b/src/modules/packages.c index 5f7c96ce9..12c89f6fd 100644 --- a/src/modules/packages.c +++ b/src/modules/packages.c @@ -289,13 +289,13 @@ void ffPrintPackages(FFinstance* instance) uint32_t all = counts.dpkg + counts.emerge + counts.flatpak + counts.nixDefault + nixUser + counts.pacman + counts.rpm + counts.snap + counts.xbps; if(all == 0) { - ffPrintError(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packagesKey, &instance->config.packagesFormat, FF_PACKAGES_NUM_FORMAT_ARGS, "No packages from known package managers found"); + ffPrintError(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages, "No packages from known package managers found"); return; } - if(instance->config.packagesFormat.length == 0) + if(instance->config.packages.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packagesKey); + ffPrintLogoAndKey(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages.key); #define FF_PRINT_PACKAGE(name) \ if(counts.name > 0) \ @@ -344,7 +344,7 @@ void ffPrintPackages(FFinstance* instance) } else { - ffPrintFormatString(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packagesKey, &instance->config.packagesFormat, NULL, FF_PACKAGES_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_PACKAGES_MODULE_NAME, 0, &instance->config.packages, FF_PACKAGES_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_UINT, &all}, {FF_FORMAT_ARG_TYPE_UINT, &counts.pacman}, {FF_FORMAT_ARG_TYPE_STRBUF, &counts.pacmanBranch}, diff --git a/src/modules/player.c b/src/modules/player.c index 2da9f9d9b..a161f4b65 100644 --- a/src/modules/player.c +++ b/src/modules/player.c @@ -11,7 +11,7 @@ void ffPrintPlayer(FFinstance* instance) if(media->player.length == 0) { - ffPrintError(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.playerKey, &instance->config.playerFormat, FF_PLAYER_NUM_FORMAT_ARGS, "No media player found"); + ffPrintError(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.player, "No media player found"); return; } @@ -50,14 +50,14 @@ void ffPrintPlayer(FFinstance* instance) if(playerPrettyIsCustom) ffStrbufAppendC(&playerPretty, ')'); - if(instance->config.playerFormat.length == 0) + if(instance->config.player.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.playerKey); + ffPrintLogoAndKey(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.player.key); ffStrbufPutTo(&playerPretty, stdout); } else { - ffPrintFormatString(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.playerKey, &instance->config.playerFormat, NULL, FF_PLAYER_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_PLAYER_MODULE_NAME, 0, &instance->config.player, FF_PLAYER_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &playerPretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &media->player}, {FF_FORMAT_ARG_TYPE_STRBUF, &media->busNameShort} diff --git a/src/modules/processes.c b/src/modules/processes.c index ff697dfee..eb0467f51 100644 --- a/src/modules/processes.c +++ b/src/modules/processes.c @@ -5,15 +5,15 @@ void ffPrintProcesses(FFinstance* instance) { - if(instance->config.processesFormat.length == 0) + if(instance->config.processes.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processesKey); + ffPrintLogoAndKey(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes.key); printf("%hu\n", instance->state.sysinfo.procs); } else { - ffPrintFormatString(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processesKey, &instance->config.processesFormat, NULL, FF_PROCESSES_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_PROCESSES_MODULE_NAME, 0, &instance->config.processes, FF_PROCESSES_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_UINT16, &instance->state.sysinfo.procs} }); } diff --git a/src/modules/publicip.c b/src/modules/publicip.c index f48aa20d9..b93fde1e2 100644 --- a/src/modules/publicip.c +++ b/src/modules/publicip.c @@ -12,18 +12,18 @@ void ffPrintPublicIp(FFinstance* instance) if(result.length == 0) { - ffPrintError(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIpKey, &instance->config.publicIpFormat, FF_PUBLICIP_NUM_FORMAT_ARGS, "Failed to connect to an IP detection server"); + ffPrintError(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIP, "Failed to connect to an IP detection server"); return; } - if(instance->config.publicIpFormat.length == 0) + if(instance->config.publicIP.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIpKey); + ffPrintLogoAndKey(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIP.key); ffStrbufPutTo(&result, stdout); } else { - ffPrintFormatString(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIpKey, &instance->config.publicIpFormat, NULL, FF_PUBLICIP_NUM_FORMAT_ARGS, (FFformatarg[]) { + ffPrintFormat(instance, FF_PUBLICIP_MODULE_NAME, 0, &instance->config.publicIP, FF_PUBLICIP_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &result} }); } diff --git a/src/modules/resolution.c b/src/modules/resolution.c index bb9305e3c..83ff4103e 100644 --- a/src/modules/resolution.c +++ b/src/modules/resolution.c @@ -17,9 +17,9 @@ void ffPrintResolution(FFinstance* instance) FFResolutionResult* result = ffListGet(&dsResult->resolutions, i); uint8_t moduleIndex = dsResult->resolutions.length == 1 ? 0 : (uint8_t) (i + 1); - if(instance->config.resolutionFormat.length == 0) + if(instance->config.resolution.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_RESOLUTION_MODULE_NAME, moduleIndex, &instance->config.resolutionKey); + ffPrintLogoAndKey(instance, FF_RESOLUTION_MODULE_NAME, moduleIndex, &instance->config.resolution.key); printf("%ix%i", result->width, result->height); if(result->refreshRate > 0) @@ -29,7 +29,7 @@ void ffPrintResolution(FFinstance* instance) } else { - ffPrintFormatString(instance, FF_RESOLUTION_MODULE_NAME, moduleIndex, &instance->config.resolutionKey, &instance->config.resolutionFormat, NULL, FF_RESOLUTION_NUM_FORMAT_ARGS, (FFformatarg[]) { + ffPrintFormat(instance, FF_RESOLUTION_MODULE_NAME, moduleIndex, &instance->config.resolution, FF_RESOLUTION_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_INT, &result->width}, {FF_FORMAT_ARG_TYPE_INT, &result->height}, {FF_FORMAT_ARG_TYPE_INT, &result->refreshRate} @@ -38,5 +38,5 @@ void ffPrintResolution(FFinstance* instance) } if(dsResult->resolutions.length == 0) - ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.resolutionKey, &instance->config.resolutionFormat, FF_RESOLUTION_NUM_FORMAT_ARGS, "Couldn't detect resolution"); + ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.resolution, "Couldn't detect resolution"); } diff --git a/src/modules/shell.c b/src/modules/shell.c index 7e340165d..4f7cfe5c4 100644 --- a/src/modules/shell.c +++ b/src/modules/shell.c @@ -12,13 +12,13 @@ void ffPrintShell(FFinstance* instance) if(result->shellProcessName.length == 0) { - ffPrintError(instance, FF_SHELL_MODULE_NAME, 0, &instance->config.shellKey, &instance->config.shellFormat, FF_SHELL_NUM_FORMAT_ARGS, "Couldn't detect shell"); + ffPrintError(instance, FF_SHELL_MODULE_NAME, 0, &instance->config.shell, "Couldn't detect shell"); return; } - if(instance->config.shellFormat.length == 0) + if(instance->config.shell.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_SHELL_MODULE_NAME, 0, &instance->config.shellKey); + ffPrintLogoAndKey(instance, FF_SHELL_MODULE_NAME, 0, &instance->config.shell.key); fputs(result->shellExeName, stdout); if(result->shellVersion.length > 0) @@ -31,7 +31,7 @@ void ffPrintShell(FFinstance* instance) } else { - ffPrintFormatString(instance, FF_SHELL_MODULE_NAME, 0, &instance->config.shellKey, &instance->config.shellFormat, NULL, FF_SHELL_NUM_FORMAT_ARGS, (FFformatarg[]) { + ffPrintFormat(instance, FF_SHELL_MODULE_NAME, 0, &instance->config.shell, FF_SHELL_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &result->shellProcessName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->shellExe}, {FF_FORMAT_ARG_TYPE_STRING, result->shellExeName}, diff --git a/src/modules/song.c b/src/modules/song.c index ed38f57ac..6a38bbc56 100644 --- a/src/modules/song.c +++ b/src/modules/song.c @@ -46,7 +46,7 @@ void ffPrintSong(FFinstance* instance) if(media->song.length == 0) { - ffPrintError(instance, FF_SONG_MODULE_NAME, 0, &instance->config.songKey, &instance->config.songFormat, FF_SONG_NUM_FORMAT_ARGS, "No song detected"); + ffPrintError(instance, FF_SONG_MODULE_NAME, 0, &instance->config.song, "No song detected"); return; } @@ -67,7 +67,7 @@ void ffPrintSong(FFinstance* instance) if(songPretty.length == 0) ffStrbufAppend(&songPretty, &media->song); - if(instance->config.songFormat.length == 0) + if(instance->config.song.outputFormat.length == 0) { //We don't expose artistPretty to the format, as it might be empty (when the think that the artist is already in the song title) FFstrbuf artistPretty; @@ -79,7 +79,7 @@ void ffPrintSong(FFinstance* instance) if(artistInSongTitle(&songPretty, &artistPretty)) ffStrbufClear(&artistPretty); - ffPrintLogoAndKey(instance, FF_SONG_MODULE_NAME, 0, &instance->config.songKey); + ffPrintLogoAndKey(instance, FF_SONG_MODULE_NAME, 0, &instance->config.song.key); if(artistPretty.length > 0) { @@ -98,7 +98,7 @@ void ffPrintSong(FFinstance* instance) } else { - ffPrintFormatString(instance, FF_SONG_MODULE_NAME, 0, &instance->config.songKey, &instance->config.songFormat, NULL, FF_SONG_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_SONG_MODULE_NAME, 0, &instance->config.song, FF_SONG_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &songPretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &media->song}, {FF_FORMAT_ARG_TYPE_STRBUF, &media->artist}, diff --git a/src/modules/terminal.c b/src/modules/terminal.c index 4672485c5..ceddefe78 100644 --- a/src/modules/terminal.c +++ b/src/modules/terminal.c @@ -13,13 +13,13 @@ void ffPrintTerminal(FFinstance* instance) if(result->terminalProcessName.length == 0) { - ffPrintError(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminalKey, &instance->config.terminalFormat, FF_TERMINAL_NUM_FORMAT_ARGS, "Couldn't detect terminal"); + ffPrintError(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminal, "Couldn't detect terminal"); return; } - if(instance->config.terminalFormat.length == 0) + if(instance->config.terminal.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminalKey); + ffPrintLogoAndKey(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminal.key); if(strncmp(result->terminalExeName, result->terminalProcessName.chars, result->terminalProcessName.length) == 0) // if exeName starts with processName, print it. Otherwise print processName puts(result->terminalExeName); @@ -28,7 +28,7 @@ void ffPrintTerminal(FFinstance* instance) } else { - ffPrintFormatString(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminalKey, &instance->config.terminalFormat, NULL, FF_TERMINAL_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_TERMINAL_MODULE_NAME, 0, &instance->config.terminal, FF_TERMINAL_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalProcessName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->terminalExe}, {FF_FORMAT_ARG_TYPE_STRING, result->terminalExeName} diff --git a/src/modules/terminalfont.c b/src/modules/terminalfont.c index a2fc1572e..bba8910a9 100644 --- a/src/modules/terminalfont.c +++ b/src/modules/terminalfont.c @@ -7,18 +7,18 @@ static void printTerminalFont(FFinstance* instance, const char* raw, FFfont* fon { if(font->pretty.length == 0) { - ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Terminal font is an empty value"); + ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Terminal font is an empty value"); return; } - if(instance->config.termFontFormat.length == 0) + if(instance->config.terminalFont.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey); + ffPrintLogoAndKey(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont.key); ffStrbufPutTo(&font->pretty, stdout); } else { - ffPrintFormatString(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, NULL, FF_TERMFONT_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, FF_TERMFONT_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRING, raw}, {FF_FORMAT_ARG_TYPE_STRBUF, &font->name}, {FF_FORMAT_ARG_TYPE_STRBUF, &font->size}, @@ -55,7 +55,7 @@ static void printTerminalFontFromConfigFile(FFinstance* instance, const char* co ffParsePropFileConfig(instance, configFile, start, &fontName); if(fontName.length == 0) - ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find terminal font in \"$XDG_CONFIG_HOME/%s\"", configFile); + ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't find terminal font in \"$XDG_CONFIG_HOME/%s\"", configFile); else { FFfont font; @@ -72,7 +72,7 @@ static void printTerminalFontFromGSettings(FFinstance* instance, char* profilePa const char* defaultProfile = ffSettingsGetGSettings(instance, profileList, NULL, "default", FF_VARIANT_TYPE_STRING).strValue; if(defaultProfile == NULL) { - ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't get \"default\" profile from gsettings"); + ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't get \"default\" profile from gsettings"); return; } @@ -88,13 +88,13 @@ static void printTerminalFontFromGSettings(FFinstance* instance, char* profilePa { fontName = ffSettingsGetGSettings(instance, profile, path.chars, "font", FF_VARIANT_TYPE_STRING).strValue; if(fontName == NULL) - ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't get terminal font from GSettings (%s::%s::font)", profile, path.chars); + ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't get terminal font from GSettings (%s::%s::font)", profile, path.chars); } else // system font { fontName = getSystemMonospaceFont(instance); if(fontName == NULL) - ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Could't get system monospace font name from GSettings / DConf"); + ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Could't get system monospace font name from GSettings / DConf"); } ffStrbufDestroy(&path); @@ -116,7 +116,7 @@ static void printKonsole(FFinstance* instance) if(profile.length == 0) { - ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"DefaultProfile=%[^\\n]\" in \".config/konsolerc\""); + ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't find \"DefaultProfile=%[^\\n]\" in \".config/konsolerc\""); ffStrbufDestroy(&profile); return; } @@ -131,7 +131,7 @@ static void printKonsole(FFinstance* instance) ffParsePropFileHome(instance, profilePath.chars, "Font =", &fontName); if(fontName.length == 0) - ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath.chars); + ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't find \"Font=%%[^\\n]\" in \"%s\"", profilePath.chars); else { FFfont font; @@ -152,7 +152,7 @@ static void printXCFETerminal(FFinstance* instance) if(!ffParsePropFileConfig(instance, "xfce4/terminal/terminalrc", "FontUseSystem =", &useSysFont)) { - ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't open \"$XDG_CONFIG_HOME/xfce4/terminal/terminalrc\""); + ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't open \"$XDG_CONFIG_HOME/xfce4/terminal/terminalrc\""); ffStrbufDestroy(&useSysFont); return; } @@ -169,7 +169,7 @@ static void printXCFETerminal(FFinstance* instance) const char* fontName = ffSettingsGetXFConf(instance, "xsettings", "/Gtk/MonospaceFontName", FF_VARIANT_TYPE_STRING).strValue; if(fontName == NULL) - ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Couldn't find \"xsettings::/Gtk/MonospaceFontName\" in XFConf"); + ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Couldn't find \"xsettings::/Gtk/MonospaceFontName\" in XFConf"); else { FFfont font; @@ -211,7 +211,7 @@ void ffPrintTerminalFont(FFinstance* instance) if(result->terminalProcessName.length == 0) { - ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Terminal font needs successfull terminal detection"); + ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Terminal font needs successfull terminal detection"); return; } @@ -228,5 +228,5 @@ void ffPrintTerminalFont(FFinstance* instance) else if(ffStrbufStartsWithIgnCaseS(&result->terminalExe, "/dev/tty")) printTTY(instance); else - ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.termFontKey, &instance->config.termFontFormat, FF_TERMFONT_NUM_FORMAT_ARGS, "Unknown terminal: %s", result->terminalProcessName.chars); + ffPrintError(instance, FF_TERMFONT_MODULE_NAME, 0, &instance->config.terminalFont, "Unknown terminal: %s", result->terminalProcessName.chars); } diff --git a/src/modules/theme.c b/src/modules/theme.c index 3d59535c8..37fc7dd41 100644 --- a/src/modules/theme.c +++ b/src/modules/theme.c @@ -14,7 +14,7 @@ void ffPrintTheme(FFinstance* instance) if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0) { - ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.fontKey, &instance->config.fontFormat, FF_THEME_NUM_FORMAT_ARGS, "Theme isn't supported in TTY"); + ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "Theme isn't supported in TTY"); return; } @@ -25,7 +25,7 @@ void ffPrintTheme(FFinstance* instance) if(plasma->widgetStyle.length == 0 && plasma->colorScheme.length == 0 && gtk2->length == 0 && gtk3->length == 0 && gtk4->length == 0) { - ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.themeKey, &instance->config.themeFormat, FF_THEME_NUM_FORMAT_ARGS, "No themes found"); + ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "No themes found"); return; } @@ -40,9 +40,9 @@ void ffPrintTheme(FFinstance* instance) FF_STRBUF_CREATE(gtkPretty); ffParseGTK(>kPretty, gtk2, gtk3, gtk4); - if(instance->config.themeFormat.length == 0) + if(instance->config.theme.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_THEME_MODULE_NAME, 0, &instance->config.themeKey); + ffPrintLogoAndKey(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme.key); if(plasma->widgetStyle.length > 0) { @@ -80,7 +80,7 @@ void ffPrintTheme(FFinstance* instance) } else { - ffPrintFormatString(instance, FF_THEME_MODULE_NAME, 0, &instance->config.themeKey, &instance->config.themeFormat, NULL, FF_THEME_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, FF_THEME_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &plasma->widgetStyle}, {FF_FORMAT_ARG_TYPE_STRBUF, &plasma->colorScheme}, {FF_FORMAT_ARG_TYPE_STRBUF, &plasmaColorPretty}, diff --git a/src/modules/time.c b/src/modules/time.c index 693b0c85d..13670b90c 100644 --- a/src/modules/time.c +++ b/src/modules/time.c @@ -4,14 +4,14 @@ void ffPrintTime(FFinstance* instance) { - if(instance->config.timeFormat.length > 0) + if(instance->config.time.outputFormat.length > 0) { - ffPrintDateTimeFormat(instance, FF_TIME_MODULE_NAME, &instance->config.timeKey, &instance->config.timeFormat); + ffPrintDateTimeFormat(instance, FF_TIME_MODULE_NAME, &instance->config.time); return; } const FFDateTimeResult* datetime = ffDetectDateTime(instance); - ffPrintLogoAndKey(instance, FF_TIME_MODULE_NAME, 0, &instance->config.timeKey); + ffPrintLogoAndKey(instance, FF_TIME_MODULE_NAME, 0, &instance->config.time.key); //hh:mm:ss printf("%s:%s:%s\n", datetime->hourPretty.chars, datetime->minutePretty.chars, datetime->secondPretty.chars); diff --git a/src/modules/uptime.c b/src/modules/uptime.c index 3df32a4d6..14a804103 100644 --- a/src/modules/uptime.c +++ b/src/modules/uptime.c @@ -10,9 +10,9 @@ void ffPrintUptime(FFinstance* instance) uint32_t minutes = (uint32_t) (instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600)) / 60; uint32_t seconds = (uint32_t) instance->state.sysinfo.uptime - (days * 86400) - (hours * 3600) - (minutes * 60); - if(instance->config.uptimeFormat.length == 0) + if(instance->config.uptime.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_UPTIME_MODULE_NAME, 0, &instance->config.uptimeKey); + ffPrintLogoAndKey(instance, FF_UPTIME_MODULE_NAME, 0, &instance->config.uptime.key); if(days == 0 && hours == 0 && minutes == 0) { @@ -57,7 +57,7 @@ void ffPrintUptime(FFinstance* instance) } else { - ffPrintFormatString(instance, FF_UPTIME_MODULE_NAME, 0, &instance->config.uptimeKey, &instance->config.uptimeFormat, NULL, FF_UPTIME_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_UPTIME_MODULE_NAME, 0, &instance->config.uptime, FF_UPTIME_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_UINT, &days}, {FF_FORMAT_ARG_TYPE_UINT, &hours}, {FF_FORMAT_ARG_TYPE_UINT, &minutes}, diff --git a/src/modules/vulkan.c b/src/modules/vulkan.c index 974c0007d..3a196c1b6 100644 --- a/src/modules/vulkan.c +++ b/src/modules/vulkan.c @@ -9,13 +9,13 @@ void ffPrintVulkan(FFinstance* instance) if(vulkan->apiVersion.length == 0 && vulkan->driver.length == 0) { - ffPrintError(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkanKey, &instance->config.vulkanFormat, FF_VULKAN_NUM_FORMAT_ARGS, "Failed to detect vulkan"); + ffPrintError(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkan, "Failed to detect vulkan"); return; } - if(instance->config.vulkanFormat.length == 0) + if(instance->config.vulkan.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkanKey); + ffPrintLogoAndKey(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkan.key); if(vulkan->driver.length > 0) { @@ -32,7 +32,7 @@ void ffPrintVulkan(FFinstance* instance) } else { - ffPrintFormatString(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkanKey, &instance->config.vulkanFormat, NULL, FF_VULKAN_NUM_FORMAT_ARGS, (FFformatarg[]) { + ffPrintFormat(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkan, FF_VULKAN_NUM_FORMAT_ARGS, (FFformatarg[]) { {FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->driver}, {FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->apiVersion}, {FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->conformanceVersion} diff --git a/src/modules/wm.c b/src/modules/wm.c index 925102e50..fe95a387e 100644 --- a/src/modules/wm.c +++ b/src/modules/wm.c @@ -14,13 +14,13 @@ void ffPrintWM(FFinstance* instance) if(result->wmPrettyName.length == 0) { - ffPrintError(instance, FF_WM_MODULE_NAME, 0, &instance->config.wmKey, &instance->config.wmFormat, FF_WM_NUM_FORMAT_ARGS, "No WM found"); + ffPrintError(instance, FF_WM_MODULE_NAME, 0, &instance->config.wm, "No WM found"); return; } - if(instance->config.wmFormat.length == 0) + if(instance->config.wm.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_WM_MODULE_NAME, 0, &instance->config.wmKey); + ffPrintLogoAndKey(instance, FF_WM_MODULE_NAME, 0, &instance->config.wm.key); ffStrbufWriteTo(&result->wmPrettyName, stdout); @@ -35,7 +35,7 @@ void ffPrintWM(FFinstance* instance) } else { - ffPrintFormatString(instance, FF_WM_MODULE_NAME, 0, &instance->config.wmKey, &instance->config.wmFormat, NULL, FF_WM_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_WM_MODULE_NAME, 0, &instance->config.wm, FF_WM_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProcessName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmPrettyName}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProtocolName} diff --git a/src/modules/wmtheme.c b/src/modules/wmtheme.c index 443653e1a..18a5dd5b0 100644 --- a/src/modules/wmtheme.c +++ b/src/modules/wmtheme.c @@ -6,14 +6,14 @@ static void printWMTheme(FFinstance* instance, const char* theme) { - if(instance->config.wmThemeFormat.length == 0) + if(instance->config.wmTheme.outputFormat.length == 0) { - ffPrintLogoAndKey(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey); + ffPrintLogoAndKey(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme.key); puts(theme); } else { - ffPrintFormatString(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, NULL, FF_WMTHEME_NUM_FORMAT_ARGS, (FFformatarg[]){ + ffPrintFormat(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, FF_WMTHEME_NUM_FORMAT_ARGS, (FFformatarg[]){ {FF_FORMAT_ARG_TYPE_STRING, theme} }); } @@ -26,7 +26,7 @@ static void printWMThemeFromConfigFile(FFinstance* instance, const char* configF if(!ffParsePropFileConfig(instance, configFile, themeRegex, &theme)) { - ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Config file %s doesn't exist", configFile); + ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Config file %s doesn't exist", configFile); ffStrbufDestroy(&theme); return; } @@ -37,7 +37,7 @@ static void printWMThemeFromConfigFile(FFinstance* instance, const char* configF if(defaultValue == NULL) { - ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find WM theme in %s", configFile); + ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't find WM theme in %s", configFile); return; } @@ -66,7 +66,7 @@ static void printWMThemeFromSettings(FFinstance* instance, const char* dconfKey, if(!ffStrSet(theme)) { - ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find WM theme in DConf or GSettings"); + ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't find WM theme in DConf or GSettings"); return; } @@ -99,7 +99,7 @@ static void printGTKThemeAsWMTheme(FFinstance* instance) return; } - ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't detect GTK4/3/2 theme"); + ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't detect GTK4/3/2 theme"); } static void printMutter(FFinstance* instance) @@ -121,7 +121,7 @@ static void printMuffin(FFinstance* instance) if(name == NULL && theme == NULL) { - ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find muffin theme in GSettings / DConf"); + ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't find muffin theme in GSettings / DConf"); return; } @@ -150,7 +150,7 @@ static void printXFWM4(FFinstance* instance) if(theme == NULL) { - ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't find xfwm4::/general/theme in XFConf"); + ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't find xfwm4::/general/theme in XFConf"); return; } @@ -177,7 +177,7 @@ static void printOpenbox(FFinstance* instance, const FFstrbuf* dePrettyName) FILE* file = fopen(absolutePath.chars, "r"); if(file == NULL) { - ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Couldn't open \"%s\"", absolutePath.chars); + ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't open \"%s\"", absolutePath.chars); ffStrbufDestroy(&absolutePath); return; @@ -213,7 +213,7 @@ static void printOpenbox(FFinstance* instance, const FFstrbuf* dePrettyName) 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); + ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Couldn't find theme name in \"%s\"", absolutePath.chars); else printWMTheme(instance, theme.chars); @@ -224,7 +224,7 @@ static void printOpenbox(FFinstance* instance, const FFstrbuf* dePrettyName) void ffPrintWMTheme(FFinstance* instance) { #ifdef __ANDROID__ - ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "WM theme detection is not supported on Android"); + ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "WM theme detection is not supported on Android"); return; #endif @@ -232,7 +232,7 @@ void ffPrintWMTheme(FFinstance* instance) if(result->wmPrettyName.length == 0) { - ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "WM Theme needs sucessfull WM detection"); + ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "WM Theme needs sucessfull WM detection"); return; } @@ -254,5 +254,5 @@ void ffPrintWMTheme(FFinstance* instance) else if(ffStrbufIgnCaseCompS(&result->wmPrettyName, "Openbox") == 0) printOpenbox(instance, &result->dePrettyName); else - ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmThemeKey, &instance->config.wmThemeFormat, FF_WMTHEME_NUM_FORMAT_ARGS, "Unknown WM: %s", result->wmPrettyName.chars); + ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "Unknown WM: %s", result->wmPrettyName.chars); } From 97d2096df81ed7c19e0d06d7bc74730623ca2ea0 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Fri, 17 Jun 2022 18:19:53 +0200 Subject: [PATCH 17/55] Delete performance test I never really used it, and it didn't even build any more --- CMakeLists.txt | 7 ---- tests/performance.c | 82 -------------------------------------------- tests/performance.sh | 6 ---- 3 files changed, 95 deletions(-) delete mode 100644 tests/performance.c delete mode 100755 tests/performance.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bfb476c2..9233ab112 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -477,13 +477,6 @@ target_link_libraries(flashfetch ################### if (BUILD_TESTS) - add_executable(fastfetch-test-performance - tests/performance.c - ) - target_link_libraries(fastfetch-test-performance - PRIVATE libfastfetch - ) - add_executable(fastfetch-test-strbuf tests/strbuf.c ) diff --git a/tests/performance.c b/tests/performance.c deleted file mode 100644 index c526a2106..000000000 --- a/tests/performance.c +++ /dev/null @@ -1,82 +0,0 @@ -#include "fastfetch.h" - -#include - -#define FASTFETCH_TEST_PERFORMANCE(func) \ - { \ - struct timespec start, end; \ - clock_gettime(CLOCK_REALTIME, &start); \ - func; \ - clock_gettime(CLOCK_REALTIME, &end); \ - long nanos = end.tv_nsec - start.tv_nsec; \ - printf("\033[F"); \ - for(uint8_t i = 0; i < 125; i++) printf("\033[C"); \ - printf("%08ldns\n", nanos); \ - } \ - -int main(int argc, char** argv) -{ - FF_UNUSED(argc, argv); - - FFinstance instance; - - FASTFETCH_TEST_PERFORMANCE( - puts("Initialization"); - ffInitInstance(&instance); - ) - - instance.config.showErrors = true; - instance.config.recache = argc == 1; - instance.config.cacheSave = false; - ffStrbufSetS(&instance.config.songFormat, "{}"); //Otherwise the line is too long - - FASTFETCH_TEST_PERFORMANCE( - puts("Thread starting"); - ffStartDetectionThreads(&instance); - ) - - FASTFETCH_TEST_PERFORMANCE( - puts("Starting"); - ffStart(&instance); - ) - - FASTFETCH_TEST_PERFORMANCE(ffPrintTitle(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintSeparator(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintOS(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintHost(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintKernel(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintUptime(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintProcesses(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintPackages(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintShell(&instance)) - 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)) - FASTFETCH_TEST_PERFORMANCE(ffPrintTerminal(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintTerminalFont(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintCPU(&instance)) - //FASTFETCH_TEST_PERFORMANCE(ffPrintCPUUsage(&instance)) // Doesn't make sense, contains a sleep call - FASTFETCH_TEST_PERFORMANCE(ffPrintGPU(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintMemory(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintDisk(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintBattery(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintPlayer(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintSong(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintLocalIp(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintPublicIp(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintDateTime(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintLocale(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintBreak(&instance)) - FASTFETCH_TEST_PERFORMANCE(ffPrintColors(&instance)) - - FASTFETCH_TEST_PERFORMANCE( - puts("Finishing"); - ffFinish(&instance); - ) - - return 0; -} diff --git a/tests/performance.sh b/tests/performance.sh deleted file mode 100755 index df6eb7809..000000000 --- a/tests/performance.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/env sh -mkdir -p build/ -cd build -cmake .. -cmake --build . --target fastfetch-test-performance -j$(nproc) -./fastfetch-test-performance "$@" From eac875b8b19b884dbcafac81e515f1f585a466ca Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Fri, 17 Jun 2022 18:28:37 +0200 Subject: [PATCH 18/55] Update bash completion to include ---error options --- completions/bash | 39 +++++++++++++++++++++++++++++++++++++-- src/data/config.txt | 6 +++--- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/completions/bash b/completions/bash index 787495d11..0c003f06b 100644 --- a/completions/bash +++ b/completions/bash @@ -213,8 +213,8 @@ __fastfetch_completion() "--player-key" "--song-format" "--song-key" - "--datetime-key" - "--datetime-format" + "--date-time-key" + "--date-time-format" "--date-format" "--date-key" "--time-format" @@ -225,6 +225,41 @@ __fastfetch_completion() "--opengl-format" "--opencl-key" "--opencl-format" + "--os-error" + "--host-error" + "--kernel-error" + "--uptime-error" + "--processes-error" + "--packages-error" + "--shell-error" + "--resolution-error" + "--de-error" + "--wm-error" + "--wm-theme-error" + "--theme-error" + "--icons-error" + "--font-error" + "--cursor-error" + "--terminal-error" + "--terminal-font-error" + "--cpu-error" + "--cpu-usage-error" + "--gpu-error" + "--memory-error" + "--disk-error" + "--battery-error" + "--locale-error" + "--disk-error" + "--local-ip-error" + "--public-ip-error" + "--player-error" + "--song-error" + "--date-time-error" + "--date-error" + "--time-error" + "--vulkan-error" + "--opengl-error" + "--opencl-error" ) local FF_OPTIONS_PATH=( diff --git a/src/data/config.txt b/src/data/config.txt index db0d7145c..a970ddf42 100644 --- a/src/data/config.txt +++ b/src/data/config.txt @@ -194,7 +194,7 @@ #--public-ip-key Public IP #--player-key Media Player #--song-key Song -#--datetime-key Date Time +#--date-time-key Date Time #--vulkan-key Vulkan #--opengl-key OpenGL #--opencl-key OpenCL @@ -232,7 +232,7 @@ #--public-ip-format #--player-format #--song-format -#--datetime-format +#--date-time-format #--vulkan-format #--opengl-format #--opencl-format @@ -270,7 +270,7 @@ #--public-ip-error #--player-error #--song-error -#--datetime-error +#--date-time-error #--vulkan-error #--opengl-error #--opencl-error From da77a7936fd216e125a070445f0d5005d674e907 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Fri, 17 Jun 2022 19:59:01 +0200 Subject: [PATCH 19/55] Detect WSL as host --- src/modules/host.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/modules/host.c b/src/modules/host.c index 092e51176..46a7d891e 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -79,6 +79,13 @@ void ffPrintHost(FFinstance* instance) if(!hostValueSet(&product_name)) ffStrbufClear(&product_name); + + //On WSL, the real host can't be detected. Instead use WSL as host. + if(product_name.length == 0 && product_family.length == 0 && ( + getenv("WSLENV") != NULL || + getenv("WSL_DISTRO") != NULL || + getenv("WSL_INTEROP") != NULL + )) ffStrbufAppendS(&product_family, "Windows Subsystem for Linux"); #else ffSettingsGetAndroidProperty("ro.product.brand", &product_name); if(product_name.length > 0){ From eb0bbd0796aede4aa1a4ae003d024aadaf7cdc56 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Fri, 17 Jun 2022 20:01:02 +0200 Subject: [PATCH 20/55] Detect WSL as host name --- src/modules/host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/host.c b/src/modules/host.c index 46a7d891e..27cc990a7 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -85,7 +85,7 @@ void ffPrintHost(FFinstance* instance) getenv("WSLENV") != NULL || getenv("WSL_DISTRO") != NULL || getenv("WSL_INTEROP") != NULL - )) ffStrbufAppendS(&product_family, "Windows Subsystem for Linux"); + )) ffStrbufAppendS(&product_name, "Windows Subsystem for Linux"); #else ffSettingsGetAndroidProperty("ro.product.brand", &product_name); if(product_name.length > 0){ From ad28b3aac567add2d2953082c7adfd1f661eedd0 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Fri, 17 Jun 2022 20:40:51 +0200 Subject: [PATCH 21/55] rename date-time to datetime --- completions/bash | 6 +++--- src/data/config.txt | 6 +++--- src/fastfetch.c | 10 +++++++--- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/completions/bash b/completions/bash index 0c003f06b..750764834 100644 --- a/completions/bash +++ b/completions/bash @@ -213,8 +213,8 @@ __fastfetch_completion() "--player-key" "--song-format" "--song-key" - "--date-time-key" - "--date-time-format" + "--datetime-key" + "--datetime-format" "--date-format" "--date-key" "--time-format" @@ -254,7 +254,7 @@ __fastfetch_completion() "--public-ip-error" "--player-error" "--song-error" - "--date-time-error" + "--datetime-error" "--date-error" "--time-error" "--vulkan-error" diff --git a/src/data/config.txt b/src/data/config.txt index a970ddf42..db0d7145c 100644 --- a/src/data/config.txt +++ b/src/data/config.txt @@ -194,7 +194,7 @@ #--public-ip-key Public IP #--player-key Media Player #--song-key Song -#--date-time-key Date Time +#--datetime-key Date Time #--vulkan-key Vulkan #--opengl-key OpenGL #--opencl-key OpenCL @@ -232,7 +232,7 @@ #--public-ip-format #--player-format #--song-format -#--date-time-format +#--datetime-format #--vulkan-format #--opengl-format #--opencl-format @@ -270,7 +270,7 @@ #--public-ip-error #--player-error #--song-error -#--date-time-error +#--datetime-error #--vulkan-error #--opengl-error #--opencl-error diff --git a/src/fastfetch.c b/src/fastfetch.c index 58e39d9dd..a0929e678 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1009,6 +1009,10 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con optionParseString(key, value, &instance->config.cpuUsage.errorFormat); else if(strcasecmp(key, "--gpu-key") == 0) optionParseString(key, value, &instance->config.gpu.key); + else if(strcasecmp(key, "--gpu-format") == 0) + optionParseString(key, value, &instance->config.gpu.outputFormat); + else if(strcasecmp(key, "--gpu-error") == 0) + optionParseString(key, value, &instance->config.gpu.errorFormat); else if(strcasecmp(key, "--memory-key") == 0) optionParseString(key, value, &instance->config.memory.key); else if(strcasecmp(key, "--memory-format") == 0) @@ -1057,11 +1061,11 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con optionParseString(key, value, &instance->config.song.outputFormat); else if(strcasecmp(key, "--song-error") == 0) optionParseString(key, value, &instance->config.song.errorFormat); - else if(strcasecmp(key, "--date-time-key") == 0) + else if(strcasecmp(key, "--datetime-key") == 0) optionParseString(key, value, &instance->config.dateTime.key); - else if(strcasecmp(key, "--date-time-format") == 0) + else if(strcasecmp(key, "--datetime-format") == 0) optionParseString(key, value, &instance->config.dateTime.outputFormat); - else if(strcasecmp(key, "--date-time-error") == 0) + else if(strcasecmp(key, "--datetime-error") == 0) optionParseString(key, value, &instance->config.dateTime.errorFormat); else if(strcasecmp(key, "--date-key") == 0) optionParseString(key, value, &instance->config.date.key); From 20e2f1e19db85ef637eb9e43db749e9e1b12ccae Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Fri, 17 Jun 2022 20:41:11 +0200 Subject: [PATCH 22/55] Detect CPU temp only if a custom format string is given --- src/modules/cpu.c | 53 +++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/modules/cpu.c b/src/modules/cpu.c index f1684ebb1..87a8390d0 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -27,6 +27,32 @@ static double getGhz(const char* policyFile, const char* cpuFile) return herz / 1000.0; //to GHz } +static double detectCPUTemp(const FFinstance* instance) +{ + const FFTempsResult *temps = ffDetectTemps(instance); + + for(uint32_t i = 0; i < temps->values.length; i++) + { + FFTempValue* value = ffListGet(&temps->values, i); + + if( + ffStrbufFirstIndexS(&value->name, "cpu") == value->name.length && + ffStrbufCompS(&value->name, "k10temp") != 0 && + ffStrbufCompS(&value->name, "coretemp") != 0 + ) continue; + + double temp = ffStrbufToDouble(&value->value); + + //NaN + if(temp != temp) + continue; + + return temp / 1000.0; // millidegrees to degrees + } + + return 0.0 / 0.0; //NaN +} + void ffPrintCPU(FFinstance* instance) { if(ffPrintFromCache(instance, FF_CPU_MODULE_NAME, &instance->config.cpu, FF_CPU_NUM_FORMAT_ARGS)) @@ -141,28 +167,11 @@ void ffPrintCPU(FFinstance* instance) ffStrbufSubstrBeforeFirstC(&namePretty, '@'); //Cut the speed output in the name as we append our own ffStrbufTrimRight(&namePretty, ' '); //If we removed the @ in previous step there was most likely a space before it - const FFTempsResult *temps = ffDetectTemps(instance); - double cpuTemp = 0.0/0.0; //NaN - - for(uint32_t i = 0; i < temps->values.length; i++) - { - FFTempValue* value = ffListGet(&temps->values, i); - - if( - ffStrbufFirstIndexS(&value->name, "cpu") == value->name.length && - ffStrbufCompS(&value->name, "k10temp") != 0 && - ffStrbufCompS(&value->name, "coretemp") != 0 - ) continue; - - double temp = ffStrbufToDouble(&value->value); - - //NaN - if(temp != temp) - continue; - - cpuTemp = temp / 1000.0; - break; - } + double cpuTemp; + if(instance->config.cpu.outputFormat.length > 0) + cpuTemp = detectCPUTemp(instance); + else + cpuTemp = 0.0 / 0.0; //NaN FFstrbuf cpu; ffStrbufInitA(&cpu, 128); From 5d853f3b175b9984e5ba1cb7c58b04373efcdb0c Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Fri, 17 Jun 2022 23:38:33 +0200 Subject: [PATCH 23/55] GPU temp detection --- DEVELOPMENT.md | 1 - README.md | 2 +- presets/verbose | 2 +- src/detection/temps.c | 31 +++++++++++++++++++++---------- src/detection/vulkan.c | 1 + src/fastfetch.c | 5 +++-- src/fastfetch.h | 3 ++- src/modules/cpu.c | 18 ++++-------------- src/modules/gpu.c | 35 +++++++++++++++++++++++++++++++---- 9 files changed, 64 insertions(+), 34 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index a1984236c..632c3f654 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -12,7 +12,6 @@ Here i just add things that are easy to forget. - `libffprint`: contains the printing functions, logos, format etc - `fastfetch` and `flashfetch`: Executables, that initialize the config of libffprint. Fist one at runtime, second one at compile time - [ ] Better OS output for all possible combinations of /etc/os-release variables. -- [ ] Expose temperatures to GPU format string - [ ] Find wayland compositor by looking at \${XDG_RUNTIME_DIR}/${WAYLAND_DISPLAY:-wayland-0} - [ ] Make LocalIP module more configurable - [ ] Automatic migrate old config files to newer versions diff --git a/README.md b/README.md index 2e65d5edb..cefe110ae 100644 --- a/README.md +++ b/README.md @@ -50,7 +50,7 @@ Title, Separator, OS, Host, Kernel, Uptime, Processes, Packages, Shell, Resoluti ##### Logos ``` -Android, Arch, Arco, Artix, Bedrock, CachyOS, CentOS, Debian, Devuan, Deepin, Endeavour, Fedora, Garuda, Gentoo, KDE Neon, Kubuntu, Linux, Manjaro, Mint, NixOS, OpenSUSE, OpenSUSE Tumbleweed, OpenSUSE LEAP, Pop!_OS, RebornOS, RedstarOS, Rocky, Ubuntu, Void, Zorin +Alpine, Android, Arch, Arco, Artix, Bedrock, CachyOS, CentOS, Debian, Devuan, Deepin, Endeavour, Fedora, Garuda, Gentoo, KDE Neon, Kubuntu, Linux, Manjaro, Mint, NixOS, OpenSUSE, OpenSUSE Tumbleweed, OpenSUSE LEAP, Pop!_OS, RebornOS, RedstarOS, Rocky, Ubuntu, Void, Zorin ``` * Most of the logos have a small variant. Access it by appending _small to the logo name. * Some logos have an old variant. Access it by appending _old to the logo name. diff --git a/presets/verbose b/presets/verbose index c45314905..f859551c5 100644 --- a/presets/verbose +++ b/presets/verbose @@ -19,7 +19,7 @@ --terminal-font-format "Raw: {}; Name: {}; Size: {}; Styles: {}; Pretty: {}" --cpu-format "Name: {}; Pretty: {}; Vendor: {}; Logical online: {}; Logical configured: {}; Physical: {}; Cores: {}; temperature: {}; bios: {}; scaling max: {}; scaling min: {}; info max: {}; info min: {}; cpuinfo: {}; frequency: {}" --cpu-usage-format "Percentage: {}" ---gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}" +--gpu-format "Vendor: {}; Vendor pretty: {}; Name: {}; Name pretty: {}; Driver: {}; Temperature: {}" --memory-format "Used: {}; Total: {}; Percentage: {}" --disk-format "Used: {}; Total: {}; Files: {}; Percentage: {}" --battery-format "Manufactor: {}; Model: {}; Technology: {}; Capacaty: {}; Status: {}" diff --git a/src/detection/temps.c b/src/detection/temps.c index 4fcdc5827..b086a424c 100644 --- a/src/detection/temps.c +++ b/src/detection/temps.c @@ -3,6 +3,7 @@ #include #include #include +#include static bool isTempFile(const char* name) { @@ -20,22 +21,34 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value) return false; uint32_t dirLength = dir->length; + value->value = 0.0 / 0.0; //use NaN as error value + + FFstrbuf valueString; + ffStrbufInit(&valueString); struct dirent* dirent; while((dirent = readdir(dirp)) != NULL) { - if(isTempFile(dirent->d_name)) - { - ffStrbufAppendS(dir, dirent->d_name); - ffGetFileContent(dir->chars, &value->value); - ffStrbufSubstrBefore(dir, dirLength); - break; - } + if(!isTempFile(dirent->d_name)) + continue; + + ffStrbufAppendS(dir, dirent->d_name); + ffGetFileContent(dir->chars, &valueString); + ffStrbufSubstrBefore(dir, dirLength); + + //ffStrbufToDouble() returns NaN if the string couldn't be parsed + value->value = ffStrbufToDouble(&valueString); + if(value->value != value->value) + continue; + + value->value /= 1000.0; //millidegrees to degrees + break; } closedir(dirp); + ffStrbufDestroy(&valueString); - if(value->value.length == 0) + if(value->value != value->value) return false; ffStrbufAppendS(dir, "name"); @@ -92,12 +105,10 @@ const FFTempsResult* ffDetectTemps(const FFinstance* instance) FFTempValue* temp = ffListAdd(&result.values); ffStrbufInit(&temp->name); ffStrbufInit(&temp->deviceClass); - ffStrbufInit(&temp->value); if(!parseHwmonDir(&baseDir, temp)) { ffStrbufDestroy(&temp->name); ffStrbufDestroy(&temp->deviceClass); - ffStrbufDestroy(&temp->value); --result.values.length; } diff --git a/src/detection/vulkan.c b/src/detection/vulkan.c index d6dae7e01..dd2c1ab8c 100644 --- a/src/detection/vulkan.c +++ b/src/detection/vulkan.c @@ -174,6 +174,7 @@ static void detectVulkan(const FFinstance* instance, FFVulkanResult* result) ffStrbufInit(&gpu->vendor); ffStrbufInit(&gpu->name); ffStrbufInit(&gpu->driver); + gpu->temperature = 0.0 / 0.0; //NaN, no way to detect temperature using vulkan ffStrbufAppendS(&gpu->name, physicalDeviceProperties.properties.deviceName); } diff --git a/src/fastfetch.c b/src/fastfetch.c index a0929e678..d646f47d1 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -262,12 +262,13 @@ static inline void printCommandHelp(const char* command) } else if(strcasecmp(command, "gpu-format") == 0) { - constructAndPrintCommandHelpFormat("gpu", "{2} {4}", 5, + constructAndPrintCommandHelpFormat("gpu", "{2} {4}", 6, "GPU vendor", "GPU vendor pretty", "GPU name", "GPU name pretty", - "GPU driver" + "GPU driver", + "GPU temperature" ); } else if(strcasecmp(command, "memory-format") == 0) diff --git a/src/fastfetch.h b/src/fastfetch.h index 265b93ae1..535c9cd9e 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -242,6 +242,7 @@ typedef struct FFGPUResult FFstrbuf vendor; FFstrbuf name; FFstrbuf driver; + double temperature; } FFGPUResult; typedef struct FFVulkanResult @@ -273,8 +274,8 @@ typedef struct FFDisplayServerResult typedef struct FFTempValue { FFstrbuf name; - FFstrbuf value; FFstrbuf deviceClass; + double value; } FFTempValue; typedef struct FFTempsResult diff --git a/src/modules/cpu.c b/src/modules/cpu.c index 87a8390d0..93c414531 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -36,18 +36,10 @@ static double detectCPUTemp(const FFinstance* instance) FFTempValue* value = ffListGet(&temps->values, i); if( - ffStrbufFirstIndexS(&value->name, "cpu") == value->name.length && - ffStrbufCompS(&value->name, "k10temp") != 0 && - ffStrbufCompS(&value->name, "coretemp") != 0 - ) continue; - - double temp = ffStrbufToDouble(&value->value); - - //NaN - if(temp != temp) - continue; - - return temp / 1000.0; // millidegrees to degrees + ffStrbufFirstIndexS(&value->name, "cpu") < value->name.length || + ffStrbufCompS(&value->name, "k10temp") == 0 || + ffStrbufCompS(&value->name, "coretemp") == 0 + ) return value->value; } return 0.0 / 0.0; //NaN @@ -170,8 +162,6 @@ void ffPrintCPU(FFinstance* instance) double cpuTemp; if(instance->config.cpu.outputFormat.length > 0) cpuTemp = detectCPUTemp(instance); - else - cpuTemp = 0.0 / 0.0; //NaN FFstrbuf cpu; ffStrbufInitA(&cpu, 128); diff --git a/src/modules/gpu.c b/src/modules/gpu.c index 9cc079426..ec58421e8 100644 --- a/src/modules/gpu.c +++ b/src/modules/gpu.c @@ -3,7 +3,7 @@ #include #define FF_GPU_MODULE_NAME "GPU" -#define FF_GPU_NUM_FORMAT_ARGS 5 +#define FF_GPU_NUM_FORMAT_ARGS 6 static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, FFGPUResult* result) { @@ -39,6 +39,7 @@ static void printGPUResult(FFinstance* instance, uint8_t index, FFcache* cache, {FF_FORMAT_ARG_TYPE_STRBUF, &result->name}, {FF_FORMAT_ARG_TYPE_STRBUF, &namePretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->driver}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &result->temperature} }); ffStrbufDestroy(&result->vendor); @@ -89,6 +90,26 @@ static void pciGetDriver(struct pci_dev* dev, FFstrbuf* driver, char*(*ffpci_get ffStrbufDestroy(&path); } +static double pciGetTemperatur(const FFinstance* instance, uint16_t deviceClass) +{ + const FFTempsResult* tempsResult = ffDetectTemps(instance); + + for(uint32_t i = 0; i < tempsResult->values.length; i++) + { + FFTempValue* tempValue = ffListGet(&tempsResult->values, i); + + uint32_t tempClass; + if(sscanf(tempValue->deviceClass.chars, "%x", &tempClass) != 1) + continue; + + //The kernel exposes the device class multiplied by 256 for some reason + if(tempClass == deviceClass * 256) + return tempValue->value; + } + + return 0.0 / 0.0; //NaN +} + static bool pciPrintGPUs(FFinstance* instance) { FF_LIBRARY_LOAD(pci, instance->config.libPCI, false, "libpci.so", 4) @@ -121,16 +142,22 @@ static bool pciPrintGPUs(FFinstance* instance) FFGPUResult* result = ffListAdd(&results); ffStrbufInitA(&result->vendor, 256); - ffpci_lookup_name(pacc, result->vendor.chars, (int) result->vendor.allocated -1, PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id); + ffpci_lookup_name(pacc, result->vendor.chars, (int) ffStrbufGetFree(&result->vendor), PCI_LOOKUP_VENDOR, dev->vendor_id, dev->device_id); ffStrbufRecalculateLength(&result->vendor); ffStrbufInitA(&result->name, 256); - ffpci_lookup_name(pacc, result->name.chars, (int) result->name.allocated - 1, PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id); + ffpci_lookup_name(pacc, result->name.chars, (int) ffStrbufGetFree(&result->name), PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id); ffStrbufRecalculateLength(&result->name); ffStrbufInit(&result->driver); - if(instance->config.gpu.outputFormat.length > 0) //We only need it for the format string, so don't detect it if it isn't needed + result->temperature = 0; + + //We only need it for the format string, so don't detect it if it isn't needed + if(instance->config.gpu.outputFormat.length > 0) + { pciGetDriver(dev, &result->driver, ffpci_get_param); + result->temperature = pciGetTemperatur(instance, dev->device_class); + } }; } From e61b31acab9c406bcaaa00e329c153b3319898e1 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sat, 18 Jun 2022 00:15:23 +0200 Subject: [PATCH 24/55] Fix build on Android --- src/modules/resolution.c | 2 +- src/modules/theme.c | 2 +- src/modules/wm.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/modules/resolution.c b/src/modules/resolution.c index 83ff4103e..e0c1b4b41 100644 --- a/src/modules/resolution.c +++ b/src/modules/resolution.c @@ -6,7 +6,7 @@ void ffPrintResolution(FFinstance* instance) { #ifdef __ANDROID__ - ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.resolutionKey, &instance->config.resolutionFormat, FF_RESOLUTION_NUM_FORMAT_ARGS, "Resolution detection is not supported on Android"); + ffPrintError(instance, FF_RESOLUTION_MODULE_NAME, 0, &instance->config.resolution, "Resolution detection is not supported on Android"); return; #endif diff --git a/src/modules/theme.c b/src/modules/theme.c index 37fc7dd41..b05ba0a3d 100644 --- a/src/modules/theme.c +++ b/src/modules/theme.c @@ -6,7 +6,7 @@ void ffPrintTheme(FFinstance* instance) { #ifdef __ANDROID__ - ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.themeKey, &instance->config.themeFormat, FF_THEME_NUM_FORMAT_ARGS, "Theme detection is not supported on Android"); + ffPrintError(instance, FF_THEME_MODULE_NAME, 0, &instance->config.theme, "Theme detection is not supported on Android"); return; #endif diff --git a/src/modules/wm.c b/src/modules/wm.c index fe95a387e..fa3d392a1 100644 --- a/src/modules/wm.c +++ b/src/modules/wm.c @@ -6,7 +6,7 @@ void ffPrintWM(FFinstance* instance) { #ifdef __ANDROID__ - ffPrintError(instance, FF_WM_MODULE_NAME, 0, &instance->config.wmKey, &instance->config.wmFormat, FF_WM_NUM_FORMAT_ARGS, "WM detection is not supported on Android"); + ffPrintError(instance, FF_WM_MODULE_NAME, 0, &instance->config.wm, "WM detection is not supported on Android"); return; #endif From 0691112e5eb17fc8f8c7255203f4323b97f67084 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sat, 18 Jun 2022 00:20:22 +0200 Subject: [PATCH 25/55] Fix build on Android part 2 --- src/modules/host.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/host.c b/src/modules/host.c index 27cc990a7..9980ecb95 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -109,8 +109,8 @@ void ffPrintHost(FFinstance* instance) #ifdef __ANDROID__ #define FF_HOST_DATA(name) - FFstrbuf product_name; \ - ffStrbufInitA(&product_name, 0); + FFstrbuf name; \ + ffStrbufInitA(&name, 0); #else #define FF_HOST_DATA(name) \ FFstrbuf name; \ From af2f97e0c9e79fa406d718aa7293579925b21947 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sat, 18 Jun 2022 00:22:07 +0200 Subject: [PATCH 26/55] Fix build on Android part 3 --- src/modules/de.c | 2 +- src/modules/host.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/modules/de.c b/src/modules/de.c index 05374afbd..b8f1a4852 100644 --- a/src/modules/de.c +++ b/src/modules/de.c @@ -8,7 +8,7 @@ void ffPrintDesktopEnvironment(FFinstance* instance) { #ifdef __ANDROID__ - ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.de "DE detection is not supported on Android"); + ffPrintError(instance, FF_DE_MODULE_NAME, 0, &instance->config.de, "DE detection is not supported on Android"); return; #endif diff --git a/src/modules/host.c b/src/modules/host.c index 9980ecb95..f088a3c44 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -108,7 +108,7 @@ void ffPrintHost(FFinstance* instance) } #ifdef __ANDROID__ - #define FF_HOST_DATA(name) + #define FF_HOST_DATA(name) \ FFstrbuf name; \ ffStrbufInitA(&name, 0); #else From a6209187ae8b827d2bc6a18b345d3d3e02cab7f8 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sat, 18 Jun 2022 00:41:43 +0200 Subject: [PATCH 27/55] Fix build on Android part 4 --- src/modules/host.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/host.c b/src/modules/host.c index f088a3c44..7679dca08 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -5,6 +5,7 @@ #define FF_HOST_MODULE_NAME "Host" #define FF_HOST_NUM_FORMAT_ARGS 15 +#ifndef __ANDROID__ static bool hostValueSet(FFstrbuf* value) { ffStrbufTrimRight(value, '\n'); @@ -32,7 +33,6 @@ static bool hostValueSet(FFstrbuf* value) ; } -#ifndef __ANDROID__ static void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer) { ffGetFileContent(devicesPath, buffer); From f35dc9f46aa81d281ed94bdca7aec23363f9c1d2 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sat, 18 Jun 2022 00:45:28 +0200 Subject: [PATCH 28/55] Detect termux --- src/detection/terminalShell.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/detection/terminalShell.c b/src/detection/terminalShell.c index 9767c1ad8..c4cabff20 100644 --- a/src/detection/terminalShell.c +++ b/src/detection/terminalShell.c @@ -122,6 +122,13 @@ static void getTerminalFromEnv(FFTerminalShellResult* result) if(!ffStrSet(term) && getenv("WT_SESSION") != NULL) term = "Windows Terminal"; + //Termux + if(!ffStrSet(term) && ( + getenv("TERMUX_VERSION") != NULL || + getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL || + getenv("TMUX_TMPDIR") != NULL + )) term = "Termux"; + //Normal Terminal if(!ffStrSet(term)) term = getenv("TERM"); From fe712917697c9830ca969348bd9807c3ec50e391 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sat, 18 Jun 2022 14:25:31 +0200 Subject: [PATCH 29/55] Clean up includes --- src/common/caching.c | 2 ++ src/common/init.c | 1 + src/common/io.c | 3 +-- src/common/library.c | 1 + src/common/networking.c | 1 - src/common/processing.c | 2 +- src/common/properties.c | 2 ++ src/common/settings.c | 1 + src/detection/datetime.c | 1 - src/detection/displayserver/displayServer.c | 1 + src/detection/displayserver/wayland.c | 5 ++++- src/detection/displayserver/wmde.c | 6 ++++-- src/detection/displayserver/xcb.c | 4 +++- src/detection/displayserver/xlib.c | 1 + src/detection/media.c | 1 + src/detection/os.c | 1 + src/detection/plasma.c | 1 + src/detection/temps.c | 3 +-- src/detection/terminalShell.c | 1 + src/detection/vulkan.c | 2 ++ src/fastfetch.c | 6 ++---- src/fastfetch.h | 11 +++-------- src/logo/image/im6.c | 2 ++ src/logo/image/im7.c | 2 ++ src/logo/image/image.c | 2 ++ src/modules/battery.c | 3 --- src/modules/cpu.c | 3 +-- src/modules/cpuUsage.c | 1 - src/modules/cursor.c | 2 ++ src/modules/de.c | 2 -- src/modules/gpu.c | 6 +++--- src/modules/host.c | 6 +++++- src/modules/locale.c | 2 ++ src/modules/localip.c | 3 +-- src/modules/memory.c | 2 ++ src/modules/opencl.c | 2 ++ src/modules/opengl.c | 1 + src/modules/packages.c | 3 +++ src/modules/shell.c | 3 --- src/modules/terminal.c | 2 -- src/modules/wmtheme.c | 2 ++ src/util/FFlist.c | 3 +-- src/util/FFstrbuf.c | 3 +-- src/util/FFvaluestore.c | 7 +++---- src/util/FFvaluestore.h | 1 + 45 files changed, 70 insertions(+), 50 deletions(-) diff --git a/src/common/caching.c b/src/common/caching.c index 804cac2c0..cc51bd08b 100644 --- a/src/common/caching.c +++ b/src/common/caching.c @@ -1,5 +1,7 @@ #include "fastfetch.h" +#include + #define FF_CACHE_VALUE_EXTENSION "ffcv" #define FF_CACHE_SPLIT_EXTENSION "ffcs" diff --git a/src/common/init.c b/src/common/init.c index 27ba23f86..4c4ecc775 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -1,5 +1,6 @@ #include "fastfetch.h" +#include #include #include #include diff --git a/src/common/io.c b/src/common/io.c index 51d99afff..535479889 100644 --- a/src/common/io.c +++ b/src/common/io.c @@ -1,9 +1,8 @@ #include "fastfetch.h" -#include +#include #include #include -#include #include #include diff --git a/src/common/library.c b/src/common/library.c index 8ba62bda0..7199f524a 100644 --- a/src/common/library.c +++ b/src/common/library.c @@ -1,6 +1,7 @@ #include "fastfetch.h" #include +#include static void* libraryLoad(const char* path, int maxVersion) { diff --git a/src/common/networking.c b/src/common/networking.c index 6a27a6ffe..615c5b163 100644 --- a/src/common/networking.c +++ b/src/common/networking.c @@ -1,6 +1,5 @@ #include "fastfetch.h" -#include #include #include #include diff --git a/src/common/processing.c b/src/common/processing.c index 585ed8862..4a00fd533 100644 --- a/src/common/processing.c +++ b/src/common/processing.c @@ -1,6 +1,6 @@ #include "fastfetch.h" -#include +#include #include #include diff --git a/src/common/properties.c b/src/common/properties.c index a6b3f2ba5..c8ff1947b 100644 --- a/src/common/properties.c +++ b/src/common/properties.c @@ -1,5 +1,7 @@ #include "fastfetch.h" +#include + static bool parsePropLinePointer(const char** line, const char* start, FFstrbuf* buffer) { if(**line == '\0') diff --git a/src/common/settings.c b/src/common/settings.c index 17be91f5c..065db007b 100644 --- a/src/common/settings.c +++ b/src/common/settings.c @@ -2,6 +2,7 @@ #include #include +#include #define FF_LIBRARY_DATA_LOAD_INIT(dataObject, userLibraryName, ...) \ static dataObject data; \ diff --git a/src/detection/datetime.c b/src/detection/datetime.c index b4a74b3f8..356633d18 100644 --- a/src/detection/datetime.c +++ b/src/detection/datetime.c @@ -1,7 +1,6 @@ #include "fastfetch.h" #include - #include const FFDateTimeResult* ffDetectDateTime(const FFinstance* instance) diff --git a/src/detection/displayserver/displayServer.c b/src/detection/displayserver/displayServer.c index af8a331d6..087f0e2e2 100644 --- a/src/detection/displayserver/displayServer.c +++ b/src/detection/displayserver/displayServer.c @@ -1,4 +1,5 @@ #include "displayServer.h" + #include #include diff --git a/src/detection/displayserver/wayland.c b/src/detection/displayserver/wayland.c index c6a7fd858..031abb084 100644 --- a/src/detection/displayserver/wayland.c +++ b/src/detection/displayserver/wayland.c @@ -1,9 +1,12 @@ #include "displayServer.h" + +#include #include #ifdef FF_HAVE_WAYLAND -#include #include +#include +#include typedef struct WaylandData { diff --git a/src/detection/displayserver/wmde.c b/src/detection/displayserver/wmde.c index ccc231592..1cb4271b2 100644 --- a/src/detection/displayserver/wmde.c +++ b/src/detection/displayserver/wmde.c @@ -1,8 +1,10 @@ #include "displayServer.h" -#include + +#include +#include #include #include -#include +#include static const char* parseEnv() { diff --git a/src/detection/displayserver/xcb.c b/src/detection/displayserver/xcb.c index de798c7bd..43f136bdd 100644 --- a/src/detection/displayserver/xcb.c +++ b/src/detection/displayserver/xcb.c @@ -1,8 +1,10 @@ #include "displayServer.h" #ifdef FF_HAVE_XCB -#include +#include #include +#include +#include typedef struct XcbPropertyData { diff --git a/src/detection/displayserver/xlib.c b/src/detection/displayserver/xlib.c index fc2097ce3..a20f16d58 100644 --- a/src/detection/displayserver/xlib.c +++ b/src/detection/displayserver/xlib.c @@ -1,6 +1,7 @@ #include "displayServer.h" #ifdef FF_HAVE_X11 +#include #include typedef struct X11PropertyData diff --git a/src/detection/media.c b/src/detection/media.c index e3432acae..f87d08a0c 100644 --- a/src/detection/media.c +++ b/src/detection/media.c @@ -7,6 +7,7 @@ #define FF_DBUS_TIMEOUT_MILLISECONDS 35 #ifdef FF_HAVE_DBUS +#include #include #define FF_DBUS_ITER_CONTINUE(iterator) \ diff --git a/src/detection/os.c b/src/detection/os.c index abe4eff33..ef975555a 100644 --- a/src/detection/os.c +++ b/src/detection/os.c @@ -1,6 +1,7 @@ #include "fastfetch.h" #include +#include #include #if !defined(__ANDROID__) diff --git a/src/detection/plasma.c b/src/detection/plasma.c index fa5d91c3b..2885209e2 100644 --- a/src/detection/plasma.c +++ b/src/detection/plasma.c @@ -1,5 +1,6 @@ #include "fastfetch.h" +#include #include #include diff --git a/src/detection/temps.c b/src/detection/temps.c index b086a424c..4a6928768 100644 --- a/src/detection/temps.c +++ b/src/detection/temps.c @@ -1,9 +1,8 @@ #include "fastfetch.h" +#include #include #include -#include -#include static bool isTempFile(const char* name) { diff --git a/src/detection/terminalShell.c b/src/detection/terminalShell.c index c4cabff20..374cf260e 100644 --- a/src/detection/terminalShell.c +++ b/src/detection/terminalShell.c @@ -2,6 +2,7 @@ #include #include +#include #include #include diff --git a/src/detection/vulkan.c b/src/detection/vulkan.c index dd2c1ab8c..f9451db63 100644 --- a/src/detection/vulkan.c +++ b/src/detection/vulkan.c @@ -3,6 +3,8 @@ #include #ifdef FF_HAVE_VULKAN +#include +#include #include static inline void applyVulkanVersion(uint32_t vulkanVersion, FFVersion* ffVersion) diff --git a/src/fastfetch.c b/src/fastfetch.c index d646f47d1..ae5591b35 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1,11 +1,9 @@ #include "fastfetch.h" +#include #include -#include -#include -#include -#include #include +#include // Things only needed by fastfetch typedef struct FFdata diff --git a/src/fastfetch.h b/src/fastfetch.h index 535c9cd9e..83c5efae3 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -3,20 +3,15 @@ #ifndef FASTFETCH_INCLUDED #define FASTFETCH_INCLUDED -#include +#include "fastfetch_config.h" + #include #include -#include -#include -#include + #include #include #include #include -#include -#include - -#include "fastfetch_config.h" #include "util/FFstrbuf.h" #include "util/FFlist.h" diff --git a/src/logo/image/im6.c b/src/logo/image/im6.c index 2f8421eb0..3ff9dec43 100644 --- a/src/logo/image/im6.c +++ b/src/logo/image/im6.c @@ -1,6 +1,8 @@ #ifdef FF_HAVE_IMAGEMAGICK6 #include "image.h" + +#include #include static FF_LIBRARY_SYMBOL(ResizeImage); diff --git a/src/logo/image/im7.c b/src/logo/image/im7.c index 7f76cfd59..1ac0e6ebf 100644 --- a/src/logo/image/im7.c +++ b/src/logo/image/im7.c @@ -1,6 +1,8 @@ #ifdef FF_HAVE_IMAGEMAGICK7 #include "image.h" + +#include #include static FF_LIBRARY_SYMBOL(ResizeImage); diff --git a/src/logo/image/image.c b/src/logo/image/image.c index 307cbd579..9741e5c87 100644 --- a/src/logo/image/image.c +++ b/src/logo/image/image.c @@ -17,6 +17,8 @@ #include #ifdef FF_HAVE_ZLIB +#include +#include #include static bool compressBlob(const FFinstance* instance, void** blob, size_t* length) diff --git a/src/modules/battery.c b/src/modules/battery.c index b0745c03a..1ef5e131a 100644 --- a/src/modules/battery.c +++ b/src/modules/battery.c @@ -1,10 +1,7 @@ #include "fastfetch.h" -#include #include -#include - #define FF_BATTERY_MODULE_NAME "Battery" #define FF_BATTERY_NUM_FORMAT_ARGS 5 diff --git a/src/modules/cpu.c b/src/modules/cpu.c index 93c414531..20625d99a 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -1,7 +1,6 @@ #include "fastfetch.h" -#include -#include +#include #define FF_CPU_MODULE_NAME "CPU" #define FF_CPU_NUM_FORMAT_ARGS 15 diff --git a/src/modules/cpuUsage.c b/src/modules/cpuUsage.c index 854abae58..41d23d6c7 100644 --- a/src/modules/cpuUsage.c +++ b/src/modules/cpuUsage.c @@ -1,6 +1,5 @@ #include "fastfetch.h" -#include #include #define FF_CPU_USAGE_MODULE_NAME "CPU Usage" diff --git a/src/modules/cursor.c b/src/modules/cursor.c index 8d1e191d1..e88a78b5b 100644 --- a/src/modules/cursor.c +++ b/src/modules/cursor.c @@ -1,5 +1,7 @@ #include "fastfetch.h" +#include + #define FF_CURSOR_MODULE_NAME "Cursor" #define FF_CURSOR_NUM_FORMAT_ARGS 2 diff --git a/src/modules/de.c b/src/modules/de.c index b8f1a4852..fe611c60d 100644 --- a/src/modules/de.c +++ b/src/modules/de.c @@ -1,7 +1,5 @@ #include "fastfetch.h" -#include - #define FF_DE_MODULE_NAME "DE" #define FF_DE_NUM_FORMAT_ARGS 3 diff --git a/src/modules/gpu.c b/src/modules/gpu.c index ec58421e8..2f1effde8 100644 --- a/src/modules/gpu.c +++ b/src/modules/gpu.c @@ -1,7 +1,5 @@ #include "fastfetch.h" -#include - #define FF_GPU_MODULE_NAME "GPU" #define FF_GPU_NUM_FORMAT_ARGS 6 @@ -61,8 +59,10 @@ static void printGPUList(FFinstance* instance, const FFlist* list) } #ifdef FF_HAVE_LIBPCI -#include +#include #include +#include +#include //see https://github.com/pciutils/pciutils/blob/5bdf63b6b1bc35b59c4b3f47f7ca83ca1868155b/ls-kernel.c#L220 static void pciGetDriver(struct pci_dev* dev, FFstrbuf* driver, char*(*ffpci_get_param)(struct pci_access*, char*)) diff --git a/src/modules/host.c b/src/modules/host.c index 7679dca08..8f3979524 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -1,10 +1,14 @@ #include "fastfetch.h" -#include +#include #define FF_HOST_MODULE_NAME "Host" #define FF_HOST_NUM_FORMAT_ARGS 15 +#ifdef __ANDROID__ + #include +#endif + #ifndef __ANDROID__ static bool hostValueSet(FFstrbuf* value) { diff --git a/src/modules/locale.c b/src/modules/locale.c index c226ddd31..ebc775a12 100644 --- a/src/modules/locale.c +++ b/src/modules/locale.c @@ -1,5 +1,7 @@ #include "fastfetch.h" +#include + #define FF_LOCALE_MODULE_NAME "Locale" #define FF_LOCALE_NUM_FORMAT_ARGS 1 diff --git a/src/modules/localip.c b/src/modules/localip.c index f5590376d..35f9f4324 100644 --- a/src/modules/localip.c +++ b/src/modules/localip.c @@ -3,10 +3,9 @@ #define FF_LOCALIP_MODULE_NAME "Local IP" #define FF_LOCALIP_NUM_FORMAT_ARGS 1 -#include +#include #include #include -#include #include static void printValue(FFinstance* instance, const char* ifaName, const char* addressBuffer) diff --git a/src/modules/memory.c b/src/modules/memory.c index dd6ff0771..95b86a9f8 100644 --- a/src/modules/memory.c +++ b/src/modules/memory.c @@ -1,5 +1,7 @@ #include "fastfetch.h" +#include + #define FF_MEMORY_MODULE_NAME "Memory" #define FF_MEMORY_NUM_FORMAT_ARGS 3 diff --git a/src/modules/opencl.c b/src/modules/opencl.c index a64964a17..1a08a9646 100644 --- a/src/modules/opencl.c +++ b/src/modules/opencl.c @@ -4,6 +4,8 @@ #define FF_OPENCL_NUM_FORMAT_ARGS 3 #ifdef FF_HAVE_OPENCL +#include + #define CL_TARGET_OPENCL_VERSION 100 #include diff --git a/src/modules/opengl.c b/src/modules/opengl.c index 88e2768b2..47fec4685 100644 --- a/src/modules/opengl.c +++ b/src/modules/opengl.c @@ -7,6 +7,7 @@ #if defined(FF_HAVE_EGL) || defined(FF_HAVE_GLX) || defined(FF_HAVE_OSMESA) #define FF_HAVE_GL 1 +#include #include #define FF_OPENGL_BUFFER_WIDTH 1 diff --git a/src/modules/packages.c b/src/modules/packages.c index 12c89f6fd..5ff7c2913 100644 --- a/src/modules/packages.c +++ b/src/modules/packages.c @@ -1,7 +1,9 @@ #include "fastfetch.h" +#include #include #include +#include #define FF_PACKAGES_MODULE_NAME "Packages" #define FF_PACKAGES_NUM_FORMAT_ARGS 11 @@ -128,6 +130,7 @@ static uint32_t getNixPackages(char* path) } #ifdef FF_HAVE_RPM +#include #include #include #include diff --git a/src/modules/shell.c b/src/modules/shell.c index 4f7cfe5c4..83d03cea3 100644 --- a/src/modules/shell.c +++ b/src/modules/shell.c @@ -1,8 +1,5 @@ #include "fastfetch.h" -#include -#include - #define FF_SHELL_MODULE_NAME "Shell" #define FF_SHELL_NUM_FORMAT_ARGS 7 diff --git a/src/modules/terminal.c b/src/modules/terminal.c index ceddefe78..1b51e9b5c 100644 --- a/src/modules/terminal.c +++ b/src/modules/terminal.c @@ -1,8 +1,6 @@ #include "fastfetch.h" #include -#include -#include #define FF_TERMINAL_MODULE_NAME "Terminal" #define FF_TERMINAL_NUM_FORMAT_ARGS 3 diff --git a/src/modules/wmtheme.c b/src/modules/wmtheme.c index 18a5dd5b0..771b35f36 100644 --- a/src/modules/wmtheme.c +++ b/src/modules/wmtheme.c @@ -1,4 +1,6 @@ #include "fastfetch.h" + +#include #include #define FF_WMTHEME_MODULE_NAME "WM Theme" diff --git a/src/util/FFlist.c b/src/util/FFlist.c index 31d7d6500..07cab9cab 100644 --- a/src/util/FFlist.c +++ b/src/util/FFlist.c @@ -1,7 +1,6 @@ #include "FFlist.h" -#include -#include +#include void ffListInit(FFlist* list, uint32_t elementSize) { diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index 354847063..541ab3651 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -1,9 +1,8 @@ #include "FFstrbuf.h" -#include +#include #include #include -#include static char* CHAR_NULL_PTR = ""; diff --git a/src/util/FFvaluestore.c b/src/util/FFvaluestore.c index 1b42b4b67..0fb7a70a6 100644 --- a/src/util/FFvaluestore.c +++ b/src/util/FFvaluestore.c @@ -1,9 +1,8 @@ -#include -#include -#include - #include "FFvaluestore.h" +#include +#include + void ffValuestoreInit(FFvaluestore* vs) { vs->capacity = 32; diff --git a/src/util/FFvaluestore.h b/src/util/FFvaluestore.h index 4fcf2eb60..963eb8819 100644 --- a/src/util/FFvaluestore.h +++ b/src/util/FFvaluestore.h @@ -4,6 +4,7 @@ #define FASTFETCH_INCLUDED_FFVALUESTORE #include +#include typedef struct FFvaluestorePair { From 9d3f762c20584308bb7f184c13e492874608c654 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sat, 18 Jun 2022 15:27:46 +0200 Subject: [PATCH 30/55] Better fallback for wayland detection --- src/detection/displayserver/wayland.c | 50 ++++++++++++--------------- 1 file changed, 23 insertions(+), 27 deletions(-) diff --git a/src/detection/displayserver/wayland.c b/src/detection/displayserver/wayland.c index 031abb084..85d0503ed 100644 --- a/src/detection/displayserver/wayland.c +++ b/src/detection/displayserver/wayland.c @@ -76,32 +76,29 @@ static void waylandGlobalAddListener(void* data, struct wl_registry* registry, u } } -void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* result) +bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) { - if(getenv("XDG_RUNTIME_DIR") == NULL) - return; + FF_LIBRARY_LOAD(wayland, instance->config.libWayland, false, "libwayland-client.so", 1) - FF_LIBRARY_LOAD(wayland, instance->config.libWayland, , "libwayland-client.so", 1) - - FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_connect,) - FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_dispatch,) - FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_roundtrip,) - FF_LIBRARY_LOAD_SYMBOL(wayland, wl_proxy_marshal_constructor,) - FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_disconnect,) - FF_LIBRARY_LOAD_SYMBOL(wayland, wl_registry_interface,) + FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_connect, false) + FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_dispatch, false) + FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_roundtrip, false) + FF_LIBRARY_LOAD_SYMBOL(wayland, wl_proxy_marshal_constructor, false) + FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_disconnect, false) + FF_LIBRARY_LOAD_SYMBOL(wayland, wl_registry_interface, false) WaylandData data; - FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_marshal_constructor_versioned, wl_proxy_marshal_constructor_versioned,) - FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_add_listener, wl_proxy_add_listener,) - FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_output_interface, wl_output_interface,) - FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_destroy, wl_proxy_destroy,) + FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_marshal_constructor_versioned, wl_proxy_marshal_constructor_versioned, false) + FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_add_listener, wl_proxy_add_listener, false) + FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_output_interface, wl_output_interface, false) + FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_destroy, wl_proxy_destroy, false) struct wl_display* display = ffwl_display_connect(NULL); if(display == NULL) { dlclose(wayland); - return; + return false; } struct wl_registry* registry = (struct wl_registry*) ffwl_proxy_marshal_constructor((struct wl_proxy*) display, WL_DISPLAY_GET_REGISTRY, ffwl_registry_interface, NULL); @@ -109,7 +106,7 @@ void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* resul { ffwl_display_disconnect(display); dlclose(wayland); - return; + return false; } data.instance = instance; @@ -136,20 +133,21 @@ void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* resul //So we can set set the session type to wayland. //This is used as an indicator that we are running wayland by the x11 backends. ffStrbufSetS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_WAYLAND); + return true; } - -#else +#endif void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* result) { - FF_UNUSED(instance); - - //We try to detect wayland already here, so the x11 methods only to resolution detection. - //Wayland requires this to be set if(getenv("XDG_RUNTIME_DIR") == NULL) return; + #ifdef FF_HAVE_WAYLAND + if(detectWayland(instance, result)) + return; + #endif + const char* xdgSessionType = getenv("XDG_SESSION_TYPE"); //If XDG_SESSION_TYPE is set, and doesn't contain "wayland", we are probably not running in a wayland session. @@ -161,9 +159,7 @@ void ffdsConnectWayland(const FFinstance* instance, FFDisplayServerResult* resul if(xdgSessionType == NULL && getenv("WAYLAND_DISPLAY") == NULL && getenv("WAYLAND_SOCKET") == NULL) return; - //We are probably running a wayland compositor at this point, but fastfetch was compiled without the required library. - //Set the protocol name and use DRM for resolution detection. + //We are probably running a wayland compositor at this point, + //but fastfetch was compiled without the required library, or loading the library failed. ffStrbufSetS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_WAYLAND); } - -#endif From 9176797327fb7df691a66c332ef095517ccb6fad Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sat, 18 Jun 2022 14:51:10 +0200 Subject: [PATCH 31/55] Detect Windows Terminal better --- src/detection/terminalShell.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/detection/terminalShell.c b/src/detection/terminalShell.c index 374cf260e..eaa7ae5da 100644 --- a/src/detection/terminalShell.c +++ b/src/detection/terminalShell.c @@ -120,8 +120,10 @@ static void getTerminalFromEnv(FFTerminalShellResult* result) term = getenv("SSH_TTY"); //Windows Terminal - if(!ffStrSet(term) && getenv("WT_SESSION") != NULL) - term = "Windows Terminal"; + if(!ffStrSet(term) && ( + getenv("WT_SESSION") != NULL || + getenv("WT_PROFILE_ID") != NULL + )) term = "Windows Terminal"; //Termux if(!ffStrSet(term) && ( From 26d17250b6b0767d14ecf1f2427f74a6d5d37de2 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sat, 18 Jun 2022 14:55:56 +0200 Subject: [PATCH 32/55] Detect WSLg --- src/detection/displayserver/wmde.c | 6 ++++++ src/detection/displayserver/xcb.c | 2 +- src/detection/displayserver/xlib.c | 2 +- src/modules/cursor.c | 6 ++++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/detection/displayserver/wmde.c b/src/detection/displayserver/wmde.c index 1cb4271b2..6c4069a14 100644 --- a/src/detection/displayserver/wmde.c +++ b/src/detection/displayserver/wmde.c @@ -5,6 +5,7 @@ #include #include #include +#include static const char* parseEnv() { @@ -42,6 +43,11 @@ static const char* parseEnv() if(getenv("TDE_FULL_SESSION") != NULL) return "Trinity"; + if( + getenv("WAYLAND_DISPLAY") != NULL && + ffFileExists("/mnt/wslg/", S_IFDIR) + ) return "WSLg"; + return NULL; } diff --git a/src/detection/displayserver/xcb.c b/src/detection/displayserver/xcb.c index 43f136bdd..0953aff9c 100644 --- a/src/detection/displayserver/xcb.c +++ b/src/detection/displayserver/xcb.c @@ -62,7 +62,7 @@ static void* xcbGetProperty(XcbPropertyData* data, xcb_connection_t* connection, static void xcbDetectWMfromEWMH(XcbPropertyData* data, xcb_connection_t* connection, xcb_window_t rootWindow, FFDisplayServerResult* result) { - if(result->wmProcessName.length > 0) + if(result->wmProcessName.length > 0 || ffStrbufCompS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_WAYLAND) == 0) return; xcb_window_t* wmWindow = (xcb_window_t*) xcbGetProperty(data, connection, rootWindow, "_NET_SUPPORTING_WM_CHECK"); diff --git a/src/detection/displayserver/xlib.c b/src/detection/displayserver/xlib.c index a20f16d58..178646661 100644 --- a/src/detection/displayserver/xlib.c +++ b/src/detection/displayserver/xlib.c @@ -35,7 +35,7 @@ static unsigned char* x11GetProperty(X11PropertyData* data, Display* display, Wi static void x11DetectWMFromEWMH(X11PropertyData* data, Display* display, FFDisplayServerResult* result) { - if(result->wmProcessName.length > 0) + if(result->wmProcessName.length > 0 || ffStrbufCompS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_WAYLAND) == 0) return; Window* wmWindow = (Window*) x11GetProperty(data, display, DefaultRootWindow(display), "_NET_SUPPORTING_WM_CHECK"); diff --git a/src/modules/cursor.c b/src/modules/cursor.c index e88a78b5b..9b978a620 100644 --- a/src/modules/cursor.c +++ b/src/modules/cursor.c @@ -193,6 +193,12 @@ void ffPrintCursor(FFinstance* instance) const FFDisplayServerResult* wmde = ffConnectDisplayServer(instance); + if(ffStrbufCompS(&wmde->wmPrettyName, "WSLg") == 0) + { + ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "WSLg uses native windows cursor"); + return; + } + if(ffStrbufIgnCaseCompS(&wmde->wmProtocolName, "TTY") == 0) { ffPrintError(instance, FF_CURSOR_MODULE_NAME, 0, &instance->config.cursor, "Cursor isn't supported in TTY"); From fb35a6e889ab5ff48303b38077351d698228292f Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sat, 18 Jun 2022 23:39:48 +0200 Subject: [PATCH 33/55] Release 1.5.4 Feature: Better WSL / WSLg support Feature: ---error arguments Bugfix: Show GiB instad of GB Feature: Export much more information to host format string Feature: Expose CPU temp to cpu format string Feature: Expose GPU temp to gpi format string Bugfix: Print last line of logo, if it is higher than the infos Logo: Alpine Linux Refactor: Cleaned up header includes Refactor: Build libfastfetch as OBJECT lib, as the linked binary is never needed Feature: Detect termux as terminal --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9233ab112..554834795 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs project(fastfetch - VERSION 1.5.3 + VERSION 1.5.4 LANGUAGES C ) From 45eae7898013af717f97fa932d49416fd415965d Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sun, 19 Jun 2022 18:21:41 +0200 Subject: [PATCH 34/55] Better ordering in initCacheDir --- src/common/init.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/common/init.c b/src/common/init.c index 4c4ecc775..e93c5f98d 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -23,10 +23,6 @@ static void initConfigDirs(FFstate* state) ffStrbufTrimRight(buffer, '/'); } - FFstrbuf xdgConfigDirs; - ffStrbufInitA(&xdgConfigDirs, 64); - ffStrbufAppendS(&xdgConfigDirs, getenv("XDG_CONFIG_DIRS")); - #define FF_ENSURE_ONLY_ONCE_IN_LIST(element) \ if(ffListFirstIndexComp(&state->configDirs, element, strbufEqualsAdapter) < state->configDirs.length - 1) \ --state->configDirs.length; @@ -42,6 +38,10 @@ static void initConfigDirs(FFstate* state) ffStrbufAppendS(userHome, state->passwd->pw_dir); FF_ENSURE_ONLY_ONCE_IN_LIST(userHome) + FFstrbuf xdgConfigDirs; + ffStrbufInitA(&xdgConfigDirs, 64); + ffStrbufAppendS(&xdgConfigDirs, getenv("XDG_CONFIG_DIRS")); + uint32_t startIndex = 0; while (startIndex < xdgConfigDirs.length) { From 6e731c80d01259eb085a958b3be1b7b3de8fdf83 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sun, 19 Jun 2022 18:22:00 +0200 Subject: [PATCH 35/55] Refactored write methods --- src/common/caching.c | 2 +- src/common/io.c | 24 +++++++++++++++++------- src/fastfetch.h | 7 +++++-- src/logo/image/image.c | 4 ++-- 4 files changed, 25 insertions(+), 12 deletions(-) diff --git a/src/common/caching.c b/src/common/caching.c index cc51bd08b..ffb0b3acf 100644 --- a/src/common/caching.c +++ b/src/common/caching.c @@ -31,7 +31,7 @@ static void writeCacheFile(FFinstance* instance, const char* moduleName, const c FFstrbuf path; ffStrbufInitA(&path, 64); getCacheFilePath(instance, moduleName, extension, &path); - ffWriteFileContent(path.chars, content); + ffWriteFileBuffer(path.chars, content); ffStrbufDestroy(&path); } diff --git a/src/common/io.c b/src/common/io.c index 535479889..016346d59 100644 --- a/src/common/io.c +++ b/src/common/io.c @@ -6,11 +6,6 @@ #include #include -bool ffWriteFDContent(int fd, const FFstrbuf* content) -{ - return write(fd, content->chars, content->length) != -1; -} - static void createSubfolders(const char* fileName) { FFstrbuf path; @@ -27,7 +22,17 @@ static void createSubfolders(const char* fileName) ffStrbufDestroy(&path); } -bool ffWriteFileContent(const char* fileName, const FFstrbuf* content) +bool ffWriteFDData(int fd, size_t dataSize, const void* data) +{ + return write(fd, data, dataSize) != -1; +} + +bool ffWriteFDBuffer(int fd, const FFstrbuf* content) +{ + return ffWriteFDData(fd, content->length, content->chars); +} + +bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data) { int openFlagsModes = O_WRONLY | O_CREAT | O_TRUNC; int openFlagsRights = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH; @@ -41,13 +46,18 @@ bool ffWriteFileContent(const char* fileName, const FFstrbuf* content) return false; } - bool ret = ffWriteFDContent(fd, content); + bool ret = ffWriteFDData(fd, dataSize, data); close(fd); return ret; } +bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer) +{ + return ffWriteFileData(fileName, buffer->length, buffer->chars); +} + void ffAppendFDContent(int fd, FFstrbuf* buffer) { ssize_t readed = 0; diff --git a/src/fastfetch.h b/src/fastfetch.h index 83c5efae3..31acd1e2c 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -413,11 +413,14 @@ void ffListFeatures(); void ffStartDetectionThreads(FFinstance* instance); //common/io.c +bool ffWriteFDData(int fd, size_t dataSize, const void* data); +bool ffWriteFDBuffer(int fd, const FFstrbuf* content); +bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data); +bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer); + void ffAppendFDContent(int fd, FFstrbuf* buffer); bool ffAppendFileContent(const char* fileName, FFstrbuf* buffer); //returns true if open() succeeds. This is used to differentiate between and bool ffGetFileContent(const char* fileName, FFstrbuf* buffer); -bool ffWriteFDContent(int fd, const FFstrbuf* content); -bool ffWriteFileContent(const char* fileName, const FFstrbuf* buffer); bool ffFileExists(const char* fileName, mode_t mode); void ffSuppressIO(bool suppress); // Not thread safe! diff --git a/src/logo/image/image.c b/src/logo/image/image.c index 9741e5c87..bf0aacbc3 100644 --- a/src/logo/image/image.c +++ b/src/logo/image/image.c @@ -94,7 +94,7 @@ static void writeCacheStrbuf(FFLogoRequestData* requestData, const FFstrbuf* val { uint32_t cacheDirLength = requestData->cacheDir.length; ffStrbufAppendS(&requestData->cacheDir, cacheFileName); - ffWriteFileContent(requestData->cacheDir.chars, value); + ffWriteFileBuffer(requestData->cacheDir.chars, value); ffStrbufSubstrBefore(&requestData->cacheDir, cacheDirLength); } @@ -127,7 +127,7 @@ static void printImagePixels(FFinstance* instance, FFLogoRequestData* requestDat //Write result to stdout ffPrintCharTimes(' ', instance->config.logoPaddingLeft); fflush(stdout); - ffWriteFDContent(STDOUT_FILENO, result); + ffWriteFDBuffer(STDOUT_FILENO, result); //Go to upper left corner fputs("\033[9999999D", stdout); From 8fa09ca0931ca6d79c1e2b361c8cb14b8add61fe Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Mon, 20 Jun 2022 16:27:33 +0200 Subject: [PATCH 36/55] Refactored read methods --- src/common/caching.c | 4 +++- src/common/io.c | 36 ++++++++++++++++++++---------- src/common/processing.c | 2 +- src/detection/displayserver/wmde.c | 4 ++-- src/detection/temps.c | 6 ++--- src/detection/terminalShell.c | 2 +- src/fastfetch.h | 8 +++---- src/logo/image/image.c | 2 +- src/logo/logo.c | 2 +- src/modules/battery.c | 14 ++++++------ src/modules/cpu.c | 4 ++-- src/modules/host.c | 8 +++---- 12 files changed, 53 insertions(+), 39 deletions(-) diff --git a/src/common/caching.c b/src/common/caching.c index ffb0b3acf..49374a5b3 100644 --- a/src/common/caching.c +++ b/src/common/caching.c @@ -5,6 +5,8 @@ #define FF_CACHE_VALUE_EXTENSION "ffcv" #define FF_CACHE_SPLIT_EXTENSION "ffcs" +#define FF_CACHE_EXTENSION_STRUCT "ffcs2" + static void getCacheFilePath(FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer) { ffStrbufAppend(buffer, &instance->state.cacheDir); @@ -22,7 +24,7 @@ static void readCacheFile(FFinstance* instance, const char* moduleName, const ch FFstrbuf path; ffStrbufInitA(&path, 64); getCacheFilePath(instance, moduleName, extension, &path); - ffAppendFileContent(path.chars, buffer); + ffAppendFileBuffer(path.chars, buffer); ffStrbufDestroy(&path); } diff --git a/src/common/io.c b/src/common/io.c index 016346d59..62e220e92 100644 --- a/src/common/io.c +++ b/src/common/io.c @@ -22,14 +22,10 @@ static void createSubfolders(const char* fileName) ffStrbufDestroy(&path); } -bool ffWriteFDData(int fd, size_t dataSize, const void* data) -{ - return write(fd, data, dataSize) != -1; -} bool ffWriteFDBuffer(int fd, const FFstrbuf* content) { - return ffWriteFDData(fd, content->length, content->chars); + return write(fd, content->chars, content->length) != -1; } bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data) @@ -46,7 +42,7 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data) return false; } - bool ret = ffWriteFDData(fd, dataSize, data); + bool ret = write(fd, data, dataSize) != -1; close(fd); @@ -58,7 +54,7 @@ bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer) return ffWriteFileData(fileName, buffer->length, buffer->chars); } -void ffAppendFDContent(int fd, FFstrbuf* buffer) +bool ffAppendFDBuffer(int fd, FFstrbuf* buffer) { ssize_t readed = 0; @@ -82,24 +78,40 @@ void ffAppendFDContent(int fd, FFstrbuf* buffer) ffStrbufTrimRight(buffer, '\n'); ffStrbufTrimRight(buffer, ' '); + + return readed >= 0; } -bool ffAppendFileContent(const char* fileName, FFstrbuf* buffer) +ssize_t ffGetFileData(const char* fileName, size_t dataSize, void* data) +{ + int fd = open(fileName, O_RDONLY); + if(fd == -1) + return -1; + + ssize_t readed = read(fd, data, dataSize); + + close(fd); + + return readed; +} + +bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) { int fd = open(fileName, O_RDONLY); if(fd == -1) return false; - ffAppendFDContent(fd, buffer); + bool ret = ffAppendFDBuffer(fd, buffer); close(fd); - return true; + + return ret; } -bool ffGetFileContent(const char* fileName, FFstrbuf* buffer) +bool ffGetFileBuffer(const char* fileName, FFstrbuf* buffer) { ffStrbufClear(buffer); - return ffAppendFileContent(fileName, buffer); + return ffAppendFileBuffer(fileName, buffer); } // Not thread safe! diff --git a/src/common/processing.c b/src/common/processing.c index 4a00fd533..95c3dcb6d 100644 --- a/src/common/processing.c +++ b/src/common/processing.c @@ -29,6 +29,6 @@ void ffProcessAppendStdOut(FFstrbuf* buffer, char* const argv[]) //Parent close(pipes[1]); waitpid(childPid, NULL, 0); - ffAppendFDContent(pipes[0], buffer); + ffAppendFDBuffer(pipes[0], buffer); close(pipes[0]); } diff --git a/src/detection/displayserver/wmde.c b/src/detection/displayserver/wmde.c index 6c4069a14..83b5dbd5e 100644 --- a/src/detection/displayserver/wmde.c +++ b/src/detection/displayserver/wmde.c @@ -337,7 +337,7 @@ static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* re //Don't check for processes not owend by the current user. ffStrbufAppendS(&procPath, "/loginuid"); - ffGetFileContent(procPath.chars, &loginuid); + ffGetFileBuffer(procPath.chars, &loginuid); if(ffStrbufComp(&userID, &loginuid) != 0) { ffStrbufSubstrBefore(&procPath, procPathLength); @@ -348,7 +348,7 @@ static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* re //We check the cmdline for the process name, because it is not trimmed. ffStrbufAppendS(&procPath, "/cmdline"); - ffGetFileContent(procPath.chars, &processName); + ffGetFileBuffer(procPath.chars, &processName); ffStrbufSubstrBeforeFirstC(&processName, '\0'); //Trim the arguments ffStrbufSubstrAfterLastC(&processName, '/'); diff --git a/src/detection/temps.c b/src/detection/temps.c index 4a6928768..c97f7c97a 100644 --- a/src/detection/temps.c +++ b/src/detection/temps.c @@ -32,7 +32,7 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value) continue; ffStrbufAppendS(dir, dirent->d_name); - ffGetFileContent(dir->chars, &valueString); + ffGetFileBuffer(dir->chars, &valueString); ffStrbufSubstrBefore(dir, dirLength); //ffStrbufToDouble() returns NaN if the string couldn't be parsed @@ -51,11 +51,11 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value) return false; ffStrbufAppendS(dir, "name"); - ffGetFileContent(dir->chars, &value->name); + ffGetFileBuffer(dir->chars, &value->name); ffStrbufSubstrBefore(dir, dirLength); ffStrbufAppendS(dir, "device/class"); - ffGetFileContent(dir->chars, &value->deviceClass); + ffGetFileBuffer(dir->chars, &value->deviceClass); ffStrbufSubstrBefore(dir, dirLength); return value->name.length > 0 || value->deviceClass.length > 0; diff --git a/src/detection/terminalShell.c b/src/detection/terminalShell.c index eaa7ae5da..4ac7b6dfa 100644 --- a/src/detection/terminalShell.c +++ b/src/detection/terminalShell.c @@ -21,7 +21,7 @@ static void getProcessInformation(const char* pid, FFstrbuf* processName, FFstrb ffStrbufAppendS(&cmdlineFilePath, pid); ffStrbufAppendS(&cmdlineFilePath, "/cmdline"); - ffGetFileContent(cmdlineFilePath.chars, exe); + ffGetFileBuffer(cmdlineFilePath.chars, exe); ffStrbufSubstrBeforeFirstC(exe, '\0'); //Trim the arguments ffStrbufTrimLeft(exe, '-'); //Happens in TTY diff --git a/src/fastfetch.h b/src/fastfetch.h index 31acd1e2c..b3848577f 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -413,14 +413,14 @@ void ffListFeatures(); void ffStartDetectionThreads(FFinstance* instance); //common/io.c -bool ffWriteFDData(int fd, size_t dataSize, const void* data); bool ffWriteFDBuffer(int fd, const FFstrbuf* content); bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data); bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer); -void ffAppendFDContent(int fd, FFstrbuf* buffer); -bool ffAppendFileContent(const char* fileName, FFstrbuf* buffer); //returns true if open() succeeds. This is used to differentiate between and -bool ffGetFileContent(const char* fileName, FFstrbuf* buffer); +bool ffAppendFDBuffer(int fd, FFstrbuf* buffer); +ssize_t ffGetFileData(const char* fileName, size_t dataSize, void* data); +bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer); +bool ffGetFileBuffer(const char* fileName, FFstrbuf* buffer); bool ffFileExists(const char* fileName, mode_t mode); void ffSuppressIO(bool suppress); // Not thread safe! diff --git a/src/logo/image/image.c b/src/logo/image/image.c index bf0aacbc3..d731b01a7 100644 --- a/src/logo/image/image.c +++ b/src/logo/image/image.c @@ -375,7 +375,7 @@ static void readCachedStrbuf(FFLogoRequestData* requestData, FFstrbuf* result, c { uint32_t cacheDirLength = requestData->cacheDir.length; ffStrbufAppendS(&requestData->cacheDir, cacheFileName); - ffAppendFileContent(requestData->cacheDir.chars, result); + ffAppendFileBuffer(requestData->cacheDir.chars, result); ffStrbufSubstrBefore(&requestData->cacheDir, cacheDirLength); } diff --git a/src/logo/logo.c b/src/logo/logo.c index 0bb5aae41..05faa7af8 100644 --- a/src/logo/logo.c +++ b/src/logo/logo.c @@ -249,7 +249,7 @@ static bool logoPrintFileIfExists(FFinstance* instance, bool doColorReplacement) FFstrbuf content; ffStrbufInitA(&content, 2047); - if(!ffAppendFileContent(instance->config.logoSource.chars, &content)) + if(!ffAppendFileBuffer(instance->config.logoSource.chars, &content)) { ffStrbufDestroy(&content); return false; diff --git a/src/modules/battery.c b/src/modules/battery.c index 1ef5e131a..4af4a310c 100644 --- a/src/modules/battery.c +++ b/src/modules/battery.c @@ -23,7 +23,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results) //type must exist and be "Battery" ffStrbufAppendS(dir, "/type"); - ffGetFileContent(dir->chars, &testBatteryBuffer); + ffGetFileBuffer(dir->chars, &testBatteryBuffer); ffStrbufSubstrBefore(dir, dirLength); if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Battery") != 0) @@ -34,7 +34,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results) //scope may not exist or must not be "Device" ffStrbufAppendS(dir, "/scope"); - ffGetFileContent(dir->chars, &testBatteryBuffer); + ffGetFileBuffer(dir->chars, &testBatteryBuffer); ffStrbufSubstrBefore(dir, dirLength); if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Device") == 0) @@ -49,7 +49,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results) //capacity must exist and be not empty ffStrbufInit(&result->capacity); ffStrbufAppendS(dir, "/capacity"); - ffGetFileContent(dir->chars, &result->capacity); + ffGetFileBuffer(dir->chars, &result->capacity); ffStrbufSubstrBefore(dir, dirLength); if(result->capacity.length == 0) @@ -63,22 +63,22 @@ static void parseBattery(FFstrbuf* dir, FFlist* results) ffStrbufInit(&result->manufacturer); ffStrbufAppendS(dir, "/manufacturer"); - ffGetFileContent(dir->chars, &result->manufacturer); + ffGetFileBuffer(dir->chars, &result->manufacturer); ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->modelName); ffStrbufAppendS(dir, "/model_name"); - ffGetFileContent(dir->chars, &result->modelName); + ffGetFileBuffer(dir->chars, &result->modelName); ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->technology); ffStrbufAppendS(dir, "/technology"); - ffGetFileContent(dir->chars, &result->technology); + ffGetFileBuffer(dir->chars, &result->technology); ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->status); ffStrbufAppendS(dir, "/status"); - ffGetFileContent(dir->chars, &result->status); + ffGetFileBuffer(dir->chars, &result->status); ffStrbufSubstrBefore(dir, dirLength); } diff --git a/src/modules/cpu.c b/src/modules/cpu.c index 20625d99a..36eb5f561 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -10,9 +10,9 @@ static double getGhz(const char* policyFile, const char* cpuFile) FFstrbuf content; ffStrbufInit(&content); - ffGetFileContent(policyFile, &content); + ffGetFileBuffer(policyFile, &content); if(content.length == 0) - ffGetFileContent(cpuFile, &content); + ffGetFileBuffer(cpuFile, &content); double herz = ffStrbufToDouble(&content); diff --git a/src/modules/host.c b/src/modules/host.c index 8f3979524..5992faa05 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -39,10 +39,10 @@ static bool hostValueSet(FFstrbuf* value) static void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer) { - ffGetFileContent(devicesPath, buffer); + ffGetFileBuffer(devicesPath, buffer); if(buffer->length == 0) - ffGetFileContent(classPath, buffer); + ffGetFileBuffer(classPath, buffer); } #endif @@ -67,10 +67,10 @@ void ffPrintHost(FFinstance* instance) getHostValue("/sys/devices/virtual/dmi/id/product_name", "/sys/class/dmi/id/product_name", &product_name); if(product_name.length == 0) - ffGetFileContent("/sys/firmware/devicetree/base/model", &product_name); + ffGetFileBuffer("/sys/firmware/devicetree/base/model", &product_name); if(product_name.length == 0) - ffGetFileContent("/tmp/sysinfo/model", &product_name); + ffGetFileBuffer("/tmp/sysinfo/model", &product_name); if(ffStrbufStartsWithS(&product_name, "Standard PC")) { From af0c72aa6102f12da61e8e5fb5f3115bb313170c Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Mon, 20 Jun 2022 16:35:15 +0200 Subject: [PATCH 37/55] Methods for caching generic data --- src/common/caching.c | 26 ++++++++++++++++++++++++-- src/common/io.c | 4 ++-- src/detection/displayserver/wmde.c | 4 ++-- src/detection/temps.c | 6 +++--- src/detection/terminalShell.c | 2 +- src/fastfetch.h | 7 +++++-- src/modules/battery.c | 14 +++++++------- src/modules/cpu.c | 4 ++-- src/modules/host.c | 8 ++++---- 9 files changed, 50 insertions(+), 25 deletions(-) diff --git a/src/common/caching.c b/src/common/caching.c index 49374a5b3..7aaef69f9 100644 --- a/src/common/caching.c +++ b/src/common/caching.c @@ -5,9 +5,9 @@ #define FF_CACHE_VALUE_EXTENSION "ffcv" #define FF_CACHE_SPLIT_EXTENSION "ffcs" -#define FF_CACHE_EXTENSION_STRUCT "ffcs2" +#define FF_CACHE_EXTENSION_DATA "ffcd" -static void getCacheFilePath(FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer) +static void getCacheFilePath(const FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer) { ffStrbufAppend(buffer, &instance->state.cacheDir); ffStrbufAppendS(buffer, moduleName); @@ -202,3 +202,25 @@ void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const ffPrintAndAppendToCache(instance, moduleName, 0, moduleArgs, &cache, value, numArgs, arguments); ffCacheClose(&cache); } + +void ffCachingWriteData(const FFinstance* instance, const char* moduleName, size_t dataSize, const void* data) +{ + FFstrbuf path; + ffStrbufInitA(&path, 128); + getCacheFilePath(instance, moduleName, FF_CACHE_EXTENSION_DATA, &path); + ffWriteFileData(path.chars, dataSize, data); + ffStrbufDestroy(&path); +} + +bool ffCachingReadData(const FFinstance* instance, const char* moduleName, size_t dataSize, void* data) +{ + if(instance->config.recache) + return false; + + FFstrbuf path; + ffStrbufInitA(&path, 128); + getCacheFilePath(instance, moduleName, FF_CACHE_EXTENSION_DATA, &path); + ssize_t result = ffReadFileData(path.chars, dataSize, data); + ffStrbufDestroy(&path); + return result > 0 && (size_t) result == dataSize; +} diff --git a/src/common/io.c b/src/common/io.c index 62e220e92..8cf2de0c6 100644 --- a/src/common/io.c +++ b/src/common/io.c @@ -82,7 +82,7 @@ bool ffAppendFDBuffer(int fd, FFstrbuf* buffer) return readed >= 0; } -ssize_t ffGetFileData(const char* fileName, size_t dataSize, void* data) +ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data) { int fd = open(fileName, O_RDONLY); if(fd == -1) @@ -108,7 +108,7 @@ bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer) return ret; } -bool ffGetFileBuffer(const char* fileName, FFstrbuf* buffer) +bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer) { ffStrbufClear(buffer); return ffAppendFileBuffer(fileName, buffer); diff --git a/src/detection/displayserver/wmde.c b/src/detection/displayserver/wmde.c index 83b5dbd5e..5327fe89b 100644 --- a/src/detection/displayserver/wmde.c +++ b/src/detection/displayserver/wmde.c @@ -337,7 +337,7 @@ static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* re //Don't check for processes not owend by the current user. ffStrbufAppendS(&procPath, "/loginuid"); - ffGetFileBuffer(procPath.chars, &loginuid); + ffReadFileBuffer(procPath.chars, &loginuid); if(ffStrbufComp(&userID, &loginuid) != 0) { ffStrbufSubstrBefore(&procPath, procPathLength); @@ -348,7 +348,7 @@ static void getFromProcDir(const FFinstance* instance, FFDisplayServerResult* re //We check the cmdline for the process name, because it is not trimmed. ffStrbufAppendS(&procPath, "/cmdline"); - ffGetFileBuffer(procPath.chars, &processName); + ffReadFileBuffer(procPath.chars, &processName); ffStrbufSubstrBeforeFirstC(&processName, '\0'); //Trim the arguments ffStrbufSubstrAfterLastC(&processName, '/'); diff --git a/src/detection/temps.c b/src/detection/temps.c index c97f7c97a..1661865a5 100644 --- a/src/detection/temps.c +++ b/src/detection/temps.c @@ -32,7 +32,7 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value) continue; ffStrbufAppendS(dir, dirent->d_name); - ffGetFileBuffer(dir->chars, &valueString); + ffReadFileBuffer(dir->chars, &valueString); ffStrbufSubstrBefore(dir, dirLength); //ffStrbufToDouble() returns NaN if the string couldn't be parsed @@ -51,11 +51,11 @@ static bool parseHwmonDir(FFstrbuf* dir, FFTempValue* value) return false; ffStrbufAppendS(dir, "name"); - ffGetFileBuffer(dir->chars, &value->name); + ffReadFileBuffer(dir->chars, &value->name); ffStrbufSubstrBefore(dir, dirLength); ffStrbufAppendS(dir, "device/class"); - ffGetFileBuffer(dir->chars, &value->deviceClass); + ffReadFileBuffer(dir->chars, &value->deviceClass); ffStrbufSubstrBefore(dir, dirLength); return value->name.length > 0 || value->deviceClass.length > 0; diff --git a/src/detection/terminalShell.c b/src/detection/terminalShell.c index 4ac7b6dfa..f42947823 100644 --- a/src/detection/terminalShell.c +++ b/src/detection/terminalShell.c @@ -21,7 +21,7 @@ static void getProcessInformation(const char* pid, FFstrbuf* processName, FFstrb ffStrbufAppendS(&cmdlineFilePath, pid); ffStrbufAppendS(&cmdlineFilePath, "/cmdline"); - ffGetFileBuffer(cmdlineFilePath.chars, exe); + ffReadFileBuffer(cmdlineFilePath.chars, exe); ffStrbufSubstrBeforeFirstC(exe, '\0'); //Trim the arguments ffStrbufTrimLeft(exe, '-'); //Happens in TTY diff --git a/src/fastfetch.h b/src/fastfetch.h index b3848577f..9c1c2bb54 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -418,9 +418,9 @@ bool ffWriteFileData(const char* fileName, size_t dataSize, const void* data); bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer); bool ffAppendFDBuffer(int fd, FFstrbuf* buffer); -ssize_t ffGetFileData(const char* fileName, size_t dataSize, void* data); +ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data); bool ffAppendFileBuffer(const char* fileName, FFstrbuf* buffer); -bool ffGetFileBuffer(const char* fileName, FFstrbuf* buffer); +bool ffReadFileBuffer(const char* fileName, FFstrbuf* buffer); bool ffFileExists(const char* fileName, mode_t mode); void ffSuppressIO(bool suppress); // Not thread safe! @@ -446,6 +446,9 @@ bool ffPrintFromCache(FFinstance* instance, const char* moduleName, const FFModu void ffPrintAndAppendToCache(FFinstance* instance, const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFcache* cache, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments); void ffPrintAndWriteToCache(FFinstance* instance, const char* moduleName, const FFModuleArgs* moduleArgs, const FFstrbuf* value, uint32_t numArgs, const FFformatarg* arguments); +void ffCachingWriteData(const FFinstance* instance, const char* moduleName, size_t dataSize, const void* data); +bool ffCachingReadData(const FFinstance* instance, const char* moduleName, size_t dataSize, void* data); + //common/properties.c bool ffParsePropLine(const char* line, const char* start, FFstrbuf* buffer); bool ffParsePropLines(const char* lines, const char* start, FFstrbuf* buffer); diff --git a/src/modules/battery.c b/src/modules/battery.c index 4af4a310c..7af71428b 100644 --- a/src/modules/battery.c +++ b/src/modules/battery.c @@ -23,7 +23,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results) //type must exist and be "Battery" ffStrbufAppendS(dir, "/type"); - ffGetFileBuffer(dir->chars, &testBatteryBuffer); + ffReadFileBuffer(dir->chars, &testBatteryBuffer); ffStrbufSubstrBefore(dir, dirLength); if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Battery") != 0) @@ -34,7 +34,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results) //scope may not exist or must not be "Device" ffStrbufAppendS(dir, "/scope"); - ffGetFileBuffer(dir->chars, &testBatteryBuffer); + ffReadFileBuffer(dir->chars, &testBatteryBuffer); ffStrbufSubstrBefore(dir, dirLength); if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Device") == 0) @@ -49,7 +49,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results) //capacity must exist and be not empty ffStrbufInit(&result->capacity); ffStrbufAppendS(dir, "/capacity"); - ffGetFileBuffer(dir->chars, &result->capacity); + ffReadFileBuffer(dir->chars, &result->capacity); ffStrbufSubstrBefore(dir, dirLength); if(result->capacity.length == 0) @@ -63,22 +63,22 @@ static void parseBattery(FFstrbuf* dir, FFlist* results) ffStrbufInit(&result->manufacturer); ffStrbufAppendS(dir, "/manufacturer"); - ffGetFileBuffer(dir->chars, &result->manufacturer); + ffReadFileBuffer(dir->chars, &result->manufacturer); ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->modelName); ffStrbufAppendS(dir, "/model_name"); - ffGetFileBuffer(dir->chars, &result->modelName); + ffReadFileBuffer(dir->chars, &result->modelName); ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->technology); ffStrbufAppendS(dir, "/technology"); - ffGetFileBuffer(dir->chars, &result->technology); + ffReadFileBuffer(dir->chars, &result->technology); ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->status); ffStrbufAppendS(dir, "/status"); - ffGetFileBuffer(dir->chars, &result->status); + ffReadFileBuffer(dir->chars, &result->status); ffStrbufSubstrBefore(dir, dirLength); } diff --git a/src/modules/cpu.c b/src/modules/cpu.c index 36eb5f561..c5022391c 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -10,9 +10,9 @@ static double getGhz(const char* policyFile, const char* cpuFile) FFstrbuf content; ffStrbufInit(&content); - ffGetFileBuffer(policyFile, &content); + ffReadFileBuffer(policyFile, &content); if(content.length == 0) - ffGetFileBuffer(cpuFile, &content); + ffReadFileBuffer(cpuFile, &content); double herz = ffStrbufToDouble(&content); diff --git a/src/modules/host.c b/src/modules/host.c index 5992faa05..87254559b 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -39,10 +39,10 @@ static bool hostValueSet(FFstrbuf* value) static void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer) { - ffGetFileBuffer(devicesPath, buffer); + ffReadFileBuffer(devicesPath, buffer); if(buffer->length == 0) - ffGetFileBuffer(classPath, buffer); + ffReadFileBuffer(classPath, buffer); } #endif @@ -67,10 +67,10 @@ void ffPrintHost(FFinstance* instance) getHostValue("/sys/devices/virtual/dmi/id/product_name", "/sys/class/dmi/id/product_name", &product_name); if(product_name.length == 0) - ffGetFileBuffer("/sys/firmware/devicetree/base/model", &product_name); + ffReadFileBuffer("/sys/firmware/devicetree/base/model", &product_name); if(product_name.length == 0) - ffGetFileBuffer("/tmp/sysinfo/model", &product_name); + ffReadFileBuffer("/tmp/sysinfo/model", &product_name); if(ffStrbufStartsWithS(&product_name, "Standard PC")) { From c440fdfca8cf120940958c9fd00177c0ac1735eb Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Wed, 22 Jun 2022 20:14:10 +0200 Subject: [PATCH 38/55] Uses instance->state.configDirs consistenlty (in particular thread save) troughout the project --- src/common/init.c | 15 ++++++++------- src/common/properties.c | 19 +++++++++---------- src/detection/gtk.c | 27 +++++++++++++-------------- src/detection/plasma.c | 18 ++++++++---------- src/logo/image/image.c | 3 +-- src/modules/battery.c | 3 +-- src/util/FFstrbuf.c | 6 ++++++ src/util/FFstrbuf.h | 2 ++ 8 files changed, 48 insertions(+), 45 deletions(-) diff --git a/src/common/init.c b/src/common/init.c index e93c5f98d..01eb17321 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -20,7 +20,7 @@ static void initConfigDirs(FFstate* state) FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs); ffStrbufInitA(buffer, 64); ffStrbufAppendS(buffer, xdgConfigHome); - ffStrbufTrimRight(buffer, '/'); + ffStrbufEnsureEndsWithC(buffer, '/'); } #define FF_ENSURE_ONLY_ONCE_IN_LIST(element) \ @@ -30,12 +30,13 @@ static void initConfigDirs(FFstate* state) FFstrbuf* userConfigHome = ffListAdd(&state->configDirs); ffStrbufInitA(userConfigHome, 64); ffStrbufAppendS(userConfigHome, state->passwd->pw_dir); - ffStrbufAppendS(userConfigHome, "/.config"); + ffStrbufAppendS(userConfigHome, "/.config/"); FF_ENSURE_ONLY_ONCE_IN_LIST(userConfigHome) FFstrbuf* userHome = ffListAdd(&state->configDirs); ffStrbufInitA(userHome, 64); ffStrbufAppendS(userHome, state->passwd->pw_dir); + ffStrbufEnsureEndsWithC(userHome, '/'); FF_ENSURE_ONLY_ONCE_IN_LIST(userHome) FFstrbuf xdgConfigDirs; @@ -51,7 +52,7 @@ static void initConfigDirs(FFstate* state) FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs); ffStrbufInitA(buffer, 64); ffStrbufAppendS(buffer, xdgConfigDirs.chars + startIndex); - ffStrbufTrimRight(buffer, '/'); + ffStrbufEnsureEndsWithC(buffer, '/'); FF_ENSURE_ONLY_ONCE_IN_LIST(buffer); startIndex = colonIndex + 1; @@ -59,12 +60,12 @@ static void initConfigDirs(FFstate* state) FFstrbuf* systemConfigHome = ffListAdd(&state->configDirs); ffStrbufInitA(systemConfigHome, 64); - ffStrbufAppendS(systemConfigHome, FASTFETCH_TARGET_DIR_ROOT"/etc/xdg"); + ffStrbufAppendS(systemConfigHome, FASTFETCH_TARGET_DIR_ROOT"/etc/xdg/"); FF_ENSURE_ONLY_ONCE_IN_LIST(systemConfigHome) FFstrbuf* systemConfig = ffListAdd(&state->configDirs); ffStrbufInitA(systemConfig, 64); - ffStrbufAppendS(systemConfig, FASTFETCH_TARGET_DIR_ROOT"/etc"); + ffStrbufAppendS(systemConfig, FASTFETCH_TARGET_DIR_ROOT"/etc/"); FF_ENSURE_ONLY_ONCE_IN_LIST(systemConfig) #undef FF_ENSURE_ONLY_ONCE_IN_LIST @@ -81,8 +82,8 @@ static void initCacheDir(FFstate* state) ffStrbufAppendS(&state->cacheDir, state->passwd->pw_dir); ffStrbufAppendS(&state->cacheDir, "/.cache/"); } - else if(!ffStrbufEndsWithC(&state->cacheDir, '/')) - ffStrbufAppendC(&state->cacheDir, '/'); + else + ffStrbufEnsureEndsWithC(&state->cacheDir, '/'); mkdir(state->cacheDir.chars, S_IRWXU | S_IXGRP | S_IRGRP | S_IXOTH | S_IROTH); //I hope everybody has a cache folder, but who knows diff --git a/src/common/properties.c b/src/common/properties.c index c8ff1947b..e0da97535 100644 --- a/src/common/properties.c +++ b/src/common/properties.c @@ -176,21 +176,18 @@ bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativ { bool foundAFile = false; + FFstrbuf baseDir; + ffStrbufInitA(&baseDir, 64); + for(uint32_t i = 0; i < instance->state.configDirs.length; i++) { - FFstrbuf* baseDir = (FFstrbuf*) ffListGet(&instance->state.configDirs, i); - uint32_t baseDirLength = baseDir->length; + //We need to copy the config dir each time, because it used by multiple threads, so we can't directly write to it. + ffStrbufSet(&baseDir, (FFstrbuf*) ffListGet(&instance->state.configDirs, i)); + ffStrbufAppendS(&baseDir, relativeFile); - if(*relativeFile != '/') - ffStrbufAppendC(baseDir, '/'); - - ffStrbufAppendS(baseDir, relativeFile); - - if(ffParsePropFileValues(baseDir->chars, numQueries, queries)) + if(ffParsePropFileValues(baseDir.chars, numQueries, queries)) foundAFile = true; - ffStrbufSubstrBefore(baseDir, baseDirLength); - bool allSet = true; for(uint32_t k = 0; k < numQueries; k++) { @@ -205,6 +202,8 @@ bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativ break; } + ffStrbufDestroy(&baseDir); + return foundAFile; } diff --git a/src/detection/gtk.c b/src/detection/gtk.c index 6bda8872d..920b0529a 100644 --- a/src/detection/gtk.c +++ b/src/detection/gtk.c @@ -103,7 +103,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG uint32_t configDirLength = configDir->length; // /gtk-.0/settings.ini - ffStrbufAppendS(configDir, "/gtk-"); + ffStrbufAppendS(configDir, "gtk-"); ffStrbufAppendS(configDir, version); ffStrbufAppendS(configDir, ".0/settings.ini"); detectGTKFromConfigFile(configDir->chars, result); @@ -112,7 +112,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG return; // /gtk-.0/gtkrc - ffStrbufAppendS(configDir, "/gtk-"); + ffStrbufAppendS(configDir, "gtk-"); ffStrbufAppendS(configDir, version); ffStrbufAppendS(configDir, ".0/gtkrc"); detectGTKFromConfigFile(configDir->chars, result); @@ -121,7 +121,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG return; // /gtkrc-.0 - ffStrbufAppendS(configDir, "/gtkrc-"); + ffStrbufAppendS(configDir, "gtkrc-"); ffStrbufAppendS(configDir, version); ffStrbufAppendS(configDir, ".0"); detectGTKFromConfigFile(configDir->chars, result); @@ -130,7 +130,7 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG return; // /.gtkrc-.0 - ffStrbufAppendS(configDir, "/.gtkrc-"); + ffStrbufAppendS(configDir, ".gtkrc-"); ffStrbufAppendS(configDir, version); ffStrbufAppendS(configDir, ".0"); detectGTKFromConfigFile(configDir->chars, result); @@ -140,22 +140,21 @@ static void detectGTKFromConfigDir(FFstrbuf* configDir, const char* version, FFG static void detectGTK(FFinstance* instance, const char* version, FFGTKResult* result) { //We need to do this because we use multiple threads on configDirs - FFstrbuf baseDirCopy; - ffStrbufInitA(&baseDirCopy, 64); + FFstrbuf baseDir; + ffStrbufInitA(&baseDir, 64); for(uint32_t i = 0; i < instance->state.configDirs.length; i++) { - FFstrbuf* baseDir = (FFstrbuf*) ffListGet(&instance->state.configDirs, i); - ffStrbufSet(&baseDirCopy, baseDir); - detectGTKFromConfigDir(&baseDirCopy, version, result); + ffStrbufSet(&baseDir, (FFstrbuf*) ffListGet(&instance->state.configDirs, i)); + detectGTKFromConfigDir(&baseDir, version, result); if(allPropertiesSet(result)) - { - ffStrbufDestroy(&baseDirCopy); - return; - } + break; } - ffStrbufDestroy(&baseDirCopy); + ffStrbufDestroy(&baseDir); + + if(allPropertiesSet(result)) + return; //Mate, Cinnamon and Gnome use dconf to save theme config //On other DEs, this will do nothing diff --git a/src/detection/plasma.c b/src/detection/plasma.c index 2885209e2..b0a6ee13b 100644 --- a/src/detection/plasma.c +++ b/src/detection/plasma.c @@ -12,9 +12,9 @@ typedef enum PlasmaCategory PLASMA_CATEGORY_OTHER } PlasmaCategory; -static bool detectFromConfigFile(const FFstrbuf* filename, FFPlasmaResult* result) +static bool detectFromConfigFile(const char* filename, FFPlasmaResult* result) { - FILE* kdeglobals = fopen(filename->chars, "r"); + FILE* kdeglobals = fopen(filename, "r"); if(kdeglobals == NULL) return false; @@ -96,17 +96,15 @@ const FFPlasmaResult* ffDetectPlasma(FFinstance* instance) bool foundAFile = false; //We need to do this because we use multiple threads on configDirs - FFstrbuf baseDirCopy; - ffStrbufInitA(&baseDirCopy, 64); + FFstrbuf baseDir; + ffStrbufInitA(&baseDir, 64); for(uint32_t i = 0; i < instance->state.configDirs.length; i++) { - FFstrbuf* baseDir = (FFstrbuf*) ffListGet(&instance->state.configDirs, i); + ffStrbufSet(&baseDir, ffListGet(&instance->state.configDirs, i)); + ffStrbufAppendS(&baseDir, "kdeglobals"); - ffStrbufSet(&baseDirCopy, baseDir); - ffStrbufAppendS(&baseDirCopy, "/kdeglobals"); - - if(detectFromConfigFile(&baseDirCopy, &result)) + if(detectFromConfigFile(baseDir.chars, &result)) foundAFile = true; if( @@ -117,7 +115,7 @@ const FFPlasmaResult* ffDetectPlasma(FFinstance* instance) ) break; } - ffStrbufDestroy(&baseDirCopy); + ffStrbufDestroy(&baseDir); if(!foundAFile) { diff --git a/src/logo/image/image.c b/src/logo/image/image.c index d731b01a7..057beac77 100644 --- a/src/logo/image/image.c +++ b/src/logo/image/image.c @@ -535,8 +535,7 @@ bool ffLogoPrintImageIfExists(FFinstance* instance, FFLogoType type) return false; } ffStrbufRecalculateLength(&requestData.cacheDir); - if(!ffStrbufEndsWithC(&requestData.cacheDir, '/')) - ffStrbufAppendC(&requestData.cacheDir, '/'); + ffStrbufEnsureEndsWithC(&requestData.cacheDir, '/'); ffStrbufAppendF(&requestData.cacheDir, "%u", requestData.logoPixelWidth); ffStrbufAppendC(&requestData.cacheDir, '*'); diff --git a/src/modules/battery.c b/src/modules/battery.c index 7af71428b..8c7489282 100644 --- a/src/modules/battery.c +++ b/src/modules/battery.c @@ -130,8 +130,7 @@ void ffPrintBattery(FFinstance* instance) if(instance->config.batteryDir.length > 0) { ffStrbufAppend(&baseDir, &instance->config.batteryDir); - if(!ffStrbufEndsWithC(&baseDir, '/')) - ffStrbufAppendC(&baseDir, '/'); + ffStrbufEndsWithC(&baseDir, '/'); } else { diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index 541ab3651..32ac8aea9 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -514,6 +514,12 @@ bool ffStrbufRemoveIgnCaseEndS(FFstrbuf* strbuf, const char* end) return false; } +void ffStrbufEnsureEndsWithC(FFstrbuf* strbuf, char c) +{ + if(!ffStrbufEndsWithC(strbuf, c)) + ffStrbufAppendC(strbuf, c); +} + void ffStrbufWriteTo(const FFstrbuf* strbuf, FILE* file) { fwrite(strbuf->chars, sizeof(*strbuf->chars), strbuf->length, file); diff --git a/src/util/FFstrbuf.h b/src/util/FFstrbuf.h index 1cd076fec..0d3febc0d 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -90,6 +90,8 @@ uint32_t ffStrbufCountC(const FFstrbuf* strbuf, char c); bool ffStrbufRemoveIgnCaseEndS(FFstrbuf* strbuf, const char* end); +void ffStrbufEnsureEndsWithC(FFstrbuf* strbuf, char c); + void ffStrbufWriteTo(const FFstrbuf* strbuf, FILE* file); void ffStrbufPutTo(const FFstrbuf* strbuf, FILE* file); From 91ba03d98869b8120eb5c6eb47dc445465b73ce1 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 23 Jun 2022 10:35:46 +0200 Subject: [PATCH 39/55] Add warning about public IP to bug_report.yml --- .github/ISSUE_TEMPLATE/bug_report.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index def328491..b1ca4827c 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -29,6 +29,10 @@ Output of `fastfetch --load-config devinfo-verbose`: //paste here ``` + + Output of `fastfetch --list-features`: ``` //paste here From b079e86c5ebdb6a61c30b9707cf2ed43bdb33f81 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 23 Jun 2022 10:36:53 +0200 Subject: [PATCH 40/55] update bug_report.yml --- .github/ISSUE_TEMPLATE/bug_report.md | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index b1ca4827c..d1ef2e797 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -25,13 +25,12 @@ Output of `fastfetch --load-config devinfo`: ``` Output of `fastfetch --load-config devinfo-verbose`: -``` -//paste here -``` - +``` +//paste here +``` Output of `fastfetch --list-features`: ``` From 94ad782caaa5b3855d22caf2d1f24e4f10861709 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 23 Jun 2022 10:44:53 +0200 Subject: [PATCH 41/55] No unneeded casts --- src/common/properties.c | 2 +- src/detection/gtk.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/common/properties.c b/src/common/properties.c index e0da97535..15763d34d 100644 --- a/src/common/properties.c +++ b/src/common/properties.c @@ -182,7 +182,7 @@ bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativ for(uint32_t i = 0; i < instance->state.configDirs.length; i++) { //We need to copy the config dir each time, because it used by multiple threads, so we can't directly write to it. - ffStrbufSet(&baseDir, (FFstrbuf*) ffListGet(&instance->state.configDirs, i)); + ffStrbufSet(&baseDir, ffListGet(&instance->state.configDirs, i)); ffStrbufAppendS(&baseDir, relativeFile); if(ffParsePropFileValues(baseDir.chars, numQueries, queries)) diff --git a/src/detection/gtk.c b/src/detection/gtk.c index 920b0529a..9ea79631a 100644 --- a/src/detection/gtk.c +++ b/src/detection/gtk.c @@ -145,7 +145,7 @@ static void detectGTK(FFinstance* instance, const char* version, FFGTKResult* re for(uint32_t i = 0; i < instance->state.configDirs.length; i++) { - ffStrbufSet(&baseDir, (FFstrbuf*) ffListGet(&instance->state.configDirs, i)); + ffStrbufSet(&baseDir, ffListGet(&instance->state.configDirs, i)); detectGTKFromConfigDir(&baseDir, version, result); if(allPropertiesSet(result)) break; From 2d2ba4c5b3268f1391adc8b791ce783fd806f11c Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 23 Jun 2022 15:51:29 +0200 Subject: [PATCH 42/55] Wayland: switch to wl_proxy_marshal_flags --- src/detection/displayserver/wayland.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/detection/displayserver/wayland.c b/src/detection/displayserver/wayland.c index 85d0503ed..0a760f9a4 100644 --- a/src/detection/displayserver/wayland.c +++ b/src/detection/displayserver/wayland.c @@ -12,7 +12,7 @@ typedef struct WaylandData { const FFinstance* instance; FFlist* results; - FF_LIBRARY_SYMBOL(wl_proxy_marshal_constructor_versioned) + FF_LIBRARY_SYMBOL(wl_proxy_marshal_flags) FF_LIBRARY_SYMBOL(wl_proxy_add_listener) FF_LIBRARY_SYMBOL(wl_proxy_destroy) const struct wl_interface* ffwl_output_interface; @@ -64,11 +64,11 @@ static void waylandOutputModeListener(void* data, struct wl_output* output, uint static void waylandGlobalAddListener(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) { - if(strcmp(interface, "wl_output") == 0) - { - WaylandData* wldata = (WaylandData*) data; + WaylandData* wldata = data; - struct wl_output* output = (struct wl_output*) wldata->ffwl_proxy_marshal_constructor_versioned((struct wl_proxy *) registry, WL_REGISTRY_BIND, wldata->ffwl_output_interface, version, name, wldata->ffwl_output_interface->name, version, NULL); + if(strcmp(interface, wldata->ffwl_output_interface->name) == 0) + { + struct wl_output* output = (struct wl_output*) wldata->ffwl_proxy_marshal_flags((struct wl_proxy *) registry, WL_REGISTRY_BIND, wldata->ffwl_output_interface, version, 0, name, wldata->ffwl_output_interface->name, version, NULL); if(output == NULL) return; @@ -89,7 +89,7 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) WaylandData data; - FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_marshal_constructor_versioned, wl_proxy_marshal_constructor_versioned, false) + FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_marshal_flags, wl_proxy_marshal_flags, false) FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_add_listener, wl_proxy_add_listener, false) FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_output_interface, wl_output_interface, false) FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_destroy, wl_proxy_destroy, false) From 3ba486a5b898899d345b9e9b816c237f2f41c7d3 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 23 Jun 2022 15:59:59 +0200 Subject: [PATCH 43/55] Wayland: switch to wl_proxy_marshal_constructor_versioned --- src/detection/displayserver/wayland.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/detection/displayserver/wayland.c b/src/detection/displayserver/wayland.c index 0a760f9a4..5ed8b9008 100644 --- a/src/detection/displayserver/wayland.c +++ b/src/detection/displayserver/wayland.c @@ -12,7 +12,7 @@ typedef struct WaylandData { const FFinstance* instance; FFlist* results; - FF_LIBRARY_SYMBOL(wl_proxy_marshal_flags) + FF_LIBRARY_SYMBOL(wl_proxy_marshal_constructor_versioned) FF_LIBRARY_SYMBOL(wl_proxy_add_listener) FF_LIBRARY_SYMBOL(wl_proxy_destroy) const struct wl_interface* ffwl_output_interface; @@ -68,7 +68,7 @@ static void waylandGlobalAddListener(void* data, struct wl_registry* registry, u if(strcmp(interface, wldata->ffwl_output_interface->name) == 0) { - struct wl_output* output = (struct wl_output*) wldata->ffwl_proxy_marshal_flags((struct wl_proxy *) registry, WL_REGISTRY_BIND, wldata->ffwl_output_interface, version, 0, name, wldata->ffwl_output_interface->name, version, NULL); + struct wl_output* output = (struct wl_output*) wldata->ffwl_proxy_marshal_constructor_versioned((struct wl_proxy *) registry, WL_REGISTRY_BIND, wldata->ffwl_output_interface, version, name, wldata->ffwl_output_interface->name, version, NULL); if(output == NULL) return; @@ -89,7 +89,7 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) WaylandData data; - FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_marshal_flags, wl_proxy_marshal_flags, false) + FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_marshal_constructor_versioned, ffwl_proxy_marshal_constructor, false) FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_add_listener, wl_proxy_add_listener, false) FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_output_interface, wl_output_interface, false) FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_destroy, wl_proxy_destroy, false) From 5820c9bbffbdacded1cb6606401b0a4d06db3e91 Mon Sep 17 00:00:00 2001 From: nous <6310912+artixnous@users.noreply.github.com> Date: Sat, 25 Jun 2022 13:26:07 +0300 Subject: [PATCH 44/55] Update builtin.c --- src/logo/builtin.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/logo/builtin.c b/src/logo/builtin.c index ca2524734..326e5bdac 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -205,18 +205,18 @@ static const FFlogo* getLogoArtix() " 'oookkxxoo'\n" " 'oiioxkkxxoo'\n" " ':;:iiiioxxxoo'\n" - " `'.;::ioxxoo''\n" + " `'.;::ioxxoo'\n" " '-. `':;jiooo'\n" - " 'oooio-.. `'i:io'\n" - " 'ooooxxxxoio:,. `'-;'\n" - " 'ooooxxxxxkkxoooIi:-. `'\n" - " 'ooooxxxxxkkkkxoiiiiiji'\n" - " 'ooooxxxxxkxxoiiii:'` .i'\n" - " 'ooooxxxxxoi:::'` .;ioxo'\n" - " 'ooooxooi::'` .:iiixkxxo'\n" - " 'ooooi:'` `'';ioxxo'\n" - "'i:'` '':io'\n" - "'` `'"; + " 'oooio-.. `'i:io'\n" + " 'ooooxxxxoio:,. `'-;'\n" + " 'ooooxxxxxkkxoooIi:-. `'\n" + " 'ooooxxxxxkkkkxoiiiiiji'\n" + " 'ooooxxxxxkxxoiiii:'` .i'\n" + " 'ooooxxxxxoi:::'` .;ioxo'\n" + " 'ooooxooi::'` .:iiixkxxo'\n" + " 'ooooi:'` `'';ioxxo'\n" + " 'i:'` '':io'\n" + "'` `'"; ) FF_LOGO_COLORS( "36" //cyan From 22a3ab4a81006943acfb8b1afe9908975937f3a5 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sun, 26 Jun 2022 13:35:16 +0200 Subject: [PATCH 45/55] Detect wayland WM _much_ faster --- src/detection/displayserver/wayland.c | 27 ++++++++++++++++++++++++++- src/detection/displayserver/wmde.c | 23 ++++++++++++++++------- 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/detection/displayserver/wayland.c b/src/detection/displayserver/wayland.c index 5ed8b9008..993ee77cc 100644 --- a/src/detection/displayserver/wayland.c +++ b/src/detection/displayserver/wayland.c @@ -1,3 +1,5 @@ +#define _GNU_SOURCE //required for struct ucred + #include "displayServer.h" #include @@ -7,6 +9,7 @@ #include #include #include +#include typedef struct WaylandData { @@ -19,6 +22,25 @@ typedef struct WaylandData struct wl_output_listener output_listener; } WaylandData; +static void waylandDetectWM(int fd, FFDisplayServerResult* result) +{ + if(fd < 1) + return; + + struct ucred ucred; + socklen_t len = sizeof(struct ucred); + if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1) + return; + + FFstrbuf procPath; + ffStrbufInit(&procPath); + ffStrbufAppendF(&procPath, "/proc/%d/cmdline", ucred.pid); //We check the cmdline for the process name, because it is not trimmed. + ffReadFileBuffer(procPath.chars, &result->wmProcessName); + ffStrbufSubstrBeforeFirstC(&result->wmProcessName, '\0'); //Trim the arguments + ffStrbufSubstrAfterLastC(&result->wmProcessName, '/'); //Trim the path + ffStrbufDestroy(&procPath); +} + static void waylandGlobalRemoveListener(void* data, struct wl_registry* wl_registry, uint32_t name){ FF_UNUSED(data, wl_registry, name); } @@ -81,6 +103,7 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) FF_LIBRARY_LOAD(wayland, instance->config.libWayland, false, "libwayland-client.so", 1) FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_connect, false) + FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_get_fd, false) FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_dispatch, false) FF_LIBRARY_LOAD_SYMBOL(wayland, wl_display_roundtrip, false) FF_LIBRARY_LOAD_SYMBOL(wayland, wl_proxy_marshal_constructor, false) @@ -89,7 +112,7 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) WaylandData data; - FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_marshal_constructor_versioned, ffwl_proxy_marshal_constructor, false) + FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_marshal_constructor_versioned, wl_proxy_marshal_constructor_versioned, false) FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_add_listener, wl_proxy_add_listener, false) FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_output_interface, wl_output_interface, false) FF_LIBRARY_LOAD_SYMBOL_ADRESS(wayland, data.ffwl_proxy_destroy, wl_proxy_destroy, false) @@ -101,6 +124,8 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) return false; } + waylandDetectWM(ffwl_display_get_fd(display), result); + struct wl_registry* registry = (struct wl_registry*) ffwl_proxy_marshal_constructor((struct wl_proxy*) display, WL_DISPLAY_GET_REGISTRY, ffwl_registry_interface, NULL); if(registry == NULL) { diff --git a/src/detection/displayserver/wmde.c b/src/detection/displayserver/wmde.c index 5327fe89b..c5264a7b2 100644 --- a/src/detection/displayserver/wmde.c +++ b/src/detection/displayserver/wmde.c @@ -56,8 +56,21 @@ static void applyPrettyNameIfWM(FFDisplayServerResult* result, const char* proce if(!ffStrSet(processName)) return; - if(strcasecmp(processName, "kwin_wayland") == 0 || strcasecmp(processName, "kwin_x11") == 0 || strcasecmp(processName, "kwin") == 0) - ffStrbufSetS(&result->wmPrettyName, "KWin"); + if( + strcasecmp(processName, "kwin_wayland") == 0 || + strcasecmp(processName, "kwin_wayland_wrapper") == 0 || + strcasecmp(processName, "kwin_x11") == 0 || + strcasecmp(processName, "kwin_x11_wrapper") == 0 || + strcasecmp(processName, "kwin") == 0 + ) ffStrbufSetS(&result->wmPrettyName, "KWin"); + else if( + strcasecmp(processName, "gnome-session-binary") == 0 || + strcasecmp(processName, "Mutter") == 0 + ) ffStrbufSetS(&result->wmPrettyName, "Mutter"); + else if( + strcasecmp(processName, "cinnamon-session") == 0 || + strcasecmp(processName, "Muffin") == 0 + ) ffStrbufSetS(&result->wmPrettyName, "Muffin"); else if(strcasecmp(processName, "sway") == 0) ffStrbufSetS(&result->wmPrettyName, "Sway"); else if(strcasecmp(processName, "weston") == 0) @@ -72,10 +85,6 @@ static void applyPrettyNameIfWM(FFDisplayServerResult* result, const char* proce ffStrbufSetS(&result->wmPrettyName, "Marco"); else if(strcasecmp(processName, "xmonad") == 0) ffStrbufSetS(&result->wmPrettyName, "XMonad"); - else if(strcasecmp(processName, "gnome-session-binary") == 0 || strcasecmp(processName, "Mutter") == 0) - ffStrbufSetS(&result->wmPrettyName, "Mutter"); - else if(strcasecmp(processName, "cinnamon-session") == 0 || strcasecmp(processName, "Muffin") == 0) - ffStrbufSetS(&result->wmPrettyName, "Muffin"); else if( // WMs where the pretty name matches the process name strcasecmp(processName, "dwm") == 0 || strcasecmp(processName, "bspwm") == 0 || @@ -379,7 +388,7 @@ void ffdsDetectWMDE(const FFinstance* instance, FFDisplayServerResult* result) getWMProtocolNameFromEnv(result); //We don't want to detect anything in TTY - //This can't happen if a X11 connection succeeded, so we don't need to clear wmProcessName + //This can't happen if a connection succeeded, so we don't need to clear wmProcessName if(ffStrbufIgnCaseCompS(&result->wmProtocolName, FF_DISPLAYSERVER_PROTOCOL_TTY) == 0) return; From 8ab7a8ba37727533074c2d6b7873d31e5024e9eb Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sun, 26 Jun 2022 13:41:55 +0200 Subject: [PATCH 46/55] Release 1.5.5 Feature: Detect wayland WM much faster Bugfix: Wayland backend for resolution working once again Bugfix: Plasma values are no longer victims to race conditions --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 554834795..02f06faff 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs project(fastfetch - VERSION 1.5.4 + VERSION 1.5.5 LANGUAGES C ) From 3b2a6e4a6ed1f88557c82ae371b24fa26ff2309d Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Mon, 27 Jun 2022 15:38:34 +0200 Subject: [PATCH 47/55] Don't load sqlite3 id db path doesn't exist --- src/common/settings.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/common/settings.c b/src/common/settings.c index 065db007b..ba2cc438f 100644 --- a/src/common/settings.c +++ b/src/common/settings.c @@ -271,6 +271,7 @@ FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, con #ifdef FF_HAVE_SQLITE3 #include +#include typedef struct SQLiteData { @@ -300,6 +301,9 @@ static const SQLiteData* getSQLiteData(const FFinstance* instance) int ffSettingsGetSQLite3Int(const FFinstance* instance, const char* dbPath, const char* query) { + if(!ffFileExists(dbPath, S_IFREG)) + return 0; + const SQLiteData* data = getSQLiteData(instance); if(data == NULL) return 0; From 1861d55f7dc5e84ff6fbcf9ff0de0b4096048d7d Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Tue, 28 Jun 2022 11:57:08 +0200 Subject: [PATCH 48/55] Refactor wayland code --- src/detection/displayserver/wayland.c | 48 ++++++--------------------- 1 file changed, 10 insertions(+), 38 deletions(-) diff --git a/src/detection/displayserver/wayland.c b/src/detection/displayserver/wayland.c index 993ee77cc..083aad076 100644 --- a/src/detection/displayserver/wayland.c +++ b/src/detection/displayserver/wayland.c @@ -13,7 +13,6 @@ typedef struct WaylandData { - const FFinstance* instance; FFlist* results; FF_LIBRARY_SYMBOL(wl_proxy_marshal_constructor_versioned) FF_LIBRARY_SYMBOL(wl_proxy_add_listener) @@ -24,9 +23,6 @@ typedef struct WaylandData static void waylandDetectWM(int fd, FFDisplayServerResult* result) { - if(fd < 1) - return; - struct ucred ucred; socklen_t len = sizeof(struct ucred); if (getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &len) == -1) @@ -41,35 +37,13 @@ static void waylandDetectWM(int fd, FFDisplayServerResult* result) ffStrbufDestroy(&procPath); } -static void waylandGlobalRemoveListener(void* data, struct wl_registry* wl_registry, uint32_t name){ - FF_UNUSED(data, wl_registry, name); -} - -static void waylandOutputGeometryListener(void* data, struct wl_output* wl_output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char* make, const char* model, int32_t transform) -{ - FF_UNUSED(data, wl_output, x, y, physical_width, physical_height, subpixel, make, model, transform); -} - -static void waylandOutputDoneListener(void* data, struct wl_output* wl_output) -{ - FF_UNUSED(data, wl_output); -} - -static void waylandOutputScaleListener(void* data, struct wl_output* wl_output, int32_t factor) -{ - FF_UNUSED(data, wl_output, factor); -} - static void waylandOutputModeListener(void* data, struct wl_output* output, uint32_t flags, int32_t width, int32_t height, int32_t refreshRate) { - if(!(flags & WL_OUTPUT_MODE_CURRENT)) - return; - - WaylandData* wldata = (WaylandData*) data; + WaylandData* wldata = data; wldata->ffwl_proxy_destroy((struct wl_proxy*) output); - if(width <= 0 || height <= 0) + if(!(flags & WL_OUTPUT_MODE_CURRENT) || width <= 0 || height <= 0) return; static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER; @@ -90,11 +64,11 @@ static void waylandGlobalAddListener(void* data, struct wl_registry* registry, u if(strcmp(interface, wldata->ffwl_output_interface->name) == 0) { - struct wl_output* output = (struct wl_output*) wldata->ffwl_proxy_marshal_constructor_versioned((struct wl_proxy *) registry, WL_REGISTRY_BIND, wldata->ffwl_output_interface, version, name, wldata->ffwl_output_interface->name, version, NULL); + struct wl_proxy* output = wldata->ffwl_proxy_marshal_constructor_versioned((struct wl_proxy*) registry, WL_REGISTRY_BIND, wldata->ffwl_output_interface, version, name, wldata->ffwl_output_interface->name, version, NULL); if(output == NULL) return; - wldata->ffwl_proxy_add_listener((struct wl_proxy*) output, (void(**)(void)) &wldata->output_listener, data); + wldata->ffwl_proxy_add_listener(output, (void(**)(void)) &wldata->output_listener, data); } } @@ -134,17 +108,15 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) return false; } - data.instance = instance; data.results = &result->resolutions; - struct wl_registry_listener regestry_listener; - regestry_listener.global = waylandGlobalAddListener; - regestry_listener.global_remove = waylandGlobalRemoveListener; + struct wl_registry_listener regestry_listener = { + .global = waylandGlobalAddListener + }; - data.output_listener.geometry = waylandOutputGeometryListener; - data.output_listener.mode = waylandOutputModeListener; - data.output_listener.done = waylandOutputDoneListener; - data.output_listener.scale = waylandOutputScaleListener; + data.output_listener = (struct wl_output_listener) { + .mode = waylandOutputModeListener + }; data.ffwl_proxy_add_listener((struct wl_proxy*) registry, (void(**)(void)) ®estry_listener, &data); ffwl_display_dispatch(display); From 9b62d17d8d0b76a37b8de6e4285649b053ab742e Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Tue, 28 Jun 2022 21:41:13 +0200 Subject: [PATCH 49/55] Refactor wayland code the second --- src/detection/displayserver/wayland.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/detection/displayserver/wayland.c b/src/detection/displayserver/wayland.c index 083aad076..dd2c17ac9 100644 --- a/src/detection/displayserver/wayland.c +++ b/src/detection/displayserver/wayland.c @@ -100,7 +100,7 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) waylandDetectWM(ffwl_display_get_fd(display), result); - struct wl_registry* registry = (struct wl_registry*) ffwl_proxy_marshal_constructor((struct wl_proxy*) display, WL_DISPLAY_GET_REGISTRY, ffwl_registry_interface, NULL); + struct wl_proxy* registry = ffwl_proxy_marshal_constructor((struct wl_proxy*) display, WL_DISPLAY_GET_REGISTRY, ffwl_registry_interface, NULL); if(registry == NULL) { ffwl_display_disconnect(display); @@ -110,7 +110,7 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) data.results = &result->resolutions; - struct wl_registry_listener regestry_listener = { + struct wl_registry_listener registry_listener = { .global = waylandGlobalAddListener }; @@ -118,11 +118,11 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) .mode = waylandOutputModeListener }; - data.ffwl_proxy_add_listener((struct wl_proxy*) registry, (void(**)(void)) ®estry_listener, &data); + data.ffwl_proxy_add_listener(registry, (void(**)(void)) ®istry_listener, &data); ffwl_display_dispatch(display); ffwl_display_roundtrip(display); - data.ffwl_proxy_destroy((struct wl_proxy*) registry); + data.ffwl_proxy_destroy(registry); ffwl_display_disconnect(display); dlclose(wayland); From 41b024d3b1bec0780f56f6bf527b25ec685b5808 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Wed, 29 Jun 2022 11:08:42 +0200 Subject: [PATCH 50/55] Refactor wayland code the third --- src/detection/displayserver/wayland.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/detection/displayserver/wayland.c b/src/detection/displayserver/wayland.c index dd2c17ac9..a3998bd2d 100644 --- a/src/detection/displayserver/wayland.c +++ b/src/detection/displayserver/wayland.c @@ -18,7 +18,6 @@ typedef struct WaylandData FF_LIBRARY_SYMBOL(wl_proxy_add_listener) FF_LIBRARY_SYMBOL(wl_proxy_destroy) const struct wl_interface* ffwl_output_interface; - struct wl_output_listener output_listener; } WaylandData; static void waylandDetectWM(int fd, FFDisplayServerResult* result) @@ -68,7 +67,12 @@ static void waylandGlobalAddListener(void* data, struct wl_registry* registry, u if(output == NULL) return; - wldata->ffwl_proxy_add_listener(output, (void(**)(void)) &wldata->output_listener, data); + //Needs to be static, because the scope of the function will already be lost when calling the listener + static struct wl_output_listener outputListener = { + .mode = waylandOutputModeListener + }; + + wldata->ffwl_proxy_add_listener(output, (void(**)(void)) &outputListener, data); } } @@ -114,10 +118,6 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) .global = waylandGlobalAddListener }; - data.output_listener = (struct wl_output_listener) { - .mode = waylandOutputModeListener - }; - data.ffwl_proxy_add_listener(registry, (void(**)(void)) ®istry_listener, &data); ffwl_display_dispatch(display); ffwl_display_roundtrip(display); From c2da7b19f9788e00096d962cbb71a86ff9af0c6b Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Wed, 29 Jun 2022 12:47:57 +0200 Subject: [PATCH 51/55] Song: Don't show album by default --- src/modules/song.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/modules/song.c b/src/modules/song.c index 6a38bbc56..a5b1abb35 100644 --- a/src/modules/song.c +++ b/src/modules/song.c @@ -87,13 +87,6 @@ void ffPrintSong(FFinstance* instance) fputs(" - ", stdout); } - //Some sites (e.g. reddit) expose their url as album. We don't want to show that - if(media->album.length > 0 && !ffStrbufStartsWithIgnCaseS(&media->album, "http")) - { - ffStrbufWriteTo(&media->album, stdout); - fputs(" - ", stdout); - } - ffStrbufPutTo(&songPretty, stdout); } else From bc76ebfb3f40470fdc4001704e4a08665bf58641 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 30 Jun 2022 12:16:38 +0200 Subject: [PATCH 52/55] Wayland: add stub listeners --- src/detection/displayserver/wayland.c | 53 ++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 2 deletions(-) diff --git a/src/detection/displayserver/wayland.c b/src/detection/displayserver/wayland.c index a3998bd2d..ee426de22 100644 --- a/src/detection/displayserver/wayland.c +++ b/src/detection/displayserver/wayland.c @@ -36,6 +36,39 @@ static void waylandDetectWM(int fd, FFDisplayServerResult* result) ffStrbufDestroy(&procPath); } +static void waylandOutputGeometryListener(void* data, struct wl_output* wl_output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char* make, const char* model, int32_t transform) +{ + FF_UNUSED(data, wl_output, x, y, physical_width, physical_height, subpixel, make, model, transform); +} + +#if WAYLAND_VERSION_MINOR >= 2 + +static void waylandOutputDoneListener(void* data, struct wl_output* wl_output) +{ + FF_UNUSED(data, wl_output); +} + +static void waylandOutputScaleListener(void* data, struct wl_output* wl_output, int32_t factor) +{ + FF_UNUSED(data, wl_output, factor); +} + +#endif + +#if WAYLAND_VERSION_MINOR >= 4 + +static void waylandOutputNameListener(void *data, struct wl_output *wl_output, const char *name) +{ + FF_UNUSED(data, wl_output, name); +} + +static void waylandOutputDescriptionListener(void *data, struct wl_output *wl_output, const char *description) +{ + FF_UNUSED(data, wl_output, description); +} + +#endif + static void waylandOutputModeListener(void* data, struct wl_output* output, uint32_t flags, int32_t width, int32_t height, int32_t refreshRate) { WaylandData* wldata = data; @@ -57,6 +90,10 @@ static void waylandOutputModeListener(void* data, struct wl_output* output, uint result->refreshRate = ffdsParseRefreshRate(refreshRate / 1000); } +static void waylandGlobalRemoveListener(void* data, struct wl_registry* wl_registry, uint32_t name){ + FF_UNUSED(data, wl_registry, name); +} + static void waylandGlobalAddListener(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) { WaylandData* wldata = data; @@ -69,7 +106,18 @@ static void waylandGlobalAddListener(void* data, struct wl_registry* registry, u //Needs to be static, because the scope of the function will already be lost when calling the listener static struct wl_output_listener outputListener = { - .mode = waylandOutputModeListener + .mode = waylandOutputModeListener, //This is the only one we really need + .geometry = waylandOutputGeometryListener, + + #if WAYLAND_VERSION_MINOR >= 2 + .done = waylandOutputDoneListener, + .scale = waylandOutputScaleListener, + #endif + + #if WAYLAND_VERSION_MINOR >= 4 + .name = waylandOutputNameListener, + .description = waylandOutputDescriptionListener, + #endif }; wldata->ffwl_proxy_add_listener(output, (void(**)(void)) &outputListener, data); @@ -115,7 +163,8 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) data.results = &result->resolutions; struct wl_registry_listener registry_listener = { - .global = waylandGlobalAddListener + .global = waylandGlobalAddListener, + .global_remove = waylandGlobalRemoveListener }; data.ffwl_proxy_add_listener(registry, (void(**)(void)) ®istry_listener, &data); From 7d6f92a44639c2ba5300d505b0d1fa49d9959f9f Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Thu, 30 Jun 2022 12:22:46 +0200 Subject: [PATCH 53/55] Wayland: only use required stub listeners --- src/detection/displayserver/wayland.c | 38 --------------------------- 1 file changed, 38 deletions(-) diff --git a/src/detection/displayserver/wayland.c b/src/detection/displayserver/wayland.c index ee426de22..169e1960a 100644 --- a/src/detection/displayserver/wayland.c +++ b/src/detection/displayserver/wayland.c @@ -41,34 +41,6 @@ static void waylandOutputGeometryListener(void* data, struct wl_output* wl_outpu FF_UNUSED(data, wl_output, x, y, physical_width, physical_height, subpixel, make, model, transform); } -#if WAYLAND_VERSION_MINOR >= 2 - -static void waylandOutputDoneListener(void* data, struct wl_output* wl_output) -{ - FF_UNUSED(data, wl_output); -} - -static void waylandOutputScaleListener(void* data, struct wl_output* wl_output, int32_t factor) -{ - FF_UNUSED(data, wl_output, factor); -} - -#endif - -#if WAYLAND_VERSION_MINOR >= 4 - -static void waylandOutputNameListener(void *data, struct wl_output *wl_output, const char *name) -{ - FF_UNUSED(data, wl_output, name); -} - -static void waylandOutputDescriptionListener(void *data, struct wl_output *wl_output, const char *description) -{ - FF_UNUSED(data, wl_output, description); -} - -#endif - static void waylandOutputModeListener(void* data, struct wl_output* output, uint32_t flags, int32_t width, int32_t height, int32_t refreshRate) { WaylandData* wldata = data; @@ -108,16 +80,6 @@ static void waylandGlobalAddListener(void* data, struct wl_registry* registry, u static struct wl_output_listener outputListener = { .mode = waylandOutputModeListener, //This is the only one we really need .geometry = waylandOutputGeometryListener, - - #if WAYLAND_VERSION_MINOR >= 2 - .done = waylandOutputDoneListener, - .scale = waylandOutputScaleListener, - #endif - - #if WAYLAND_VERSION_MINOR >= 4 - .name = waylandOutputNameListener, - .description = waylandOutputDescriptionListener, - #endif }; wldata->ffwl_proxy_add_listener(output, (void(**)(void)) &outputListener, data); From 609fa14f4fa411dadd4bc3f024c409f3379d132b Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sun, 3 Jul 2022 16:10:17 +0200 Subject: [PATCH 54/55] Wayland: use a single, common stub listener --- src/detection/displayserver/wayland.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/src/detection/displayserver/wayland.c b/src/detection/displayserver/wayland.c index 169e1960a..137ebeb34 100644 --- a/src/detection/displayserver/wayland.c +++ b/src/detection/displayserver/wayland.c @@ -36,9 +36,9 @@ static void waylandDetectWM(int fd, FFDisplayServerResult* result) ffStrbufDestroy(&procPath); } -static void waylandOutputGeometryListener(void* data, struct wl_output* wl_output, int32_t x, int32_t y, int32_t physical_width, int32_t physical_height, int32_t subpixel, const char* make, const char* model, int32_t transform) +static void stubListener(void* data, ...) { - FF_UNUSED(data, wl_output, x, y, physical_width, physical_height, subpixel, make, model, transform); + (void) data; } static void waylandOutputModeListener(void* data, struct wl_output* output, uint32_t flags, int32_t width, int32_t height, int32_t refreshRate) @@ -62,10 +62,6 @@ static void waylandOutputModeListener(void* data, struct wl_output* output, uint result->refreshRate = ffdsParseRefreshRate(refreshRate / 1000); } -static void waylandGlobalRemoveListener(void* data, struct wl_registry* wl_registry, uint32_t name){ - FF_UNUSED(data, wl_registry, name); -} - static void waylandGlobalAddListener(void* data, struct wl_registry* registry, uint32_t name, const char* interface, uint32_t version) { WaylandData* wldata = data; @@ -78,8 +74,20 @@ static void waylandGlobalAddListener(void* data, struct wl_registry* registry, u //Needs to be static, because the scope of the function will already be lost when calling the listener static struct wl_output_listener outputListener = { - .mode = waylandOutputModeListener, //This is the only one we really need - .geometry = waylandOutputGeometryListener, + .mode = waylandOutputModeListener, + .geometry = (void*) stubListener, + + //https://lists.freedesktop.org/archives/wayland-devel/2013-July/010278.html + #if WAYLAND_VERSION_MINOR >= 2 + .done = (void*) stubListener, + .scale = (void*) stubListener, + #endif + + //https://lists.freedesktop.org/archives/wayland-devel/2021-December/042064.html + #if WAYLAND_VERSION_MINOR >= 20 + .name = (void*) stubListener, + .description = (void*) stubListener, + #endif }; wldata->ffwl_proxy_add_listener(output, (void(**)(void)) &outputListener, data); @@ -126,7 +134,7 @@ bool detectWayland(const FFinstance* instance, FFDisplayServerResult* result) struct wl_registry_listener registry_listener = { .global = waylandGlobalAddListener, - .global_remove = waylandGlobalRemoveListener + .global_remove = (void*) stubListener }; data.ffwl_proxy_add_listener(registry, (void(**)(void)) ®istry_listener, &data); From 02cc214dfc706956b14bce36be5e5049658800d0 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Sun, 3 Jul 2022 16:16:39 +0200 Subject: [PATCH 55/55] Release 1.5.6 Bugfix: Don't segfault when connecting to some wayland compositors See https://github.com/LinusDierheimer/fastfetch/issues/188 --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 02f06faff..deaaad607 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.12.0) # target_link_libraries with OBJECT libs project(fastfetch - VERSION 1.5.5 + VERSION 1.5.6 LANGUAGES C )