Modules: refactor module option handling for static allocation

Moves module option structs out of global config and removes dynamic allocation, using static buffers and size assertions for safer, simpler management.

Refactors module initialization and destruction to work with isolated option structs, eliminating the need for the previous modules container and related code.

Unifies module option header usage and updates detection logic to leverage statically-sized option buffers, improving encapsulation and maintainability.

Simplifies module function signatures and reduces coupling between modules and config.

Enhances future extensibility and reliability by enforcing max size constraints and removing unnecessary indirections.
This commit is contained in:
李通洲 committed 2025-08-04 14:46:01 +08:00
1 parent 559082806b
commit 75d2c668d0
289 files changed
+1449 -1672

No files matched your search

+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/battery/option.h"
#define FF_BATTERY_TEMP_UNSET (0/0.0)
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/bios/option.h"
typedef struct FFBiosResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/bluetooth/option.h"
typedef struct FFBluetoothResult
{
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/bluetoothradio/option.h"
typedef struct FFBluetoothRadioResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/board/option.h"
typedef struct FFBoardResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/bootmgr/option.h"
typedef struct FFBootmgrResult
{
+1 -1
View File
@@ -1,7 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "util/FFlist.h"
#include "modules/brightness/option.h"
typedef struct FFBrightnessResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/btrfs/option.h"
typedef struct FFBtrfsDiskUsage
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/camera/option.h"
typedef struct FFCameraResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/chassis/option.h"
typedef struct FFChassisResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/cpu/option.h"
#define FF_CPU_TEMP_UNSET (0/0.0)
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/cpucache/option.h"
typedef enum __attribute__((__packed__)) FFCPUCacheType
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/cpuusage/option.h"
typedef struct FFCpuUsageInfo {
uint64_t inUseAll;
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/cursor/option.h"
typedef struct FFCursorResult
{
+1
View File
@@ -1,5 +1,6 @@
#pragma once
#include "fastfetch.h"
#include "modules/de/option.h"
const char* ffDetectDEVersion(const FFstrbuf* deName, FFstrbuf* result, FFDEOptions* options);
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/disk/option.h"
typedef struct FFDisk
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/diskio/option.h"
typedef struct FFDiskIOResult
{
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/display/option.h"
#define FF_DE_PRETTY_PLASMA "KDE Plasma"
#define FF_DE_PRETTY_GNOME "GNOME"
+1
View File
@@ -1,5 +1,6 @@
#pragma once
#include "fastfetch.h"
#include "modules/dns/option.h"
const char* ffDetectDNS(FFDNSOptions* options, FFlist* results /* list of FFstrbuf */);
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/editor/option.h"
typedef struct FFEditorResult
{
+2 -1
View File
@@ -1,8 +1,9 @@
#pragma once
#include "fastfetch.h"
#include "modules/font/option.h"
#define FF_DETECT_FONT_NUM_FONTS 4
enum { FF_DETECT_FONT_NUM_FONTS = 4 };
typedef struct FFFontResult
{
+5 -1
View File
@@ -2,6 +2,7 @@
#include "detection/vulkan/vulkan.h"
#include "detection/opencl/opencl.h"
#include "detection/opengl/opengl.h"
#include "modules/opengl/opengl.h"
const char* FF_GPU_VENDOR_NAME_APPLE = "Apple";
const char* FF_GPU_VENDOR_NAME_AMD = "AMD";
@@ -56,7 +57,10 @@ const char* detectByOpenGL(FFlist* gpus)
ffStrbufInit(&result.slv);
ffStrbufInit(&result.library);
const char* error = ffDetectOpenGL(&instance.config.modules.openGL, &result);
__attribute__((__cleanup__(ffDestroyOpenGLOptions))) FFOpenGLOptions options;
ffInitOpenGLOptions(&options);
const char* error = ffDetectOpenGL(&options, &result);
if (!error)
{
FFGPUResult* gpu = (FFGPUResult*) ffListAdd(gpus);
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/gpu/option.h"
#define FF_GPU_TEMP_UNSET (0/0.0)
#define FF_GPU_CORE_COUNT_UNSET -1
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/host/option.h"
typedef struct FFHostResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/icons/option.h"
typedef struct FFIconsResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/initsystem/option.h"
typedef struct FFInitSystemResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/lm/option.h"
typedef struct FFLMResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/localip/option.h"
typedef struct FFLocalIpResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/media/option.h"
typedef struct FFMediaResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/memory/option.h"
typedef struct FFMemoryResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/netio/option.h"
typedef struct FFNetIOResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/opencl/option.h"
typedef struct FFOpenCLResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/opengl/option.h"
typedef struct FFOpenGLResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/os/option.h"
typedef struct FFOSResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/packages/option.h"
typedef struct FFPackagesResult
{
@@ -1,4 +1,5 @@
#include "fastfetch.h"
#include "modules/physicaldisk/option.h"
#define FF_PHYSICALDISK_TEMP_UNSET (0/0.0)
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/physicalmemory/option.h"
typedef struct FFPhysicalMemoryResult
{
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/poweradapter/option.h"
typedef struct FFPowerAdapterResult
{
+2 -2
View File
@@ -5,7 +5,7 @@
static FFNetworkingState states[2];
static const char* statuses[2] = { FF_UNITIALIZED, FF_UNITIALIZED };
void ffPreparePublicIp(FFPublicIpOptions* options)
void ffPreparePublicIp(FFPublicIPOptions* options)
{
FFNetworkingState* state = &states[options->ipv6];
const char** status = &statuses[options->ipv6];
@@ -58,7 +58,7 @@ static inline void wrapYyjsonFree(yyjson_doc** doc)
yyjson_doc_free(*doc);
}
const char* ffDetectPublicIp(FFPublicIpOptions* options, FFPublicIpResult* result)
const char* ffDetectPublicIp(FFPublicIPOptions* options, FFPublicIpResult* result)
{
FFNetworkingState* state = &states[options->ipv6];
const char** status = &statuses[options->ipv6];
+3 -2
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/publicip/option.h"
typedef struct FFPublicIpResult
{
@@ -8,5 +9,5 @@ typedef struct FFPublicIpResult
FFstrbuf location;
} FFPublicIpResult;
void ffPreparePublicIp(FFPublicIpOptions* options);
const char* ffDetectPublicIp(FFPublicIpOptions* options, FFPublicIpResult* result);
void ffPreparePublicIp(FFPublicIPOptions* options);
const char* ffDetectPublicIp(FFPublicIPOptions* options, FFPublicIpResult* result);
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/swap/option.h"
typedef struct FFSwapResult
{
@@ -2,6 +2,7 @@
#include "fastfetch.h"
#include "common/font.h"
#include "modules/font/option.h"
typedef struct FFTerminalFontResult
{
@@ -1,6 +1,8 @@
#pragma once
#include "fastfetch.h"
#include "modules/terminal/option.h"
#include "modules/shell/option.h"
typedef struct FFShellResult
{
@@ -53,7 +53,7 @@ static pid_t getShellInfo(FFShellResult* result, pid_t pid)
ffStrbufContainS(&result->processName, "hyfetch") || //when hyfetch uses fastfetch as backend
ffStrbufEqualS(&result->processName, "clifm") || //https://github.com/leo-arch/clifm/issues/289
ffStrbufEqualS(&result->processName, "valgrind") ||
ffStrbufEqualS(&result->processName, "fastfetch") || //994
ffStrbufEqualS(&result->processName, "fastfetch") || //#994
ffStrbufEqualS(&result->processName, "flashfetch") ||
ffStrbufEqualS(&result->processName, "proot") ||
ffStrbufEqualS(&result->processName, "script") ||
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/terminalsize/option.h"
typedef struct FFTerminalSizeResult
{
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/terminaltheme/option.h"
typedef struct FFTerminalThemeColor
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/theme/option.h"
typedef struct FFThemeResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/tpm/option.h"
typedef struct FFTPMResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/uptime/option.h"
typedef struct FFUptimeResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/users/option.h"
typedef struct FFUserResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/version/option.h"
typedef struct FFVersionResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/vulkan/option.h"
typedef struct FFVulkanResult
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/weather/option.h"
void ffPrepareWeather(FFWeatherOptions* options);
const char* ffDetectWeather(FFWeatherOptions* options, FFstrbuf* result);
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/wifi/option.h"
struct FFWifiInterface
{
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/wm/wm.h"
const char* ffDetectWMPlugin(FFstrbuf* pluginName);
const char* ffDetectWMVersion(const FFstrbuf* wmName, FFstrbuf* result, FFWMOptions* options);
+1
View File
@@ -1,6 +1,7 @@
#pragma once
#include "fastfetch.h"
#include "modules/zpool/option.h"
typedef struct FFZpoolResult
{