diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index def328491..d1ef2e797 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -25,6 +25,9 @@ Output of `fastfetch --load-config devinfo`: ``` Output of `fastfetch --load-config devinfo-verbose`: + ``` //paste here ``` diff --git a/CMakeLists.txt b/CMakeLists.txt index 2bfb476c2..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.3 + VERSION 1.5.6 LANGUAGES C ) @@ -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/DEVELOPMENT.md b/DEVELOPMENT.md index 7002e39ec..632c3f654 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -12,8 +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 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 - [ ] 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/completions/bash b/completions/bash index 787495d11..750764834 100644 --- a/completions/bash +++ b/completions/bash @@ -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" + "--datetime-error" + "--date-error" + "--time-error" + "--vulkan-error" + "--opengl-error" + "--opencl-error" ) local FF_OPTIONS_PATH=( diff --git a/presets/verbose b/presets/verbose index 9694e4f6b..f859551c5 100644 --- a/presets/verbose +++ b/presets/verbose @@ -17,9 +17,9 @@ --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: {}; 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/common/caching.c b/src/common/caching.c index e5e95ba8d..7aaef69f9 100644 --- a/src/common/caching.c +++ b/src/common/caching.c @@ -1,9 +1,13 @@ #include "fastfetch.h" +#include + #define FF_CACHE_VALUE_EXTENSION "ffcv" #define FF_CACHE_SPLIT_EXTENSION "ffcs" -static void getCacheFilePath(FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer) +#define FF_CACHE_EXTENSION_DATA "ffcd" + +static void getCacheFilePath(const FFinstance* instance, const char* moduleName, const char* extension, FFstrbuf* buffer) { ffStrbufAppend(buffer, &instance->state.cacheDir); ffStrbufAppendS(buffer, moduleName); @@ -20,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); } @@ -29,7 +33,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); } @@ -77,7 +81,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 +99,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 +110,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 +138,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 +152,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 +195,32 @@ 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); } + +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/format.c b/src/common/format.c index dd1d39038..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; @@ -72,6 +63,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') || @@ -81,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; @@ -128,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] == '-') { @@ -186,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 @@ -223,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..01eb17321 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -1,5 +1,6 @@ #include "fastfetch.h" +#include #include #include #include @@ -19,13 +20,9 @@ static void initConfigDirs(FFstate* state) FFstrbuf* buffer = (FFstrbuf*) ffListAdd(&state->configDirs); ffStrbufInitA(buffer, 64); ffStrbufAppendS(buffer, xdgConfigHome); - ffStrbufTrimRight(buffer, '/'); + ffStrbufEnsureEndsWithC(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; @@ -33,14 +30,19 @@ 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; + ffStrbufInitA(&xdgConfigDirs, 64); + ffStrbufAppendS(&xdgConfigDirs, getenv("XDG_CONFIG_DIRS")); + uint32_t startIndex = 0; while (startIndex < xdgConfigDirs.length) { @@ -50,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; @@ -58,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 @@ -80,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 @@ -102,6 +104,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 +137,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/io.c b/src/common/io.c index 51d99afff..8cf2de0c6 100644 --- a/src/common/io.c +++ b/src/common/io.c @@ -1,17 +1,11 @@ #include "fastfetch.h" -#include +#include #include #include -#include #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; @@ -28,7 +22,13 @@ static void createSubfolders(const char* fileName) ffStrbufDestroy(&path); } -bool ffWriteFileContent(const char* fileName, const FFstrbuf* content) + +bool ffWriteFDBuffer(int fd, const FFstrbuf* content) +{ + return write(fd, content->chars, content->length) != -1; +} + +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; @@ -42,14 +42,19 @@ bool ffWriteFileContent(const char* fileName, const FFstrbuf* content) return false; } - bool ret = ffWriteFDContent(fd, content); + bool ret = write(fd, data, dataSize) != -1; close(fd); return ret; } -void ffAppendFDContent(int fd, FFstrbuf* buffer) +bool ffWriteFileBuffer(const char* fileName, const FFstrbuf* buffer) +{ + return ffWriteFileData(fileName, buffer->length, buffer->chars); +} + +bool ffAppendFDBuffer(int fd, FFstrbuf* buffer) { ssize_t readed = 0; @@ -73,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 ffReadFileData(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 ffReadFileBuffer(const char* fileName, FFstrbuf* buffer) { ffStrbufClear(buffer); - return ffAppendFileContent(fileName, buffer); + return ffAppendFileBuffer(fileName, buffer); } // Not thread safe! 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/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/common/processing.c b/src/common/processing.c index 585ed8862..95c3dcb6d 100644 --- a/src/common/processing.c +++ b/src/common/processing.c @@ -1,6 +1,6 @@ #include "fastfetch.h" -#include +#include #include #include @@ -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/common/properties.c b/src/common/properties.c index a6b3f2ba5..15763d34d 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') @@ -174,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, 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++) { @@ -203,6 +202,8 @@ bool ffParsePropFileConfigValues(const FFinstance* instance, const char* relativ break; } + ffStrbufDestroy(&baseDir); + return foundAFile; } diff --git a/src/common/settings.c b/src/common/settings.c index 17be91f5c..ba2cc438f 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; \ @@ -270,6 +271,7 @@ FFvariant ffSettingsGetXFConf(FFinstance* instance, const char* channelName, con #ifdef FF_HAVE_SQLITE3 #include +#include typedef struct SQLiteData { @@ -299,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; 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/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..137ebeb34 100644 --- a/src/detection/displayserver/wayland.c +++ b/src/detection/displayserver/wayland.c @@ -1,50 +1,53 @@ +#define _GNU_SOURCE //required for struct ucred + #include "displayServer.h" + +#include #include #ifdef FF_HAVE_WAYLAND -#include #include +#include +#include +#include typedef struct WaylandData { - const FFinstance* instance; FFlist* results; 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; - struct wl_output_listener output_listener; } WaylandData; -static void waylandGlobalRemoveListener(void* data, struct wl_registry* wl_registry, uint32_t name){ - FF_UNUSED(data, wl_registry, name); +static void waylandDetectWM(int fd, FFDisplayServerResult* result) +{ + 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 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); -} - -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); + (void) data; } 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; @@ -61,71 +64,84 @@ 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_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); + //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, + .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); } } -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_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) + 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); + waylandDetectWM(ffwl_display_get_fd(display), result); + + 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); dlclose(wayland); - return; + 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 registry_listener = { + .global = waylandGlobalAddListener, + .global_remove = (void*) stubListener + }; - data.output_listener.geometry = waylandOutputGeometryListener; - data.output_listener.mode = waylandOutputModeListener; - data.output_listener.done = waylandOutputDoneListener; - data.output_listener.scale = waylandOutputScaleListener; - - 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); @@ -133,20 +149,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. @@ -158,9 +175,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 diff --git a/src/detection/displayserver/wmde.c b/src/detection/displayserver/wmde.c index ccc231592..c5264a7b2 100644 --- a/src/detection/displayserver/wmde.c +++ b/src/detection/displayserver/wmde.c @@ -1,8 +1,11 @@ #include "displayServer.h" -#include + +#include +#include #include #include -#include +#include +#include static const char* parseEnv() { @@ -40,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; } @@ -48,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) @@ -64,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 || @@ -329,7 +346,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); + ffReadFileBuffer(procPath.chars, &loginuid); if(ffStrbufComp(&userID, &loginuid) != 0) { ffStrbufSubstrBefore(&procPath, procPathLength); @@ -340,7 +357,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); + ffReadFileBuffer(procPath.chars, &processName); ffStrbufSubstrBeforeFirstC(&processName, '\0'); //Trim the arguments ffStrbufSubstrAfterLastC(&processName, '/'); @@ -371,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; diff --git a/src/detection/displayserver/xcb.c b/src/detection/displayserver/xcb.c index de798c7bd..0953aff9c 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 { @@ -60,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 fc2097ce3..178646661 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 @@ -34,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/detection/gtk.c b/src/detection/gtk.c index 6bda8872d..9ea79631a 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, 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/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..b0a6ee13b 100644 --- a/src/detection/plasma.c +++ b/src/detection/plasma.c @@ -1,5 +1,6 @@ #include "fastfetch.h" +#include #include #include @@ -11,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; @@ -95,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( @@ -116,7 +115,7 @@ const FFPlasmaResult* ffDetectPlasma(FFinstance* instance) ) break; } - ffStrbufDestroy(&baseDirCopy); + ffStrbufDestroy(&baseDir); if(!foundAFile) { diff --git a/src/detection/temps.c b/src/detection/temps.c index 4fcdc5827..1661865a5 100644 --- a/src/detection/temps.c +++ b/src/detection/temps.c @@ -1,8 +1,8 @@ #include "fastfetch.h" +#include #include #include -#include static bool isTempFile(const char* name) { @@ -20,30 +20,42 @@ 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); + ffReadFileBuffer(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"); - ffGetFileContent(dir->chars, &value->name); + ffReadFileBuffer(dir->chars, &value->name); ffStrbufSubstrBefore(dir, dirLength); ffStrbufAppendS(dir, "device/class"); - ffGetFileContent(dir->chars, &value->deviceClass); + ffReadFileBuffer(dir->chars, &value->deviceClass); ffStrbufSubstrBefore(dir, dirLength); return value->name.length > 0 || value->deviceClass.length > 0; @@ -92,12 +104,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/terminalShell.c b/src/detection/terminalShell.c index 9767c1ad8..f42947823 100644 --- a/src/detection/terminalShell.c +++ b/src/detection/terminalShell.c @@ -2,6 +2,7 @@ #include #include +#include #include #include @@ -20,7 +21,7 @@ static void getProcessInformation(const char* pid, FFstrbuf* processName, FFstrb ffStrbufAppendS(&cmdlineFilePath, pid); ffStrbufAppendS(&cmdlineFilePath, "/cmdline"); - ffGetFileContent(cmdlineFilePath.chars, exe); + ffReadFileBuffer(cmdlineFilePath.chars, exe); ffStrbufSubstrBeforeFirstC(exe, '\0'); //Trim the arguments ffStrbufTrimLeft(exe, '-'); //Happens in TTY @@ -119,8 +120,17 @@ 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) && ( + getenv("TERMUX_VERSION") != NULL || + getenv("TERMUX_MAIN_PACKAGE_FORMAT") != NULL || + getenv("TMUX_TMPDIR") != NULL + )) term = "Termux"; //Normal Terminal if(!ffStrSet(term)) diff --git a/src/detection/vulkan.c b/src/detection/vulkan.c index d6dae7e01..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) @@ -174,6 +176,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 f148dbce0..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 @@ -236,7 +234,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", 15, "CPU name", "Prettified CPU name", "CPU Vendor name (Vendor ID)", @@ -244,6 +242,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", @@ -261,12 +260,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) @@ -888,146 +888,214 @@ 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, "--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.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); + 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, "--datetime-key") == 0) - optionParseString(key, value, &instance->config.dateTimeKey); + optionParseString(key, value, &instance->config.dateTime.key); else if(strcasecmp(key, "--datetime-format") == 0) - optionParseString(key, value, &instance->config.dateTimeFormat); + optionParseString(key, value, &instance->config.dateTime.outputFormat); + 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.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..9c1c2bb54 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" @@ -50,6 +45,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 +76,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; @@ -269,6 +237,7 @@ typedef struct FFGPUResult FFstrbuf vendor; FFstrbuf name; FFstrbuf driver; + double temperature; } FFGPUResult; typedef struct FFVulkanResult @@ -300,8 +269,8 @@ typedef struct FFDisplayServerResult typedef struct FFTempValue { FFstrbuf name; - FFstrbuf value; FFstrbuf deviceClass; + double value; } FFTempValue; typedef struct FFTempsResult @@ -444,11 +413,14 @@ void ffListFeatures(); void ffStartDetectionThreads(FFinstance* instance); //common/io.c -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 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); + +bool ffAppendFDBuffer(int fd, FFstrbuf* buffer); +ssize_t ffReadFileData(const char* fileName, size_t dataSize, void* data); +bool ffAppendFileBuffer(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! @@ -457,8 +429,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 +442,12 @@ 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); + +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); @@ -490,7 +467,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 +550,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/logo/builtin.c b/src/logo/builtin.c index 0360d7b2f..326e5bdac 100644 --- a/src/logo/builtin.c +++ b/src/logo/builtin.c @@ -43,6 +43,56 @@ 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* getLogoAlpineSmall() +{ + FF_LOGO_INIT + FF_LOGO_NAMES("alpine_small", "alpine-linux-small") + FF_LOGO_LINES( + " /\\ /\\\n" + " // \\ \\\n" + " // \\ \\\n" + "/// \\ \\\n" + "// \\ \\\n" + " \\" + ) + FF_LOGO_COLORS( + "34" //blue + ) + FF_LOGO_RETURN +} + static const FFlogo* getLogoAndroid() { FF_LOGO_INIT @@ -155,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 @@ -1434,6 +1484,8 @@ GetLogoMethod* ffLogoBuiltinGetAll() static GetLogoMethod logoMethods[] = { ffLogoBuiltinGetUnknown, getLogoNone, + getLogoAlpine, + getLogoAlpineSmall, getLogoAndroid, getLogoAndroidSmall, getLogoArch, 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..057beac77 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) @@ -92,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); } @@ -125,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); @@ -373,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); } @@ -533,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/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 1b7847d9c..8c7489282 100644 --- a/src/modules/battery.c +++ b/src/modules/battery.c @@ -1,6 +1,5 @@ #include "fastfetch.h" -#include #include #define FF_BATTERY_MODULE_NAME "Battery" @@ -24,7 +23,7 @@ static void parseBattery(FFstrbuf* dir, FFlist* results) //type must exist and be "Battery" ffStrbufAppendS(dir, "/type"); - ffGetFileContent(dir->chars, &testBatteryBuffer); + ffReadFileBuffer(dir->chars, &testBatteryBuffer); ffStrbufSubstrBefore(dir, dirLength); if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Battery") != 0) @@ -35,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); + ffReadFileBuffer(dir->chars, &testBatteryBuffer); ffStrbufSubstrBefore(dir, dirLength); if(ffStrbufIgnCaseCompS(&testBatteryBuffer, "Device") == 0) @@ -50,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); + ffReadFileBuffer(dir->chars, &result->capacity); ffStrbufSubstrBefore(dir, dirLength); if(result->capacity.length == 0) @@ -64,30 +63,30 @@ static void parseBattery(FFstrbuf* dir, FFlist* results) ffStrbufInit(&result->manufacturer); ffStrbufAppendS(dir, "/manufacturer"); - ffGetFileContent(dir->chars, &result->manufacturer); + ffReadFileBuffer(dir->chars, &result->manufacturer); ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->modelName); ffStrbufAppendS(dir, "/model_name"); - ffGetFileContent(dir->chars, &result->modelName); + ffReadFileBuffer(dir->chars, &result->modelName); ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->technology); ffStrbufAppendS(dir, "/technology"); - ffGetFileContent(dir->chars, &result->technology); + ffReadFileBuffer(dir->chars, &result->technology); ffStrbufSubstrBefore(dir, dirLength); ffStrbufInit(&result->status); ffStrbufAppendS(dir, "/status"); - ffGetFileContent(dir->chars, &result->status); + ffReadFileBuffer(dir->chars, &result->status); ffStrbufSubstrBefore(dir, dirLength); } 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 +113,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}, @@ -131,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 { @@ -144,7 +142,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 +173,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 ffbcf3c43..c5022391c 100644 --- a/src/modules/cpu.c +++ b/src/modules/cpu.c @@ -1,48 +1,58 @@ #include "fastfetch.h" -#include +#include #define FF_CPU_MODULE_NAME "CPU" -#define FF_CPU_NUM_FORMAT_ARGS 14 - -static double parseHz(FFstrbuf* content) -{ - if(content->length == 0) - return 0; - - double herz; - if(sscanf(content->chars, "%lf", &herz) != 1) - return 0; - - return herz; -} +#define FF_CPU_NUM_FORMAT_ARGS 15 static double getGhz(const char* policyFile, const char* cpuFile) { FFstrbuf content; ffStrbufInit(&content); - ffGetFileContent(policyFile, &content); + ffReadFileBuffer(policyFile, &content); if(content.length == 0) - ffGetFileContent(cpuFile, &content); + ffReadFileBuffer(cpuFile, &content); - double herz = parseHz(&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 } +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 + ) return value->value; + } + + return 0.0 / 0.0; //NaN +} + 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; } @@ -81,7 +91,12 @@ void ffPrintCPU(FFinstance* instance) fclose(cpuinfo); - double procGhz = parseHz(&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"); @@ -124,7 +139,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; } @@ -143,6 +158,10 @@ 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 + double cpuTemp; + if(instance->config.cpu.outputFormat.length > 0) + cpuTemp = detectCPUTemp(instance); + FFstrbuf cpu; ffStrbufInitA(&cpu, 128); @@ -164,7 +183,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}, @@ -172,6 +191,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, &cpuTemp}, {FF_FORMAT_ARG_TYPE_DOUBLE, &biosLimit}, {FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMaxFreq}, {FF_FORMAT_ARG_TYPE_DOUBLE, &scalingMinFreq}, diff --git a/src/modules/cpuUsage.c b/src/modules/cpuUsage.c index 8f98ea84a..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" @@ -12,7 +11,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 +30,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..9b978a620 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 @@ -12,9 +14,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 +30,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 +49,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 +71,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 +107,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,15 +187,21 @@ 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 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.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..fe611c60d 100644 --- a/src/modules/de.c +++ b/src/modules/de.c @@ -1,14 +1,12 @@ #include "fastfetch.h" -#include - #define FF_DE_MODULE_NAME "DE" #define FF_DE_NUM_FORMAT_ARGS 3 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 +14,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 +34,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..2f1effde8 100644 --- a/src/modules/gpu.c +++ b/src/modules/gpu.c @@ -1,9 +1,7 @@ #include "fastfetch.h" -#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) { @@ -33,12 +31,13 @@ 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}, {FF_FORMAT_ARG_TYPE_STRBUF, &namePretty}, {FF_FORMAT_ARG_TYPE_STRBUF, &result->driver}, + {FF_FORMAT_ARG_TYPE_DOUBLE, &result->temperature} }); ffStrbufDestroy(&result->vendor); @@ -60,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*)) @@ -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.gpuFormat.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); + } }; } @@ -163,7 +190,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 +201,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..87254559b 100644 --- a/src/modules/host.c +++ b/src/modules/host.c @@ -1,10 +1,15 @@ #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) { ffStrbufTrimRight(value, '\n'); @@ -32,19 +37,18 @@ static bool hostValueSet(FFstrbuf* value) ; } -#ifndef __ANDROID__ static void getHostValue(const char* devicesPath, const char* classPath, FFstrbuf* buffer) { - ffGetFileContent(devicesPath, buffer); + ffReadFileBuffer(devicesPath, buffer); if(buffer->length == 0) - ffGetFileContent(classPath, buffer); + ffReadFileBuffer(classPath, buffer); } #endif 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; @@ -63,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); + ffReadFileBuffer("/sys/firmware/devicetree/base/model", &product_name); if(product_name.length == 0) - ffGetFileContent("/tmp/sysinfo/model", &product_name); + ffReadFileBuffer("/tmp/sysinfo/model", &product_name); if(ffStrbufStartsWithS(&product_name, "Standard PC")) { @@ -79,6 +83,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_name, "Windows Subsystem for Linux"); #else ffSettingsGetAndroidProperty("ro.product.brand", &product_name); if(product_name.length > 0){ @@ -96,14 +107,14 @@ 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; } #ifdef __ANDROID__ - #define FF_HOST_DATA(name) - FFstrbuf product_name; \ - ffStrbufInitA(&product_name, 0); + #define FF_HOST_DATA(name) \ + FFstrbuf name; \ + ffStrbufInitA(&name, 0); #else #define FF_HOST_DATA(name) \ FFstrbuf name; \ @@ -141,7 +152,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..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 @@ -22,7 +24,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 +47,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..35f9f4324 100644 --- a/src/modules/localip.c +++ b/src/modules/localip.c @@ -3,29 +3,35 @@ #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) { - 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 +44,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..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 @@ -8,7 +10,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 +44,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..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 @@ -44,14 +46,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 +89,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..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 @@ -27,14 +28,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 +389,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..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 @@ -289,13 +292,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 +347,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..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 @@ -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..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 @@ -12,13 +9,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 +28,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..a5b1abb35 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) { @@ -87,18 +87,11 @@ 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 { - 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..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 @@ -13,13 +11,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 +26,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..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 @@ -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..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 @@ -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..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" @@ -6,14 +8,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 +28,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 +39,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 +68,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 +101,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 +123,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 +152,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 +179,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 +215,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 +226,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 +234,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 +256,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); } 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 92d33be4f..32ac8aea9 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 = ""; @@ -515,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); @@ -526,6 +531,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..0d3febc0d 100644 --- a/src/util/FFstrbuf.h +++ b/src/util/FFstrbuf.h @@ -90,9 +90,13 @@ 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); +double ffStrbufToDouble(const FFstrbuf* strbuf); + void ffStrbufDestroy(FFstrbuf* strbuf); #endif 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 { 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 "$@"