diff --git a/CMakeLists.txt b/CMakeLists.txt index ad8904a8a..4de34905b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -328,7 +328,7 @@ set(LIBFASTFETCH_SRC src/modules/locale/locale.c src/modules/localip/localip.c src/modules/memory/memory.c - src/modules/nativeresolution/nativeresolution.c + src/modules/phycialdisplay/phycialdisplay.c src/modules/opencl/opencl.c src/modules/opengl/opengl.c src/modules/os/os.c @@ -395,7 +395,7 @@ if(LINUX) src/detection/gamepad/gamepad_linux.c src/detection/media/media_linux.c src/detection/memory/memory_linux.c - src/detection/nativeresolution/nativeresolution_linux.c + src/detection/phycialdisplay/phycialdisplay_linux.c src/detection/opengl/opengl_linux.c src/detection/os/os_linux.c src/detection/packages/packages_linux.c @@ -441,7 +441,7 @@ elseif(ANDROID) src/detection/gamepad/gamepad_nosupport.c src/detection/media/media_nosupport.c src/detection/memory/memory_linux.c - src/detection/nativeresolution/nativeresolution_nosupport.c + src/detection/phycialdisplay/phycialdisplay_nosupport.c src/detection/opengl/opengl_linux.c src/detection/os/os_android.c src/detection/packages/packages_linux.c @@ -493,7 +493,7 @@ elseif(BSD) src/detection/gamepad/gamepad_bsd.c src/detection/media/media_linux.c src/detection/memory/memory_bsd.c - src/detection/nativeresolution/nativeresolution_nosupport.c + src/detection/phycialdisplay/phycialdisplay_nosupport.c src/detection/opengl/opengl_linux.c src/detection/os/os_linux.c src/detection/packages/packages_linux.c @@ -541,7 +541,7 @@ elseif(APPLE) src/detection/gamepad/gamepad_apple.c src/detection/media/media_apple.m src/detection/memory/memory_apple.c - src/detection/nativeresolution/nativeresolution_nosupport.c + src/detection/phycialdisplay/phycialdisplay_nosupport.c src/detection/opengl/opengl_apple.c src/detection/os/os_apple.m src/detection/packages/packages_apple.c @@ -588,7 +588,7 @@ elseif(WIN32) src/detection/gamepad/gamepad_windows.c src/detection/media/media_nosupport.c src/detection/memory/memory_windows.c - src/detection/nativeresolution/nativeresolution_windows.c + src/detection/phycialdisplay/phycialdisplay_windows.c src/detection/opengl/opengl_windows.c src/detection/os/os_windows.cpp src/detection/packages/packages_windows.c diff --git a/src/common/jsonconfig.c b/src/common/jsonconfig.c index 55ba7d6e0..5494b81b3 100644 --- a/src/common/jsonconfig.c +++ b/src/common/jsonconfig.c @@ -159,7 +159,7 @@ static bool parseModuleJsonObject(const char* type, yyjson_val* module) case 'N': { return - tryModule(type, module, FF_NATIVERESOLUTION_MODULE_NAME, ffParseNativeResolutionJsonObject) || + tryModule(type, module, FF_PHYCIALDISPLAY_MODULE_NAME, ffParsePhycialDisplayJsonObject) || false; } diff --git a/src/detection/nativeresolution/nativeresolution.h b/src/detection/nativeresolution/nativeresolution.h deleted file mode 100644 index aa07971c1..000000000 --- a/src/detection/nativeresolution/nativeresolution.h +++ /dev/null @@ -1,10 +0,0 @@ -#include "fastfetch.h" - -typedef struct FFNativeResolutionResult -{ - FFstrbuf name; - uint32_t width; - uint32_t height; -} FFNativeResolutionResult; - -const char* ffDetectNativeResolution(FFlist* results); diff --git a/src/detection/nativeresolution/nativeresolution_nosupport.c b/src/detection/nativeresolution/nativeresolution_nosupport.c deleted file mode 100644 index 6731a0dde..000000000 --- a/src/detection/nativeresolution/nativeresolution_nosupport.c +++ /dev/null @@ -1,6 +0,0 @@ -#include "nativeresolution.h" - -const char* ffDetectNativeResolution(FF_MAYBE_UNUSED FFlist* results) -{ - return "Not supported on this platform"; -} diff --git a/src/detection/phycialdisplay/phycialdisplay.h b/src/detection/phycialdisplay/phycialdisplay.h new file mode 100644 index 000000000..faa7a7172 --- /dev/null +++ b/src/detection/phycialdisplay/phycialdisplay.h @@ -0,0 +1,10 @@ +#include "fastfetch.h" + +typedef struct FFPhycialDisplayResult +{ + FFstrbuf name; + uint32_t width; + uint32_t height; +} FFPhycialDisplayResult; + +const char* ffDetectPhycialDisplay(FFlist* results); diff --git a/src/detection/nativeresolution/nativeresolution_linux.c b/src/detection/phycialdisplay/phycialdisplay_linux.c similarity index 85% rename from src/detection/nativeresolution/nativeresolution_linux.c rename to src/detection/phycialdisplay/phycialdisplay_linux.c index bb7e5a5e1..245f9e685 100644 --- a/src/detection/nativeresolution/nativeresolution_linux.c +++ b/src/detection/phycialdisplay/phycialdisplay_linux.c @@ -1,4 +1,4 @@ -#include "nativeresolution.h" +#include "phycialdisplay.h" #include "common/io/io.h" #include "util/edidHelper.h" @@ -6,7 +6,7 @@ #include -const char* ffDetectNativeResolution(FFlist* results) +const char* ffDetectPhycialDisplay(FFlist* results) { const char* drmDirPath = "/sys/class/drm/"; @@ -36,7 +36,7 @@ const char* ffDetectNativeResolution(FFlist* results) } uint32_t width, height; - ffEdidGetNativeResolution(edidData, &width, &height); + ffEdidGetPhycialDisplay(edidData, &width, &height); if (width != 0 && height != 0) { const char* plainName = entry->d_name; @@ -46,7 +46,7 @@ const char* ffDetectNativeResolution(FFlist* results) if (tmp) plainName = tmp + 1; } - FFNativeResolutionResult* display = (FFNativeResolutionResult*) ffListAdd(results); + FFPhycialDisplayResult* display = (FFPhycialDisplayResult*) ffListAdd(results); display->width = width; display->height = height; ffStrbufInitS(&display->name, plainName); diff --git a/src/detection/phycialdisplay/phycialdisplay_nosupport.c b/src/detection/phycialdisplay/phycialdisplay_nosupport.c new file mode 100644 index 000000000..5254f52c6 --- /dev/null +++ b/src/detection/phycialdisplay/phycialdisplay_nosupport.c @@ -0,0 +1,6 @@ +#include "phycialdisplay.h" + +const char* ffDetectPhycialDisplay(FF_MAYBE_UNUSED FFlist* results) +{ + return "Not supported on this platform"; +} diff --git a/src/detection/nativeresolution/nativeresolution_windows.c b/src/detection/phycialdisplay/phycialdisplay_windows.c similarity index 86% rename from src/detection/nativeresolution/nativeresolution_windows.c rename to src/detection/phycialdisplay/phycialdisplay_windows.c index e5b9a5d16..ad8161ce3 100644 --- a/src/detection/nativeresolution/nativeresolution_windows.c +++ b/src/detection/phycialdisplay/phycialdisplay_windows.c @@ -1,4 +1,4 @@ -#include "nativeresolution.h" +#include "phycialdisplay.h" #include "common/io/io.h" #include "util/edidHelper.h" @@ -16,7 +16,7 @@ static inline void wrapSetupDiDestroyDeviceInfoList(HDEVINFO* hdev) SetupDiDestroyDeviceInfoList(*hdev); } -const char* ffDetectNativeResolution(FFlist* results) +const char* ffDetectPhycialDisplay(FFlist* results) { //https://learn.microsoft.com/en-us/windows/win32/power/enumerating-battery-devices HDEVINFO hdev __attribute__((__cleanup__(wrapSetupDiDestroyDeviceInfoList))) = @@ -33,13 +33,13 @@ const char* ffDetectNativeResolution(FFlist* results) uint8_t edidData[256] = {}; if (!ffRegReadData(hKey, L"EDID", edidData, sizeof(edidData), NULL)) continue; uint32_t width, height; - ffEdidGetNativeResolution(edidData, &width, &height); + ffEdidGetPhycialDisplay(edidData, &width, &height); if (width == 0 || height == 0) continue; wchar_t wName[MAX_PATH] = {}; // MONITOR\BOE09F9 if (!SetupDiGetDeviceRegistryPropertyW(hdev, &did, SPDRP_HARDWAREID, NULL, (BYTE*) wName, sizeof(wName), NULL)) continue; - FFNativeResolutionResult* display = (FFNativeResolutionResult*) ffListAdd(results); + FFPhycialDisplayResult* display = (FFPhycialDisplayResult*) ffListAdd(results); display->width = width; display->height = height; ffStrbufInitWS(&display->name, wcschr(wName, L'\\') + 1); diff --git a/src/fastfetch.c b/src/fastfetch.c index 6f451ab84..b1de0d875 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1018,7 +1018,7 @@ static void parseOption(FFdata* data, const char* key, const char* value) else if(ffParseWeatherCommandOptions(&instance.config.weather, key, value)) {} else if(ffParsePlayerCommandOptions(&instance.config.player, key, value)) {} else if(ffParseMediaCommandOptions(&instance.config.media, key, value)) {} - else if(ffParseNativeResolutionCommandOptions(&instance.config.nativeResolution, key, value)) {} + else if(ffParsePhycialDisplayCommandOptions(&instance.config.nativeResolution, key, value)) {} else if(ffParseDateTimeCommandOptions(&instance.config.dateTime, key, value)) {} else if(ffParseVulkanCommandOptions(&instance.config.vulkan, key, value)) {} else if(ffParseOpenGLCommandOptions(&instance.config.openGL, key, value)) {} @@ -1252,8 +1252,8 @@ static void parseStructureCommand(const char* line, FFlist* customValues) ffPrintPlayer(&instance.config.player); else if(ffStrEqualsIgnCase(line, FF_MEDIA_MODULE_NAME)) ffPrintMedia(&instance.config.media); - else if(ffStrEqualsIgnCase(line, FF_NATIVERESOLUTION_MODULE_NAME)) - ffPrintNativeResolution(&instance.config.nativeResolution); + else if(ffStrEqualsIgnCase(line, FF_PHYCIALDISPLAY_MODULE_NAME)) + ffPrintPhycialDisplay(&instance.config.nativeResolution); else if(ffStrEqualsIgnCase(line, FF_DATETIME_MODULE_NAME)) ffPrintDateTime(&instance.config.dateTime); else if(ffStrEqualsIgnCase(line, FF_COLORS_MODULE_NAME)) diff --git a/src/fastfetch.h b/src/fastfetch.h index 09501bd5f..a4ffb6ff8 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -110,7 +110,7 @@ typedef struct FFconfig FFWeatherOptions weather; FFPlayerOptions player; FFMediaOptions media; - FFNativeResolutionOptions nativeResolution; + FFPhycialDisplayOptions nativeResolution; FFDateTimeOptions dateTime; FFVulkanOptions vulkan; FFOpenGLOptions openGL; diff --git a/src/modules/modules.h b/src/modules/modules.h index 70521efd0..532679faa 100644 --- a/src/modules/modules.h +++ b/src/modules/modules.h @@ -30,7 +30,7 @@ #include "modules/localip/localip.h" #include "modules/media/media.h" #include "modules/memory/memory.h" -#include "modules/nativeresolution/nativeresolution.h" +#include "modules/phycialdisplay/phycialdisplay.h" #include "modules/opengl/opengl.h" #include "modules/opencl/opencl.h" #include "modules/os/os.h" diff --git a/src/modules/nativeresolution/nativeresolution.c b/src/modules/nativeresolution/nativeresolution.c deleted file mode 100644 index bbdc25ab7..000000000 --- a/src/modules/nativeresolution/nativeresolution.c +++ /dev/null @@ -1,106 +0,0 @@ -#include "common/printing.h" -#include "common/jsonconfig.h" -#include "detection/nativeresolution/nativeresolution.h" -#include "modules/nativeresolution/nativeresolution.h" -#include "util/stringUtils.h" - -#define FF_NATIVERESOLUTION_DISPLAY_NAME "Native Resolution" -#define FF_NATIVERESOLUTION_NUM_FORMAT_ARGS 3 - -void ffPrintNativeResolution(FFNativeResolutionOptions* options) -{ - FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFNativeResolutionResult)); - - const char* error = ffDetectNativeResolution(&result); - - if(error) - { - ffPrintError(FF_NATIVERESOLUTION_DISPLAY_NAME, 0, &options->moduleArgs, "%s", error); - return; - } - - if(!result.length) - { - ffPrintError(FF_NATIVERESOLUTION_DISPLAY_NAME, 0, &options->moduleArgs, "No devices detected"); - return; - } - - uint8_t index = 0; - FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate(); - FF_LIST_FOR_EACH(FFNativeResolutionResult, display, result) - { - if(options->moduleArgs.outputFormat.length == 0) - { - ffStrbufClear(&key); - if(options->moduleArgs.key.length == 0) - { - ffStrbufAppendF(&key, "%s (%s)", FF_NATIVERESOLUTION_DISPLAY_NAME, display->name.chars); - } - else - { - ffParseFormatString(&key, &options->moduleArgs.key, 1, (FFformatarg[]){ - {FF_FORMAT_ARG_TYPE_STRBUF, &display->name}, - }); - } - ffPrintLogoAndKey(key.chars, 0, NULL, &options->moduleArgs.keyColor); - - printf("%ux%u", display->width, display->height); - } - else - { - ffPrintFormat(FF_NATIVERESOLUTION_DISPLAY_NAME, index, &options->moduleArgs, FF_NATIVERESOLUTION_NUM_FORMAT_ARGS, (FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &display->name}, - {FF_FORMAT_ARG_TYPE_UINT, &display->width}, - {FF_FORMAT_ARG_TYPE_UINT, &display->height}, - }); - } - - ffStrbufDestroy(&display->name); - } -} - -void ffInitNativeResolutionOptions(FFNativeResolutionOptions* options) -{ - options->moduleName = FF_NATIVERESOLUTION_MODULE_NAME; - ffOptionInitModuleArg(&options->moduleArgs); -} - -bool ffParseNativeResolutionCommandOptions(FFNativeResolutionOptions* options, const char* key, const char* value) -{ - const char* subKey = ffOptionTestPrefix(key, FF_NATIVERESOLUTION_MODULE_NAME); - if (!subKey) return false; - if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) - return true; - - return false; -} - -void ffDestroyNativeResolutionOptions(FFNativeResolutionOptions* options) -{ - ffOptionDestroyModuleArg(&options->moduleArgs); -} - -void ffParseNativeResolutionJsonObject(yyjson_val* module) -{ - FFNativeResolutionOptions __attribute__((__cleanup__(ffDestroyNativeResolutionOptions))) options; - ffInitNativeResolutionOptions(&options); - - if (module) - { - yyjson_val *key_, *val; - size_t idx, max; - yyjson_obj_foreach(module, idx, max, key_, val) - { - const char* key = yyjson_get_str(key_); - if(ffStrEqualsIgnCase(key, "type")) - continue; - - if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) - continue; - - ffPrintError(FF_NATIVERESOLUTION_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key); - } - } - - ffPrintNativeResolution(&options); -} diff --git a/src/modules/nativeresolution/nativeresolution.h b/src/modules/nativeresolution/nativeresolution.h deleted file mode 100644 index e7d065394..000000000 --- a/src/modules/nativeresolution/nativeresolution.h +++ /dev/null @@ -1,11 +0,0 @@ -#pragma once - -#include "fastfetch.h" - -#define FF_NATIVERESOLUTION_MODULE_NAME "NativeResolution" - -void ffPrintNativeResolution(FFNativeResolutionOptions* options); -void ffInitNativeResolutionOptions(FFNativeResolutionOptions* options); -bool ffParseNativeResolutionCommandOptions(FFNativeResolutionOptions* options, const char* key, const char* value); -void ffDestroyNativeResolutionOptions(FFNativeResolutionOptions* options); -void ffParseNativeResolutionJsonObject(yyjson_val* module); diff --git a/src/modules/options.h b/src/modules/options.h index c93103387..6f33a048a 100644 --- a/src/modules/options.h +++ b/src/modules/options.h @@ -29,7 +29,7 @@ #include "modules/localip/option.h" #include "modules/media/option.h" #include "modules/memory/option.h" -#include "modules/nativeresolution/option.h" +#include "modules/phycialdisplay/option.h" #include "modules/opengl/option.h" #include "modules/opencl/option.h" #include "modules/os/option.h" diff --git a/src/modules/nativeresolution/option.h b/src/modules/phycialdisplay/option.h similarity index 72% rename from src/modules/nativeresolution/option.h rename to src/modules/phycialdisplay/option.h index 7c5f6fdd7..2f16f55a7 100644 --- a/src/modules/nativeresolution/option.h +++ b/src/modules/phycialdisplay/option.h @@ -4,8 +4,8 @@ #include "common/option.h" -typedef struct FFNativeResolutionOptions +typedef struct FFPhycialDisplayOptions { const char* moduleName; FFModuleArgs moduleArgs; -} FFNativeResolutionOptions; +} FFPhycialDisplayOptions; diff --git a/src/modules/phycialdisplay/phycialdisplay.c b/src/modules/phycialdisplay/phycialdisplay.c new file mode 100644 index 000000000..9a14c8a44 --- /dev/null +++ b/src/modules/phycialdisplay/phycialdisplay.c @@ -0,0 +1,106 @@ +#include "common/printing.h" +#include "common/jsonconfig.h" +#include "detection/phycialdisplay/phycialdisplay.h" +#include "modules/phycialdisplay/phycialdisplay.h" +#include "util/stringUtils.h" + +#define FF_PHYCIALDISPLAY_DISPLAY_NAME "Phycial Display" +#define FF_PHYCIALDISPLAY_NUM_FORMAT_ARGS 3 + +void ffPrintPhycialDisplay(FFPhycialDisplayOptions* options) +{ + FF_LIST_AUTO_DESTROY result = ffListCreate(sizeof(FFPhycialDisplayResult)); + + const char* error = ffDetectPhycialDisplay(&result); + + if(error) + { + ffPrintError(FF_PHYCIALDISPLAY_DISPLAY_NAME, 0, &options->moduleArgs, "%s", error); + return; + } + + if(!result.length) + { + ffPrintError(FF_PHYCIALDISPLAY_DISPLAY_NAME, 0, &options->moduleArgs, "No phycial display detected"); + return; + } + + uint8_t index = 0; + FF_STRBUF_AUTO_DESTROY key = ffStrbufCreate(); + FF_LIST_FOR_EACH(FFPhycialDisplayResult, display, result) + { + if(options->moduleArgs.outputFormat.length == 0) + { + ffStrbufClear(&key); + if(options->moduleArgs.key.length == 0) + { + ffStrbufAppendF(&key, "%s (%s)", FF_PHYCIALDISPLAY_DISPLAY_NAME, display->name.chars); + } + else + { + ffParseFormatString(&key, &options->moduleArgs.key, 1, (FFformatarg[]){ + {FF_FORMAT_ARG_TYPE_STRBUF, &display->name}, + }); + } + ffPrintLogoAndKey(key.chars, 0, NULL, &options->moduleArgs.keyColor); + + printf("%ux%u\n", display->width, display->height); + } + else + { + ffPrintFormat(FF_PHYCIALDISPLAY_DISPLAY_NAME, index, &options->moduleArgs, FF_PHYCIALDISPLAY_NUM_FORMAT_ARGS, (FFformatarg[]) { + {FF_FORMAT_ARG_TYPE_STRBUF, &display->name}, + {FF_FORMAT_ARG_TYPE_UINT, &display->width}, + {FF_FORMAT_ARG_TYPE_UINT, &display->height}, + }); + } + + ffStrbufDestroy(&display->name); + } +} + +void ffInitPhycialDisplayOptions(FFPhycialDisplayOptions* options) +{ + options->moduleName = FF_PHYCIALDISPLAY_MODULE_NAME; + ffOptionInitModuleArg(&options->moduleArgs); +} + +bool ffParsePhycialDisplayCommandOptions(FFPhycialDisplayOptions* options, const char* key, const char* value) +{ + const char* subKey = ffOptionTestPrefix(key, FF_PHYCIALDISPLAY_MODULE_NAME); + if (!subKey) return false; + if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) + return true; + + return false; +} + +void ffDestroyPhycialDisplayOptions(FFPhycialDisplayOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} + +void ffParsePhycialDisplayJsonObject(yyjson_val* module) +{ + FFPhycialDisplayOptions __attribute__((__cleanup__(ffDestroyPhycialDisplayOptions))) options; + ffInitPhycialDisplayOptions(&options); + + if (module) + { + yyjson_val *key_, *val; + size_t idx, max; + yyjson_obj_foreach(module, idx, max, key_, val) + { + const char* key = yyjson_get_str(key_); + if(ffStrEqualsIgnCase(key, "type")) + continue; + + if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) + continue; + + ffPrintError(FF_PHYCIALDISPLAY_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key); + } + } + + ffPrintPhycialDisplay(&options); +} diff --git a/src/modules/phycialdisplay/phycialdisplay.h b/src/modules/phycialdisplay/phycialdisplay.h new file mode 100644 index 000000000..d65876643 --- /dev/null +++ b/src/modules/phycialdisplay/phycialdisplay.h @@ -0,0 +1,11 @@ +#pragma once + +#include "fastfetch.h" + +#define FF_PHYCIALDISPLAY_MODULE_NAME "PhycialDisplay" + +void ffPrintPhycialDisplay(FFPhycialDisplayOptions* options); +void ffInitPhycialDisplayOptions(FFPhycialDisplayOptions* options); +bool ffParsePhycialDisplayCommandOptions(FFPhycialDisplayOptions* options, const char* key, const char* value); +void ffDestroyPhycialDisplayOptions(FFPhycialDisplayOptions* options); +void ffParsePhycialDisplayJsonObject(yyjson_val* module);