diff --git a/CMakeLists.txt b/CMakeLists.txt index 41a6aa113..47e2fd6af 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,7 +287,7 @@ set(LIBFASTFETCH_SRC src/modules/locale/locale.c src/modules/localip/localip.c src/modules/memory/memory.c - src/modules/opencl.c + src/modules/opencl/opencl.c src/modules/opengl/opengl.c src/modules/os/os.c src/modules/packages/packages.c diff --git a/src/common/init.c b/src/common/init.c index a96984042..c5e9fbf60 100644 --- a/src/common/init.c +++ b/src/common/init.c @@ -99,7 +99,7 @@ static void defaultConfig(FFinstance* instance) initModuleArg(&instance->config.vulkan); ffInitWallpaperOptions(&instance->config.wallpaper); ffInitOpenGLOptions(&instance->config.openGL); - initModuleArg(&instance->config.openCL); + ffInitOpenCLOptions(&instance->config.openCL); initModuleArg(&instance->config.users); ffInitBluetoothOptions(&instance->config.bluetooth); ffInitSoundOptions(&instance->config.sound); @@ -318,7 +318,7 @@ static void destroyConfig(FFinstance* instance) ffDestroyDateTimeOptions(&instance->config.dateTime); destroyModuleArg(&instance->config.vulkan); ffDestroyOpenGLOptions(&instance->config.openGL); - destroyModuleArg(&instance->config.openCL); + ffDestroyOpenCLOptions(&instance->config.openCL); destroyModuleArg(&instance->config.users); ffDestroyBluetoothOptions(&instance->config.bluetooth); ffDestroySeparatorOptions(&instance->config.separator); diff --git a/src/fastfetch.c b/src/fastfetch.c index 1ae686a41..d7fb796a8 100644 --- a/src/fastfetch.c +++ b/src/fastfetch.c @@ -1016,7 +1016,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con else if(ffParseDateTimeCommandOptions(&instance->config.dateTime, key, value)) {} else if(optionParseModuleArgs(key, value, "vulkan", &instance->config.vulkan)) {} else if(ffParseOpenGLCommandOptions(&instance->config.openGL, key, value)) {} - else if(optionParseModuleArgs(key, value, "opencl", &instance->config.openCL)) {} + else if(ffParseOpenCLCommandOptions(&instance->config.openCL, key, value)) {} else if(optionParseModuleArgs(key, value, "users", &instance->config.users)) {} else if(ffParseBluetoothCommandOptions(&instance->config.bluetooth, key, value)) {} else if(ffParseSeparatorCommandOptions(&instance->config.separator, key, value)) {} @@ -1242,8 +1242,8 @@ static void parseStructureCommand(FFinstance* instance, const char* line) ffPrintVulkan(instance); else if(strcasecmp(line, FF_OPENGL_MODULE_NAME) == 0) ffPrintOpenGL(instance, &instance->config.openGL); - else if(strcasecmp(line, "opencl") == 0) - ffPrintOpenCL(instance); + else if(strcasecmp(line, FF_OPENCL_MODULE_NAME) == 0) + ffPrintOpenCL(instance, &instance->config.openCL); else if(strcasecmp(line, "users") == 0) ffPrintUsers(instance); else if(strcasecmp(line, FF_COMMAND_MODULE_NAME) == 0) diff --git a/src/fastfetch.h b/src/fastfetch.h index a7d9f90c6..50dcc11d9 100644 --- a/src/fastfetch.h +++ b/src/fastfetch.h @@ -90,7 +90,7 @@ typedef struct FFconfig FFDateTimeOptions dateTime; FFModuleArgs vulkan; FFOpenGLOptions openGL; - FFModuleArgs openCL; + FFOpenCLOptions openCL; FFModuleArgs users; FFBluetoothOptions bluetooth; FFSeparatorOptions separator; @@ -196,7 +196,6 @@ void ffPrintPublicIp(FFinstance* instance); void ffPrintWeather(FFinstance* instance); void ffPrintColors(FFinstance* instance); void ffPrintVulkan(FFinstance* instance); -void ffPrintOpenCL(FFinstance* instance); void ffPrintUsers(FFinstance* instance); #endif diff --git a/src/flashfetch.c b/src/flashfetch.c index bd876fb9c..74ebbeb53 100644 --- a/src/flashfetch.c +++ b/src/flashfetch.c @@ -62,7 +62,7 @@ int main(int argc, char** argv) //ffPrintTime(&instance); //ffPrintVulkan(&instance); //ffPrintOpenGL(&instance, &instance.config.openGL); - //ffPrintOpenCL(&instance); + //ffPrintOpenCL(&instance, &instance.config.openCL); //ffPrintUsers(&instance); //ffPrintWeather(&instance); //ffPrintBluetooth(&instance); diff --git a/src/modules/jsonconfig/jsonconfig.c b/src/modules/jsonconfig/jsonconfig.c index d6f4a6060..b3f24d48d 100644 --- a/src/modules/jsonconfig/jsonconfig.c +++ b/src/modules/jsonconfig/jsonconfig.c @@ -103,6 +103,7 @@ static bool parseModuleJsonObject(FFinstance* instance, const char* type, json_o case 'O': { return + tryModule(instance, type, module, FF_OPENCL_MODULE_NAME, ffParseOpenCLJsonObject) || tryModule(instance, type, module, FF_OPENGL_MODULE_NAME, ffParseOpenGLJsonObject) || tryModule(instance, type, module, FF_OS_MODULE_NAME, ffParseOSJsonObject) || false; diff --git a/src/modules/modules.h b/src/modules/modules.h index e05b959a2..990d190b2 100644 --- a/src/modules/modules.h +++ b/src/modules/modules.h @@ -28,6 +28,7 @@ #include "modules/localip/localip.h" #include "modules/memory/memory.h" #include "modules/opengl/opengl.h" +#include "modules/opencl/opencl.h" #include "modules/os/os.h" #include "modules/packages/packages.h" #include "modules/poweradapter/poweradapter.h" diff --git a/src/modules/opencl.c b/src/modules/opencl.c deleted file mode 100644 index c9d33b10d..000000000 --- a/src/modules/opencl.c +++ /dev/null @@ -1,39 +0,0 @@ -#include "fastfetch.h" -#include "common/printing.h" -#include "detection/opencl/opencl.h" - -#define FF_OPENCL_MODULE_NAME "OpenCL" -#define FF_OPENCL_NUM_FORMAT_ARGS 3 - -void ffPrintOpenCL(FFinstance* instance) -{ - FFOpenCLResult opencl; - ffStrbufInit(&opencl.version); - ffStrbufInit(&opencl.device); - ffStrbufInit(&opencl.vendor); - - const char* error = ffDetectOpenCL(instance, &opencl); - - if(error != NULL) - ffPrintError(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCL, "%s", error); - else - { - if(instance->config.openCL.outputFormat.length == 0) - { - ffPrintLogoAndKey(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCL.key); - ffStrbufPutTo(&opencl.version, stdout); - } - else - { - ffPrintFormat(instance, FF_OPENCL_MODULE_NAME, 0, &instance->config.openCL, FF_OPENCL_NUM_FORMAT_ARGS, (FFformatarg[]) { - {FF_FORMAT_ARG_TYPE_STRBUF, &opencl.version}, - {FF_FORMAT_ARG_TYPE_STRBUF, &opencl.device}, - {FF_FORMAT_ARG_TYPE_STRBUF, &opencl.vendor}, - }); - } - } - - ffStrbufDestroy(&opencl.version); - ffStrbufDestroy(&opencl.device); - ffStrbufDestroy(&opencl.vendor); -} diff --git a/src/modules/opencl/opencl.c b/src/modules/opencl/opencl.c new file mode 100644 index 000000000..169aaec7f --- /dev/null +++ b/src/modules/opencl/opencl.c @@ -0,0 +1,81 @@ +#include "fastfetch.h" +#include "common/printing.h" +#include "detection/opencl/opencl.h" +#include "modules/opencl/opencl.h" + +#define FF_OPENCL_NUM_FORMAT_ARGS 3 + +void ffPrintOpenCL(FFinstance* instance, FFOpenCLOptions* options) +{ + FFOpenCLResult opencl; + ffStrbufInit(&opencl.version); + ffStrbufInit(&opencl.device); + ffStrbufInit(&opencl.vendor); + + const char* error = ffDetectOpenCL(instance, &opencl); + + if(error != NULL) + ffPrintError(instance, FF_OPENCL_MODULE_NAME, 0, &options->moduleArgs, "%s", error); + else + { + if(options->moduleArgs.outputFormat.length == 0) + { + ffPrintLogoAndKey(instance, FF_OPENCL_MODULE_NAME, 0, &options->moduleArgs.key); + ffStrbufPutTo(&opencl.version, stdout); + } + else + { + ffPrintFormat(instance, FF_OPENCL_MODULE_NAME, 0, &options->moduleArgs, FF_OPENCL_NUM_FORMAT_ARGS, (FFformatarg[]) { + {FF_FORMAT_ARG_TYPE_STRBUF, &opencl.version}, + {FF_FORMAT_ARG_TYPE_STRBUF, &opencl.device}, + {FF_FORMAT_ARG_TYPE_STRBUF, &opencl.vendor}, + }); + } + } + + ffStrbufDestroy(&opencl.version); + ffStrbufDestroy(&opencl.device); + ffStrbufDestroy(&opencl.vendor); +} + +void ffInitOpenCLOptions(FFOpenCLOptions* options) +{ + options->moduleName = FF_OPENCL_MODULE_NAME; + ffOptionInitModuleArg(&options->moduleArgs); +} + +bool ffParseOpenCLCommandOptions(FFOpenCLOptions* options, const char* key, const char* value) +{ + const char* subKey = ffOptionTestPrefix(key, FF_OPENCL_MODULE_NAME); + if (!subKey) return false; + if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs)) + return true; + + return false; +} + +void ffDestroyOpenCLOptions(FFOpenCLOptions* options) +{ + ffOptionDestroyModuleArg(&options->moduleArgs); +} + +#ifdef FF_HAVE_JSONC +void ffParseOpenCLJsonObject(FFinstance* instance, json_object* module) +{ + FFOpenCLOptions __attribute__((__cleanup__(ffDestroyOpenCLOptions))) options; + ffInitOpenCLOptions(&options); + + if (module) + { + json_object_object_foreach(module, key, val) + { + if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs)) + continue; + + ffPrintError(instance, FF_OPENCL_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key); + } + } + + ffPrintOpenCL(instance, &options); +} +#endif diff --git a/src/modules/opencl/opencl.h b/src/modules/opencl/opencl.h new file mode 100644 index 000000000..21843c41d --- /dev/null +++ b/src/modules/opencl/opencl.h @@ -0,0 +1,15 @@ +#pragma once + +#include "fastfetch.h" + +#define FF_OPENCL_MODULE_NAME "OpenCL" + +void ffPrintOpenCL(FFinstance* instance, FFOpenCLOptions* options); +void ffInitOpenCLOptions(FFOpenCLOptions* options); +bool ffParseOpenCLCommandOptions(FFOpenCLOptions* options, const char* key, const char* value); +void ffDestroyOpenCLOptions(FFOpenCLOptions* options); + +#ifdef FF_HAVE_JSONC +#include "common/jsonconfig.h" +void ffParseOpenCLJsonObject(FFinstance* instance, json_object* module); +#endif diff --git a/src/modules/opencl/option.h b/src/modules/opencl/option.h new file mode 100644 index 000000000..addac5245 --- /dev/null +++ b/src/modules/opencl/option.h @@ -0,0 +1,11 @@ +#pragma once + +// This file will be included in "fastfetch.h", do NOT put unnecessary things here + +#include "common/option.h" + +typedef struct FFOpenCLOptions +{ + const char* moduleName; + FFModuleArgs moduleArgs; +} FFOpenCLOptions; diff --git a/src/modules/options.h b/src/modules/options.h index fa40194dc..5a5d9fb4a 100644 --- a/src/modules/options.h +++ b/src/modules/options.h @@ -26,6 +26,7 @@ #include "modules/localip/option.h" #include "modules/memory/option.h" #include "modules/opengl/option.h" +#include "modules/opencl/option.h" #include "modules/os/option.h" #include "modules/packages/option.h" #include "modules/poweradapter/option.h"