NativeResolution: rename module to PhycialDisplay

This commit is contained in:
李通洲 2023-08-09 09:03:32 +08:00
parent 3acbe84570
commit bb0279bae1
No known key found for this signature in database
GPG Key ID: 269AD4F5325A22A3
17 changed files with 156 additions and 156 deletions

View File

@ -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

View File

@ -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;
}

View File

@ -1,10 +0,0 @@
#include "fastfetch.h"
typedef struct FFNativeResolutionResult
{
FFstrbuf name;
uint32_t width;
uint32_t height;
} FFNativeResolutionResult;
const char* ffDetectNativeResolution(FFlist* results);

View File

@ -1,6 +0,0 @@
#include "nativeresolution.h"
const char* ffDetectNativeResolution(FF_MAYBE_UNUSED FFlist* results)
{
return "Not supported on this platform";
}

View File

@ -0,0 +1,10 @@
#include "fastfetch.h"
typedef struct FFPhycialDisplayResult
{
FFstrbuf name;
uint32_t width;
uint32_t height;
} FFPhycialDisplayResult;
const char* ffDetectPhycialDisplay(FFlist* results);

View File

@ -1,4 +1,4 @@
#include "nativeresolution.h"
#include "phycialdisplay.h"
#include "common/io/io.h"
#include "util/edidHelper.h"
@ -6,7 +6,7 @@
#include <dirent.h>
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);

View File

@ -0,0 +1,6 @@
#include "phycialdisplay.h"
const char* ffDetectPhycialDisplay(FF_MAYBE_UNUSED FFlist* results)
{
return "Not supported on this platform";
}

View File

@ -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);

View File

@ -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))

View File

@ -110,7 +110,7 @@ typedef struct FFconfig
FFWeatherOptions weather;
FFPlayerOptions player;
FFMediaOptions media;
FFNativeResolutionOptions nativeResolution;
FFPhycialDisplayOptions nativeResolution;
FFDateTimeOptions dateTime;
FFVulkanOptions vulkan;
FFOpenGLOptions openGL;

View File

@ -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"

View File

@ -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);
}

View File

@ -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);

View File

@ -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"

View File

@ -4,8 +4,8 @@
#include "common/option.h"
typedef struct FFNativeResolutionOptions
typedef struct FFPhycialDisplayOptions
{
const char* moduleName;
FFModuleArgs moduleArgs;
} FFNativeResolutionOptions;
} FFPhycialDisplayOptions;

View File

@ -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);
}

View File

@ -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);