From 97e1b987dd91f9fb802d32fb5c711b46a10ff7ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 14 Nov 2024 10:04:57 +0800 Subject: [PATCH] Global: pack all enums and make flag enums unsigned --- src/common/format.h | 2 +- src/common/io/io.h | 3 ++- src/common/option.h | 3 ++- src/common/percent.c | 10 ++++---- src/common/percent.h | 23 +++++++++++++------ src/common/printing.h | 3 ++- src/common/settings.h | 2 +- src/detection/cpucache/cpucache.h | 2 +- src/detection/displayserver/displayserver.h | 4 ++-- .../displayserver/linux/wayland/wayland.h | 2 +- src/detection/gpu/gpu_driver_specific.h | 3 ++- src/detection/gtk_qt/qt.c | 2 +- src/detection/physicaldisk/physicaldisk.h | 5 +++- src/logo/image/image.h | 2 +- src/logo/logo.c | 2 +- src/logo/logo.h | 3 ++- src/modules/battery/battery.c | 2 +- src/modules/battery/option.h | 2 +- src/modules/bluetooth/bluetooth.c | 2 +- src/modules/bluetooth/option.h | 2 +- src/modules/brightness/brightness.c | 2 +- src/modules/brightness/option.h | 2 +- src/modules/btrfs/btrfs.c | 2 +- src/modules/btrfs/option.h | 2 +- src/modules/colors/option.h | 2 +- src/modules/cpuusage/cpuusage.c | 2 +- src/modules/cpuusage/option.h | 2 +- src/modules/disk/disk.c | 2 +- src/modules/disk/option.h | 7 +++--- src/modules/display/option.h | 5 ++-- src/modules/dns/dns.c | 3 +++ src/modules/dns/option.h | 3 ++- src/modules/gamepad/gamepad.c | 2 +- src/modules/gamepad/option.h | 2 +- src/modules/gpu/gpu.c | 2 +- src/modules/gpu/option.h | 6 ++--- src/modules/loadavg/loadavg.c | 2 +- src/modules/loadavg/option.h | 2 +- src/modules/localip/option.h | 4 +++- src/modules/memory/memory.c | 2 +- src/modules/memory/option.h | 2 +- src/modules/opengl/option.h | 2 +- src/modules/packages/option.h | 4 +++- src/modules/sound/option.h | 4 ++-- src/modules/sound/sound.c | 2 +- src/modules/swap/option.h | 2 +- src/modules/swap/swap.c | 2 +- src/modules/wifi/option.h | 2 +- src/modules/wifi/wifi.c | 2 +- src/modules/zpool/option.h | 2 +- src/modules/zpool/zpool.c | 2 +- src/options/display.h | 6 ++--- src/options/general.h | 2 +- src/options/logo.h | 4 ++-- 54 files changed, 100 insertions(+), 73 deletions(-) diff --git a/src/common/format.h b/src/common/format.h index 79e1c90f4..fa092b40a 100644 --- a/src/common/format.h +++ b/src/common/format.h @@ -2,7 +2,7 @@ #include "util/FFstrbuf.h" -typedef enum FFformatArgType +typedef enum __attribute__((__packed__)) FFformatArgType { FF_FORMAT_ARG_TYPE_NULL = 0, FF_FORMAT_ARG_TYPE_UINT, diff --git a/src/common/io/io.h b/src/common/io/io.h index 910c64825..4cee2e471 100644 --- a/src/common/io/io.h +++ b/src/common/io/io.h @@ -87,11 +87,12 @@ static inline bool ffReadFileBufferRelative(FFNativeFD dfd, const char* fileName } //Bit flags, combine with | -typedef enum FFPathType +typedef enum __attribute__((__packed__)) FFPathType { FF_PATHTYPE_FILE = 1 << 0, FF_PATHTYPE_DIRECTORY = 1 << 1, FF_PATHTYPE_ANY = FF_PATHTYPE_FILE | FF_PATHTYPE_DIRECTORY, + FF_PATHTYPE_FORCE_UNSIGNED = UINT8_MAX, } FFPathType; static inline bool ffPathExists(const char* path, FFPathType pathType) diff --git a/src/common/option.h b/src/common/option.h index 10576c0ff..b9f3fb311 100644 --- a/src/common/option.h +++ b/src/common/option.h @@ -45,12 +45,13 @@ static inline void ffOptionInitModuleBaseInfo( baseInfo->generateJsonConfig = (__typeof__(baseInfo->generateJsonConfig)) generateJsonConfig; } -typedef enum FFModuleKeyType +typedef enum __attribute__((__packed__)) FFModuleKeyType { FF_MODULE_KEY_TYPE_NONE = 0, FF_MODULE_KEY_TYPE_STRING = 1 << 0, FF_MODULE_KEY_TYPE_ICON = 1 << 1, FF_MODULE_KEY_TYPE_BOTH = FF_MODULE_KEY_TYPE_STRING | FF_MODULE_KEY_TYPE_ICON, + FF_MODULE_KEY_TYPE_FORCE_UNSIGNED = UINT8_MAX, } FFModuleKeyType; typedef struct FFModuleArgs diff --git a/src/common/percent.c b/src/common/percent.c index 9cc6e9d45..0993346e8 100644 --- a/src/common/percent.c +++ b/src/common/percent.c @@ -14,7 +14,7 @@ static void appendOutputColor(FFstrbuf* buffer, const FFModuleArgs* module) ffStrbufAppendF(buffer, "\e[%sm", instance.config.display.colorOutput.chars); } -void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig config, const FFModuleArgs* module) +void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConfig config, const FFModuleArgs* module) { uint8_t green = config.green, yellow = config.yellow; assert(green <= 100 && yellow <= 100); @@ -104,7 +104,7 @@ void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig con } } -void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFColorRangeConfig config, bool parentheses, const FFModuleArgs* module) +void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentageModuleConfig config, bool parentheses, const FFModuleArgs* module) { uint8_t green = config.green, yellow = config.yellow; assert(green <= 100 && yellow <= 100); @@ -156,7 +156,7 @@ void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFColorRangeConfig con ffStrbufAppendC(buffer, ')'); } -bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFColorRangeConfig* config) +bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFPercentageModuleConfig* config) { if (!ffStrStartsWithIgnCase(subkey, "percent-")) return false; @@ -190,7 +190,7 @@ bool ffPercentParseCommandOptions(const char* key, const char* subkey, const cha return false; } -bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFColorRangeConfig* config) +bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFPercentageModuleConfig* config) { if (!ffStrEqualsIgnCase(key, "percent")) return false; @@ -228,7 +228,7 @@ bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFColorRangeCo return true; } -void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFColorRangeConfig defaultConfig, FFColorRangeConfig config) +void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentageModuleConfig defaultConfig, FFPercentageModuleConfig config) { if (config.green == defaultConfig.green && config.yellow == defaultConfig.yellow) return; diff --git a/src/common/percent.h b/src/common/percent.h index 33921f689..c7350ff1c 100644 --- a/src/common/percent.h +++ b/src/common/percent.h @@ -4,14 +4,23 @@ #include "common/parsing.h" #include "common/option.h" -enum FFPercentageTypeFlags +typedef enum __attribute__((__packed__)) FFPercentageTypeFlags { + FF_PERCENTAGE_TYPE_NONE = 0, FF_PERCENTAGE_TYPE_NUM_BIT = 1 << 0, FF_PERCENTAGE_TYPE_BAR_BIT = 1 << 1, FF_PERCENTAGE_TYPE_HIDE_OTHERS_BIT = 1 << 2, FF_PERCENTAGE_TYPE_NUM_COLOR_BIT = 1 << 3, FF_PERCENTAGE_TYPE_BAR_MONOCHROME_BIT = FF_PERCENTAGE_TYPE_NUM_COLOR_BIT, -}; + FF_PERCENTAGE_TYPE_FORCE_UNSIGNED_ = UINT8_MAX, +} FFPercentageTypeFlags; +static_assert(sizeof(FFPercentageTypeFlags) == 1, ""); + +typedef struct FFPercentageModuleConfig +{ + uint8_t green; + uint8_t yellow; +} FFPercentageModuleConfig; // if (green <= yellow) // [0, green]: print green @@ -23,12 +32,12 @@ enum FFPercentageTypeFlags // [yellow, green): print yellow // [0, yellow): print red -void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFColorRangeConfig config, const FFModuleArgs* module); -void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFColorRangeConfig config, bool parentheses, const FFModuleArgs* module); +void ffPercentAppendBar(FFstrbuf* buffer, double percent, FFPercentageModuleConfig config, const FFModuleArgs* module); +void ffPercentAppendNum(FFstrbuf* buffer, double percent, FFPercentageModuleConfig config, bool parentheses, const FFModuleArgs* module); typedef struct yyjson_val yyjson_val; typedef struct yyjson_mut_doc yyjson_mut_doc; typedef struct yyjson_mut_val yyjson_mut_val; -bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFColorRangeConfig* config); -bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFColorRangeConfig* config); -void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFColorRangeConfig defaultConfig, FFColorRangeConfig config); +bool ffPercentParseCommandOptions(const char* key, const char* subkey, const char* value, FFPercentageModuleConfig* config); +bool ffPercentParseJsonObject(const char* key, yyjson_val* value, FFPercentageModuleConfig* config); +void ffPercentGenerateJsonConfig(yyjson_mut_doc* doc, yyjson_mut_val* module, FFPercentageModuleConfig defaultConfig, FFPercentageModuleConfig config); diff --git a/src/common/printing.h b/src/common/printing.h index 2060337c5..94479dc03 100644 --- a/src/common/printing.h +++ b/src/common/printing.h @@ -3,12 +3,13 @@ #include "fastfetch.h" #include "common/format.h" -typedef enum FFPrintType { +typedef enum __attribute__((__packed__)) FFPrintType { FF_PRINT_TYPE_DEFAULT = 0, FF_PRINT_TYPE_NO_CUSTOM_KEY = 1 << 0, // key has been formatted outside FF_PRINT_TYPE_NO_CUSTOM_KEY_COLOR = 1 << 1, FF_PRINT_TYPE_NO_CUSTOM_KEY_WIDTH = 1 << 2, FF_PRINT_TYPE_NO_CUSTOM_OUTPUT_FORMAT = 1 << 3, // reserved + FF_PRINT_TYPE_FORCE_UNSIGNED = UINT8_MAX, } FFPrintType; void ffPrintLogoAndKey(const char* moduleName, uint8_t moduleIndex, const FFModuleArgs* moduleArgs, FFPrintType printType); diff --git a/src/common/settings.h b/src/common/settings.h index 0b87bb33e..cfe6d093e 100644 --- a/src/common/settings.h +++ b/src/common/settings.h @@ -2,7 +2,7 @@ #include "fastfetch.h" -typedef enum FFvarianttype +typedef enum __attribute__((__packed__)) FFvarianttype { FF_VARIANT_TYPE_STRING, FF_VARIANT_TYPE_BOOL, diff --git a/src/detection/cpucache/cpucache.h b/src/detection/cpucache/cpucache.h index fb8170c4a..f63964240 100644 --- a/src/detection/cpucache/cpucache.h +++ b/src/detection/cpucache/cpucache.h @@ -2,7 +2,7 @@ #include "fastfetch.h" -typedef enum FFCPUCacheType +typedef enum __attribute__((__packed__)) FFCPUCacheType { FF_CPU_CACHE_TYPE_UNIFIED = 0, FF_CPU_CACHE_TYPE_INSTRUCTION = 1, diff --git a/src/detection/displayserver/displayserver.h b/src/detection/displayserver/displayserver.h index d1d21839e..4de3bdd4d 100644 --- a/src/detection/displayserver/displayserver.h +++ b/src/detection/displayserver/displayserver.h @@ -42,13 +42,13 @@ #define FF_WM_PROTOCOL_X11 "X11" #define FF_WM_PROTOCOL_WAYLAND "Wayland" -typedef enum FFDisplayType { +typedef enum __attribute__((__packed__)) FFDisplayType { FF_DISPLAY_TYPE_UNKNOWN, FF_DISPLAY_TYPE_BUILTIN, FF_DISPLAY_TYPE_EXTERNAL, } FFDisplayType; -typedef enum FFDisplayHdrStatus +typedef enum __attribute__((__packed__)) FFDisplayHdrStatus { FF_DISPLAY_HDR_STATUS_UNKNOWN, FF_DISPLAY_HDR_STATUS_UNSUPPORTED, diff --git a/src/detection/displayserver/linux/wayland/wayland.h b/src/detection/displayserver/linux/wayland/wayland.h index 3c3b64a94..c19d88199 100644 --- a/src/detection/displayserver/linux/wayland/wayland.h +++ b/src/detection/displayserver/linux/wayland/wayland.h @@ -9,7 +9,7 @@ #include "../displayserver_linux.h" -typedef enum WaylandProtocolType +typedef enum __attribute__((__packed__)) WaylandProtocolType { FF_WAYLAND_PROTOCOL_TYPE_NONE, FF_WAYLAND_PROTOCOL_TYPE_GLOBAL, diff --git a/src/detection/gpu/gpu_driver_specific.h b/src/detection/gpu/gpu_driver_specific.h index 989ef6093..258dc68f1 100644 --- a/src/detection/gpu/gpu_driver_specific.h +++ b/src/detection/gpu/gpu_driver_specific.h @@ -2,11 +2,12 @@ #include "gpu.h" -typedef enum FFGpuDriverConditionType +typedef enum __attribute__((__packed__)) FFGpuDriverConditionType { FF_GPU_DRIVER_CONDITION_TYPE_BUS_ID = 1 << 0, FF_GPU_DRIVER_CONDITION_TYPE_DEVICE_ID = 1 << 1, FF_GPU_DRIVER_CONDITION_TYPE_LUID = 1 << 2, + FF_GPU_DRIVER_CONDITION_TYPE_FORCE_UNSIGNED = UINT8_MAX, } FFGpuDriverConditionType; typedef struct FFGpuDriverPciBusId diff --git a/src/detection/gtk_qt/qt.c b/src/detection/gtk_qt/qt.c index 02c578a16..cefdf86dc 100644 --- a/src/detection/gtk_qt/qt.c +++ b/src/detection/gtk_qt/qt.c @@ -18,7 +18,7 @@ static inline bool allValuesSet(const FFQtResult* result) result->wallpaper.length > 0; } -typedef enum PlasmaCategory +typedef enum __attribute__((__packed__)) PlasmaCategory { PLASMA_CATEGORY_GENERAL, PLASMA_CATEGORY_KDE, diff --git a/src/detection/physicaldisk/physicaldisk.h b/src/detection/physicaldisk/physicaldisk.h index 76863f783..fbed2f52c 100644 --- a/src/detection/physicaldisk/physicaldisk.h +++ b/src/detection/physicaldisk/physicaldisk.h @@ -2,7 +2,7 @@ #define FF_PHYSICALDISK_TEMP_UNSET (0/0.0) -typedef enum FFPhysicalDiskType +typedef enum __attribute__((__packed__)) FFPhysicalDiskType { FF_PHYSICALDISK_TYPE_NONE = 0, @@ -15,7 +15,10 @@ typedef enum FFPhysicalDiskType FF_PHYSICALDISK_TYPE_READWRITE = 1 << 4, FF_PHYSICALDISK_TYPE_READONLY = 1 << 5, + + FF_PHYSICALDISK_TYPE_FORCE_UNSIGNED = UINT8_MAX, } FFPhysicalDiskType; +static_assert(sizeof(FFPhysicalDiskType) == sizeof(uint8_t), ""); typedef struct FFPhysicalDiskResult { diff --git a/src/logo/image/image.h b/src/logo/image/image.h index 608286392..58a2f6289 100644 --- a/src/logo/image/image.h +++ b/src/logo/image/image.h @@ -4,7 +4,7 @@ #if defined(FF_HAVE_IMAGEMAGICK7) || defined(FF_HAVE_IMAGEMAGICK6) -typedef enum FFLogoImageResult +typedef enum __attribute__((__packed__)) FFLogoImageResult { FF_LOGO_IMAGE_RESULT_SUCCESS, //Logo printed FF_LOGO_IMAGE_RESULT_INIT_ERROR, //Failed to load library, try again with next IM version diff --git a/src/logo/logo.c b/src/logo/logo.c index 26da1eed7..09dfd8696 100644 --- a/src/logo/logo.c +++ b/src/logo/logo.c @@ -9,7 +9,7 @@ #include #include -typedef enum FFLogoSize +typedef enum __attribute__((__packed__)) FFLogoSize { FF_LOGO_SIZE_UNKNOWN, FF_LOGO_SIZE_NORMAL, diff --git a/src/logo/logo.h b/src/logo/logo.h index e9bea9788..92a1683a6 100644 --- a/src/logo/logo.h +++ b/src/logo/logo.h @@ -2,11 +2,12 @@ #include "fastfetch.h" -typedef enum FFLogoLineType +typedef enum __attribute__((__packed__)) FFLogoLineType { FF_LOGO_LINE_TYPE_NORMAL = 0, FF_LOGO_LINE_TYPE_SMALL_BIT = 1 << 0, // The names of small logo must end with `_small` or `-small` FF_LOGO_LINE_TYPE_ALTER_BIT = 1 << 1, + FF_LOGO_LINE_TYPE_FORCE_UNSIGNED = UINT8_MAX, } FFLogoLineType; typedef struct FFlogo diff --git a/src/modules/battery/battery.c b/src/modules/battery/battery.c index cc30b4262..fad309bb7 100644 --- a/src/modules/battery/battery.c +++ b/src/modules/battery/battery.c @@ -301,7 +301,7 @@ void ffInitBatteryOptions(FFBatteryOptions* options) ffOptionInitModuleArg(&options->moduleArgs, ""); options->temp = false; options->tempConfig = (FFColorRangeConfig) { 60, 80 }; - options->percent = (FFColorRangeConfig) { 50, 20 }; + options->percent = (FFPercentageModuleConfig) { 50, 20 }; #ifdef _WIN32 options->useSetupApi = false; diff --git a/src/modules/battery/option.h b/src/modules/battery/option.h index ecaa45ccc..8b04ef1b4 100644 --- a/src/modules/battery/option.h +++ b/src/modules/battery/option.h @@ -12,7 +12,7 @@ typedef struct FFBatteryOptions bool temp; FFColorRangeConfig tempConfig; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; #ifdef _WIN32 bool useSetupApi; diff --git a/src/modules/bluetooth/bluetooth.c b/src/modules/bluetooth/bluetooth.c index b00ff013c..0139289e1 100644 --- a/src/modules/bluetooth/bluetooth.c +++ b/src/modules/bluetooth/bluetooth.c @@ -202,7 +202,7 @@ void ffInitBluetoothOptions(FFBluetoothOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs, ""); options->showDisconnected = false; - options->percent = (FFColorRangeConfig) { 50, 20 }; + options->percent = (FFPercentageModuleConfig) { 50, 20 }; } void ffDestroyBluetoothOptions(FFBluetoothOptions* options) diff --git a/src/modules/bluetooth/option.h b/src/modules/bluetooth/option.h index 7938e77f0..4de6fff72 100644 --- a/src/modules/bluetooth/option.h +++ b/src/modules/bluetooth/option.h @@ -11,5 +11,5 @@ typedef struct FFBluetoothOptions FFModuleArgs moduleArgs; bool showDisconnected; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; } FFBluetoothOptions; diff --git a/src/modules/brightness/brightness.c b/src/modules/brightness/brightness.c index c5740bc57..7b06613c5 100644 --- a/src/modules/brightness/brightness.c +++ b/src/modules/brightness/brightness.c @@ -237,7 +237,7 @@ void ffInitBrightnessOptions(FFBrightnessOptions* options) ffOptionInitModuleArg(&options->moduleArgs, "󰯪"); options->ddcciSleep = 10; - options->percent = (FFColorRangeConfig) { 100, 100 }; + options->percent = (FFPercentageModuleConfig) { 100, 100 }; options->compact = false; } diff --git a/src/modules/brightness/option.h b/src/modules/brightness/option.h index e359cdc3e..70337f59e 100644 --- a/src/modules/brightness/option.h +++ b/src/modules/brightness/option.h @@ -11,6 +11,6 @@ typedef struct FFBrightnessOptions FFModuleArgs moduleArgs; uint32_t ddcciSleep; // ms - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; bool compact; } FFBrightnessOptions; diff --git a/src/modules/btrfs/btrfs.c b/src/modules/btrfs/btrfs.c index 77e7ba1ad..c874b69d4 100644 --- a/src/modules/btrfs/btrfs.c +++ b/src/modules/btrfs/btrfs.c @@ -245,7 +245,7 @@ void ffInitBtrfsOptions(FFBtrfsOptions* options) ffGenerateBtrfsJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs, "󱑛"); - options->percent = (FFColorRangeConfig) { 50, 80 }; + options->percent = (FFPercentageModuleConfig) { 50, 80 }; } void ffDestroyBtrfsOptions(FFBtrfsOptions* options) diff --git a/src/modules/btrfs/option.h b/src/modules/btrfs/option.h index 504b15768..2e4b069b4 100644 --- a/src/modules/btrfs/option.h +++ b/src/modules/btrfs/option.h @@ -10,5 +10,5 @@ typedef struct FFBtrfsOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; } FFBtrfsOptions; diff --git a/src/modules/colors/option.h b/src/modules/colors/option.h index 54a8e496d..1a948a9b1 100644 --- a/src/modules/colors/option.h +++ b/src/modules/colors/option.h @@ -4,7 +4,7 @@ #include "common/option.h" -typedef enum FFColorsSymbol +typedef enum __attribute__((__packed__)) FFColorsSymbol { FF_COLORS_SYMBOL_BLOCK, FF_COLORS_SYMBOL_BACKGROUND, diff --git a/src/modules/cpuusage/cpuusage.c b/src/modules/cpuusage/cpuusage.c index ab5e4b9d2..cf4a5a65c 100644 --- a/src/modules/cpuusage/cpuusage.c +++ b/src/modules/cpuusage/cpuusage.c @@ -214,7 +214,7 @@ void ffInitCPUUsageOptions(FFCPUUsageOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs, "󰓅"); options->separate = false; - options->percent = (FFColorRangeConfig) { 50, 80 }; + options->percent = (FFPercentageModuleConfig) { 50, 80 }; options->waitTime = 200; } diff --git a/src/modules/cpuusage/option.h b/src/modules/cpuusage/option.h index 844828b94..9f65f701d 100644 --- a/src/modules/cpuusage/option.h +++ b/src/modules/cpuusage/option.h @@ -11,6 +11,6 @@ typedef struct FFCPUUsageOptions FFModuleArgs moduleArgs; bool separate; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; uint32_t waitTime; // in ms } FFCPUUsageOptions; diff --git a/src/modules/disk/disk.c b/src/modules/disk/disk.c index 5dddf1e90..2eb39f48f 100644 --- a/src/modules/disk/disk.c +++ b/src/modules/disk/disk.c @@ -473,7 +473,7 @@ void ffInitDiskOptions(FFDiskOptions* options) ffStrbufInit(&options->folders); options->showTypes = FF_DISK_VOLUME_TYPE_REGULAR_BIT | FF_DISK_VOLUME_TYPE_EXTERNAL_BIT | FF_DISK_VOLUME_TYPE_READONLY_BIT; options->calcType = FF_DISK_CALC_TYPE_FREE; - options->percent = (FFColorRangeConfig) { 50, 80 }; + options->percent = (FFPercentageModuleConfig) { 50, 80 }; } void ffDestroyDiskOptions(FFDiskOptions* options) diff --git a/src/modules/disk/option.h b/src/modules/disk/option.h index 7c2abdcaa..eb2323f4c 100644 --- a/src/modules/disk/option.h +++ b/src/modules/disk/option.h @@ -5,7 +5,7 @@ #include "common/option.h" #include "common/percent.h" -typedef enum FFDiskVolumeType +typedef enum __attribute__((__packed__)) FFDiskVolumeType { FF_DISK_VOLUME_TYPE_NONE = 0, FF_DISK_VOLUME_TYPE_REGULAR_BIT = 1 << 0, @@ -14,9 +14,10 @@ typedef enum FFDiskVolumeType FF_DISK_VOLUME_TYPE_SUBVOLUME_BIT = 1 << 3, FF_DISK_VOLUME_TYPE_UNKNOWN_BIT = 1 << 4, FF_DISK_VOLUME_TYPE_READONLY_BIT = 1 << 5, + FF_DISK_VOLUME_TYPE_FORCE_UNSIGNED = UINT8_MAX, } FFDiskVolumeType; -typedef enum FFDiskCalcType +typedef enum __attribute__((__packed__)) FFDiskCalcType { FF_DISK_CALC_TYPE_FREE, FF_DISK_CALC_TYPE_AVAILABLE, @@ -30,5 +31,5 @@ typedef struct FFDiskOptions FFstrbuf folders; FFDiskVolumeType showTypes; FFDiskCalcType calcType; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; } FFDiskOptions; diff --git a/src/modules/display/option.h b/src/modules/display/option.h index d6238e1b1..7233b2dd3 100644 --- a/src/modules/display/option.h +++ b/src/modules/display/option.h @@ -4,15 +4,16 @@ #include "common/option.h" -typedef enum FFDisplayCompactType +typedef enum __attribute__((__packed__)) FFDisplayCompactType { FF_DISPLAY_COMPACT_TYPE_NONE = 0, FF_DISPLAY_COMPACT_TYPE_ORIGINAL_BIT = 1 << 0, FF_DISPLAY_COMPACT_TYPE_SCALED_BIT = 1 << 1, FF_DISPLAY_COMPACT_TYPE_REFRESH_RATE_BIT = 1 << 2, + FF_DISPLAY_COMPACT_TYPE_UNSIGNED = UINT8_MAX, } FFDisplayCompactType; -typedef enum FFDisplayOrder +typedef enum __attribute__((__packed__)) FFDisplayOrder { FF_DISPLAY_ORDER_NONE, FF_DISPLAY_ORDER_ASC, diff --git a/src/modules/dns/dns.c b/src/modules/dns/dns.c index 63a744885..fe4654f23 100644 --- a/src/modules/dns/dns.c +++ b/src/modules/dns/dns.c @@ -122,6 +122,8 @@ void ffGenerateDNSJsonConfig(FFDNSOptions* options, yyjson_mut_doc* doc, yyjson_ if (defaultOptions.showType != options->showType) { + #pragma GCC diagnostic push + #pragma GCC diagnostic ignored "-Wswitch" // FF_DNS_TYPE_FORCE_UNSIGNED switch (options->showType) { case FF_DNS_TYPE_IPV4_BIT: @@ -134,6 +136,7 @@ void ffGenerateDNSJsonConfig(FFDNSOptions* options, yyjson_mut_doc* doc, yyjson_ yyjson_mut_obj_add_str(doc, module, "showType", "both"); break; } + #pragma GCC diagnostic pop } } diff --git a/src/modules/dns/option.h b/src/modules/dns/option.h index d261d7e06..18dbb147b 100644 --- a/src/modules/dns/option.h +++ b/src/modules/dns/option.h @@ -4,10 +4,11 @@ #include "common/option.h" -typedef enum FFDNSShowType { +typedef enum __attribute__((__packed__)) FFDNSShowType { FF_DNS_TYPE_IPV4_BIT = 1, FF_DNS_TYPE_IPV6_BIT = 2, FF_DNS_TYPE_BOTH = FF_DNS_TYPE_IPV4_BIT | FF_DNS_TYPE_IPV6_BIT, + FF_DNS_TYPE_FORCE_UNSIGNED = UINT8_MAX, } FFDNSShowType; typedef struct FFDNSOptions diff --git a/src/modules/gamepad/gamepad.c b/src/modules/gamepad/gamepad.c index b1b3457f0..f30aa1772 100644 --- a/src/modules/gamepad/gamepad.c +++ b/src/modules/gamepad/gamepad.c @@ -160,7 +160,7 @@ void ffInitGamepadOptions(FFGamepadOptions* options) ffGenerateGamepadJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs, "󰺵"); - options->percent = (FFColorRangeConfig) { 50, 20 }; + options->percent = (FFPercentageModuleConfig) { 50, 20 }; } void ffDestroyGamepadOptions(FFGamepadOptions* options) diff --git a/src/modules/gamepad/option.h b/src/modules/gamepad/option.h index b4ecaf94d..d1b570bf8 100644 --- a/src/modules/gamepad/option.h +++ b/src/modules/gamepad/option.h @@ -9,5 +9,5 @@ typedef struct FFGamepadOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; } FFGamepadOptions; diff --git a/src/modules/gpu/gpu.c b/src/modules/gpu/gpu.c index 57a7b9a8a..890e06716 100644 --- a/src/modules/gpu/gpu.c +++ b/src/modules/gpu/gpu.c @@ -439,7 +439,7 @@ void ffInitGPUOptions(FFGPUOptions* options) options->temp = false; options->hideType = FF_GPU_TYPE_UNKNOWN; options->tempConfig = (FFColorRangeConfig) { 60, 80 }; - options->percent = (FFColorRangeConfig) { 50, 80 }; + options->percent = (FFPercentageModuleConfig) { 50, 80 }; } void ffDestroyGPUOptions(FFGPUOptions* options) diff --git a/src/modules/gpu/option.h b/src/modules/gpu/option.h index 5f53d2f6f..98362940b 100644 --- a/src/modules/gpu/option.h +++ b/src/modules/gpu/option.h @@ -5,14 +5,14 @@ #include "common/option.h" #include "common/percent.h" -typedef enum FFGPUType +typedef enum __attribute__((__packed__)) FFGPUType { FF_GPU_TYPE_UNKNOWN, FF_GPU_TYPE_INTEGRATED, FF_GPU_TYPE_DISCRETE, } FFGPUType; -typedef enum FFGPUDetectionMethod +typedef enum __attribute__((__packed__)) FFGPUDetectionMethod { FF_GPU_DETECTION_METHOD_AUTO, FF_GPU_DETECTION_METHOD_PCI, @@ -32,5 +32,5 @@ typedef struct FFGPUOptions bool driverSpecific; bool forceMethod; FFColorRangeConfig tempConfig; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; } FFGPUOptions; diff --git a/src/modules/loadavg/loadavg.c b/src/modules/loadavg/loadavg.c index d53b12ff4..4e712e93b 100644 --- a/src/modules/loadavg/loadavg.c +++ b/src/modules/loadavg/loadavg.c @@ -204,7 +204,7 @@ void ffInitLoadavgOptions(FFLoadavgOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs, ""); - options->percent = (FFColorRangeConfig) { 50, 80 }; + options->percent = (FFPercentageModuleConfig) { 50, 80 }; options->ndigits = 2; options->compact = true; } diff --git a/src/modules/loadavg/option.h b/src/modules/loadavg/option.h index 0bcce0037..aee5f435c 100644 --- a/src/modules/loadavg/option.h +++ b/src/modules/loadavg/option.h @@ -9,7 +9,7 @@ typedef struct FFLoadavgOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; uint8_t ndigits; bool compact; } FFLoadavgOptions; diff --git a/src/modules/localip/option.h b/src/modules/localip/option.h index 511ec729d..c95b77d8b 100644 --- a/src/modules/localip/option.h +++ b/src/modules/localip/option.h @@ -4,7 +4,7 @@ #include "common/option.h" -typedef enum FFLocalIpType +typedef enum __attribute__((__packed__)) FFLocalIpType { FF_LOCALIP_TYPE_NONE, FF_LOCALIP_TYPE_LOOP_BIT = 1 << 0, @@ -19,7 +19,9 @@ typedef enum FFLocalIpType FF_LOCALIP_TYPE_COMPACT_BIT = 1 << 10, FF_LOCALIP_TYPE_DEFAULT_ROUTE_ONLY_BIT = 1 << 11, FF_LOCALIP_TYPE_ALL_IPS_BIT = 1 << 12, + FF_LOCALIP_TYPE_FORCE_UNSIGNED = UINT16_MAX, } FFLocalIpType; +static_assert(sizeof(FFLocalIpType) == sizeof(uint16_t), ""); typedef struct FFLocalIpOptions { diff --git a/src/modules/memory/memory.c b/src/modules/memory/memory.c index 05f58a0e7..58b0aff7f 100644 --- a/src/modules/memory/memory.c +++ b/src/modules/memory/memory.c @@ -152,7 +152,7 @@ void ffInitMemoryOptions(FFMemoryOptions* options) ffGenerateMemoryJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs, ""); - options->percent = (FFColorRangeConfig) { 50, 80 }; + options->percent = (FFPercentageModuleConfig) { 50, 80 }; } void ffDestroyMemoryOptions(FFMemoryOptions* options) diff --git a/src/modules/memory/option.h b/src/modules/memory/option.h index 4936b252b..76fc9fd06 100644 --- a/src/modules/memory/option.h +++ b/src/modules/memory/option.h @@ -10,5 +10,5 @@ typedef struct FFMemoryOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; } FFMemoryOptions; diff --git a/src/modules/opengl/option.h b/src/modules/opengl/option.h index 8c9db6309..54fd466c9 100644 --- a/src/modules/opengl/option.h +++ b/src/modules/opengl/option.h @@ -4,7 +4,7 @@ #include "common/option.h" -typedef enum FFOpenGLLibrary +typedef enum __attribute__((__packed__)) FFOpenGLLibrary { FF_OPENGL_LIBRARY_AUTO, FF_OPENGL_LIBRARY_EGL, diff --git a/src/modules/packages/option.h b/src/modules/packages/option.h index ddb7d0f13..cab933592 100644 --- a/src/modules/packages/option.h +++ b/src/modules/packages/option.h @@ -4,7 +4,7 @@ #include "common/option.h" -typedef enum FFPackagesFlags +typedef enum __attribute__((__packed__)) FFPackagesFlags { FF_PACKAGES_FLAG_NONE = 0, FF_PACKAGES_FLAG_APK_BIT = 1 << 0, @@ -35,7 +35,9 @@ typedef enum FFPackagesFlags FF_PACKAGES_FLAG_PACSTALL_BIT = 1 << 25, FF_PACKAGES_FLAG_MPORT_BIT = 1 << 26, FF_PACKAGES_FLAG_QI_BIT = 1 << 27, + FF_PACKAGES_FLAG_FORCE_UNSIGNED = UINT32_MAX, } FFPackagesFlags; +static_assert(sizeof(FFPackagesFlags) == sizeof(uint32_t), ""); typedef struct FFPackagesOptions { diff --git a/src/modules/sound/option.h b/src/modules/sound/option.h index ad659a557..7ec2c1614 100644 --- a/src/modules/sound/option.h +++ b/src/modules/sound/option.h @@ -5,7 +5,7 @@ #include "common/option.h" #include "common/percent.h" -typedef enum FFSoundType +typedef enum __attribute__((__packed__)) FFSoundType { FF_SOUND_TYPE_MAIN, FF_SOUND_TYPE_ACTIVE, @@ -18,5 +18,5 @@ typedef struct FFSoundOptions FFModuleArgs moduleArgs; FFSoundType soundType; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; } FFSoundOptions; diff --git a/src/modules/sound/sound.c b/src/modules/sound/sound.c index 3d24b2be6..ad78fa320 100644 --- a/src/modules/sound/sound.c +++ b/src/modules/sound/sound.c @@ -253,7 +253,7 @@ void ffInitSoundOptions(FFSoundOptions* options) ffOptionInitModuleArg(&options->moduleArgs, ""); options->soundType = FF_SOUND_TYPE_MAIN; - options->percent = (FFColorRangeConfig) { 80, 90 }; + options->percent = (FFPercentageModuleConfig) { 80, 90 }; } void ffDestroySoundOptions(FFSoundOptions* options) diff --git a/src/modules/swap/option.h b/src/modules/swap/option.h index 1c96ce41f..d6e7965ad 100644 --- a/src/modules/swap/option.h +++ b/src/modules/swap/option.h @@ -10,5 +10,5 @@ typedef struct FFSwapOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; } FFSwapOptions; diff --git a/src/modules/swap/swap.c b/src/modules/swap/swap.c index 210351631..235e7b9f7 100644 --- a/src/modules/swap/swap.c +++ b/src/modules/swap/swap.c @@ -161,7 +161,7 @@ void ffInitSwapOptions(FFSwapOptions* options) ffGenerateSwapJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs, "󰓡"); - options->percent = (FFColorRangeConfig) { 50, 80 }; + options->percent = (FFPercentageModuleConfig) { 50, 80 }; } void ffDestroySwapOptions(FFSwapOptions* options) diff --git a/src/modules/wifi/option.h b/src/modules/wifi/option.h index 305a95a47..3628df69d 100644 --- a/src/modules/wifi/option.h +++ b/src/modules/wifi/option.h @@ -9,5 +9,5 @@ typedef struct FFWifiOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; } FFWifiOptions; diff --git a/src/modules/wifi/wifi.c b/src/modules/wifi/wifi.c index d000c7e6b..a65de1168 100644 --- a/src/modules/wifi/wifi.c +++ b/src/modules/wifi/wifi.c @@ -222,7 +222,7 @@ void ffInitWifiOptions(FFWifiOptions* options) ); ffOptionInitModuleArg(&options->moduleArgs, ""); - options->percent = (FFColorRangeConfig) { 50, 20 }; + options->percent = (FFPercentageModuleConfig) { 50, 20 }; } void ffDestroyWifiOptions(FFWifiOptions* options) diff --git a/src/modules/zpool/option.h b/src/modules/zpool/option.h index 3143cf91b..ac4f8ff3f 100644 --- a/src/modules/zpool/option.h +++ b/src/modules/zpool/option.h @@ -10,5 +10,5 @@ typedef struct FFZpoolOptions FFModuleBaseInfo moduleInfo; FFModuleArgs moduleArgs; - FFColorRangeConfig percent; + FFPercentageModuleConfig percent; } FFZpoolOptions; diff --git a/src/modules/zpool/zpool.c b/src/modules/zpool/zpool.c index 719d411bf..41cec9a23 100644 --- a/src/modules/zpool/zpool.c +++ b/src/modules/zpool/zpool.c @@ -205,7 +205,7 @@ void ffInitZpoolOptions(FFZpoolOptions* options) ffGenerateZpoolJsonConfig ); ffOptionInitModuleArg(&options->moduleArgs, "󱑛"); - options->percent = (FFColorRangeConfig) { 50, 80 }; + options->percent = (FFPercentageModuleConfig) { 50, 80 }; } void ffDestroyZpoolOptions(FFZpoolOptions* options) diff --git a/src/options/display.h b/src/options/display.h index fe1f0ba5d..47aaed0d6 100644 --- a/src/options/display.h +++ b/src/options/display.h @@ -2,14 +2,14 @@ #include "util/FFstrbuf.h" -typedef enum FFSizeBinaryPrefixType +typedef enum __attribute__((__packed__)) FFSizeBinaryPrefixType { FF_SIZE_BINARY_PREFIX_TYPE_IEC, // 1024 Bytes = 1 KiB, 1024 KiB = 1 MiB, ... (standard) FF_SIZE_BINARY_PREFIX_TYPE_SI, // 1000 Bytes = 1 KB, 1000 KB = 1 MB, ... FF_SIZE_BINARY_PREFIX_TYPE_JEDEC, // 1024 Bytes = 1 kB, 1024 kB = 1 MB, ... } FFSizeBinaryPrefixType; -typedef enum FFTemperatureUnit +typedef enum __attribute__((__packed__)) FFTemperatureUnit { FF_TEMPERATURE_UNIT_CELSIUS, FF_TEMPERATURE_UNIT_FAHRENHEIT, @@ -46,7 +46,7 @@ typedef struct FFOptionsDisplay FFstrbuf barBorderLeft; FFstrbuf barBorderRight; uint8_t barWidth; - uint8_t percentType; + FFPercentageTypeFlags percentType; uint8_t percentNdigits; FFstrbuf percentColorGreen; FFstrbuf percentColorYellow; diff --git a/src/options/general.h b/src/options/general.h index f1f0f3ff8..8cb0d4884 100644 --- a/src/options/general.h +++ b/src/options/general.h @@ -2,7 +2,7 @@ #include "util/FFstrbuf.h" -typedef enum FFDsForceDrmType +typedef enum __attribute__((__packed__)) FFDsForceDrmType { FF_DS_FORCE_DRM_TYPE_FALSE = 0, // Disable FF_DS_FORCE_DRM_TYPE_TRUE = 1, // Try `libdrm`, then `sysfs` if libdrm failed diff --git a/src/options/logo.h b/src/options/logo.h index ab22843b9..a4a031d5f 100644 --- a/src/options/logo.h +++ b/src/options/logo.h @@ -5,7 +5,7 @@ #define FASTFETCH_LOGO_MAX_NAMES 9 #define FASTFETCH_LOGO_MAX_COLORS 9 //two digits would make parsing much more complicated (index 1 - 9) -typedef enum FFLogoType +typedef enum __attribute__((__packed__)) FFLogoType { FF_LOGO_TYPE_AUTO, //if something is given, first try builtin, then file. Otherwise detect logo FF_LOGO_TYPE_BUILTIN, //builtin ascii art @@ -23,7 +23,7 @@ typedef enum FFLogoType FF_LOGO_TYPE_NONE, //--logo none } FFLogoType; -typedef enum FFLogoPosition +typedef enum __attribute__((__packed__)) FFLogoPosition { FF_LOGO_POSITION_LEFT, FF_LOGO_POSITION_TOP,