mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
OpenCL: add JSON config support
This commit is contained in:
+1
-1
@@ -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
|
||||
|
||||
+2
-2
@@ -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);
|
||||
|
||||
+3
-3
@@ -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)
|
||||
|
||||
+1
-2
@@ -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
|
||||
|
||||
+1
-1
@@ -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);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -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
|
||||
@@ -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;
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user