mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
Vulkan: add JSON config support
This commit is contained in:
+1
-1
@@ -307,7 +307,7 @@ set(LIBFASTFETCH_SRC
|
||||
src/modules/title/title.c
|
||||
src/modules/uptime/uptime.c
|
||||
src/modules/users.c
|
||||
src/modules/vulkan.c
|
||||
src/modules/vulkan/vulkan.c
|
||||
src/modules/wallpaper/wallpaper.c
|
||||
src/modules/weather.c
|
||||
src/modules/wifi/wifi.c
|
||||
|
||||
+2
-2
@@ -96,7 +96,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
initModuleArg(&instance->config.player);
|
||||
initModuleArg(&instance->config.media);
|
||||
ffInitDateTimeOptions(&instance->config.dateTime);
|
||||
initModuleArg(&instance->config.vulkan);
|
||||
ffInitVulkanOptions(&instance->config.vulkan);
|
||||
ffInitWallpaperOptions(&instance->config.wallpaper);
|
||||
ffInitOpenGLOptions(&instance->config.openGL);
|
||||
ffInitOpenCLOptions(&instance->config.openCL);
|
||||
@@ -316,7 +316,7 @@ static void destroyConfig(FFinstance* instance)
|
||||
destroyModuleArg(&instance->config.player);
|
||||
destroyModuleArg(&instance->config.media);
|
||||
ffDestroyDateTimeOptions(&instance->config.dateTime);
|
||||
destroyModuleArg(&instance->config.vulkan);
|
||||
ffDestroyVulkanOptions(&instance->config.vulkan);
|
||||
ffDestroyOpenGLOptions(&instance->config.openGL);
|
||||
ffDestroyOpenCLOptions(&instance->config.openCL);
|
||||
destroyModuleArg(&instance->config.users);
|
||||
|
||||
+3
-3
@@ -1014,7 +1014,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
else if(optionParseModuleArgs(key, value, "player", &instance->config.player)) {}
|
||||
else if(optionParseModuleArgs(key, value, "media", &instance->config.media)) {}
|
||||
else if(ffParseDateTimeCommandOptions(&instance->config.dateTime, key, value)) {}
|
||||
else if(optionParseModuleArgs(key, value, "vulkan", &instance->config.vulkan)) {}
|
||||
else if(ffParseVulkanCommandOptions(&instance->config.vulkan, key, value)) {}
|
||||
else if(ffParseOpenGLCommandOptions(&instance->config.openGL, key, value)) {}
|
||||
else if(ffParseOpenCLCommandOptions(&instance->config.openCL, key, value)) {}
|
||||
else if(optionParseModuleArgs(key, value, "users", &instance->config.users)) {}
|
||||
@@ -1238,8 +1238,8 @@ static void parseStructureCommand(FFinstance* instance, const char* line)
|
||||
ffPrintDateTime(instance, &instance->config.dateTime);
|
||||
else if(strcasecmp(line, FF_COLORS_MODULE_NAME) == 0)
|
||||
ffPrintColors(instance);
|
||||
else if(strcasecmp(line, "vulkan") == 0)
|
||||
ffPrintVulkan(instance);
|
||||
else if(strcasecmp(line, FF_VULKAN_MODULE_NAME) == 0)
|
||||
ffPrintVulkan(instance, &instance->config.vulkan);
|
||||
else if(strcasecmp(line, FF_OPENGL_MODULE_NAME) == 0)
|
||||
ffPrintOpenGL(instance, &instance->config.openGL);
|
||||
else if(strcasecmp(line, FF_OPENCL_MODULE_NAME) == 0)
|
||||
|
||||
+1
-2
@@ -88,7 +88,7 @@ typedef struct FFconfig
|
||||
FFModuleArgs player;
|
||||
FFModuleArgs media;
|
||||
FFDateTimeOptions dateTime;
|
||||
FFModuleArgs vulkan;
|
||||
FFVulkanOptions vulkan;
|
||||
FFOpenGLOptions openGL;
|
||||
FFOpenCLOptions openCL;
|
||||
FFModuleArgs users;
|
||||
@@ -195,7 +195,6 @@ void ffPrintMedia(FFinstance* instance);
|
||||
void ffPrintPublicIp(FFinstance* instance);
|
||||
void ffPrintWeather(FFinstance* instance);
|
||||
void ffPrintColors(FFinstance* instance);
|
||||
void ffPrintVulkan(FFinstance* instance);
|
||||
void ffPrintUsers(FFinstance* instance);
|
||||
|
||||
#endif
|
||||
|
||||
+1
-1
@@ -60,7 +60,7 @@ int main(int argc, char** argv)
|
||||
//ffPrintDateTime(&instance);
|
||||
//ffPrintDate(&instance);
|
||||
//ffPrintTime(&instance);
|
||||
//ffPrintVulkan(&instance);
|
||||
//ffPrintVulkan(&instance, &instance.config.vulkan);
|
||||
//ffPrintOpenGL(&instance, &instance.config.openGL);
|
||||
//ffPrintOpenCL(&instance, &instance.config.openCL);
|
||||
//ffPrintUsers(&instance);
|
||||
|
||||
@@ -139,6 +139,12 @@ static bool parseModuleJsonObject(FFinstance* instance, const char* type, json_o
|
||||
false;
|
||||
}
|
||||
|
||||
case 'V': {
|
||||
return
|
||||
tryModule(instance, type, module, FF_VULKAN_MODULE_NAME, ffParseVulkanJsonObject) ||
|
||||
false;
|
||||
}
|
||||
|
||||
case 'W': {
|
||||
return
|
||||
tryModule(instance, type, module, FF_WALLPAPER_MODULE_NAME, ffParseWallpaperJsonObject) ||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "modules/title/title.h"
|
||||
#include "modules/jsonconfig/jsonconfig.h"
|
||||
#include "modules/uptime/uptime.h"
|
||||
#include "modules/vulkan/vulkan.h"
|
||||
#include "modules/wallpaper/wallpaper.h"
|
||||
#include "modules/wifi/wifi.h"
|
||||
#include "modules/wm/wm.h"
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "modules/terminalfont/option.h"
|
||||
#include "modules/title/option.h"
|
||||
#include "modules/uptime/option.h"
|
||||
#include "modules/vulkan/option.h"
|
||||
#include "modules/wallpaper/option.h"
|
||||
#include "modules/wifi/option.h"
|
||||
#include "modules/wm/option.h"
|
||||
|
||||
@@ -1,43 +0,0 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/vulkan/vulkan.h"
|
||||
|
||||
#define FF_VULKAN_MODULE_NAME "Vulkan"
|
||||
#define FF_VULKAN_NUM_FORMAT_ARGS 3
|
||||
|
||||
void ffPrintVulkan(FFinstance* instance)
|
||||
{
|
||||
const FFVulkanResult* vulkan = ffDetectVulkan(instance);
|
||||
|
||||
if(vulkan->error)
|
||||
{
|
||||
ffPrintError(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkan, "%s", vulkan->error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(instance->config.vulkan.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkan.key);
|
||||
|
||||
if(vulkan->apiVersion.length > 0)
|
||||
{
|
||||
ffStrbufWriteTo(&vulkan->apiVersion, stdout);
|
||||
|
||||
if(vulkan->driver.length > 0)
|
||||
fputs(" - ", stdout);
|
||||
}
|
||||
|
||||
if(vulkan->driver.length > 0)
|
||||
ffStrbufWriteTo(&vulkan->driver, stdout);
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_VULKAN_MODULE_NAME, 0, &instance->config.vulkan, FF_VULKAN_NUM_FORMAT_ARGS, (FFformatarg[]) {
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->driver},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->apiVersion},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->conformanceVersion}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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 FFVulkanOptions
|
||||
{
|
||||
const char* moduleName;
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFVulkanOptions;
|
||||
@@ -0,0 +1,85 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/vulkan/vulkan.h"
|
||||
#include "modules/vulkan/vulkan.h"
|
||||
|
||||
#define FF_VULKAN_NUM_FORMAT_ARGS 3
|
||||
|
||||
void ffPrintVulkan(FFinstance* instance, FFVulkanOptions* options)
|
||||
{
|
||||
const FFVulkanResult* vulkan = ffDetectVulkan(instance);
|
||||
|
||||
if(vulkan->error)
|
||||
{
|
||||
ffPrintError(instance, FF_VULKAN_MODULE_NAME, 0, &options->moduleArgs, "%s", vulkan->error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_VULKAN_MODULE_NAME, 0, &options->moduleArgs.key);
|
||||
|
||||
if(vulkan->apiVersion.length > 0)
|
||||
{
|
||||
ffStrbufWriteTo(&vulkan->apiVersion, stdout);
|
||||
|
||||
if(vulkan->driver.length > 0)
|
||||
fputs(" - ", stdout);
|
||||
}
|
||||
|
||||
if(vulkan->driver.length > 0)
|
||||
ffStrbufWriteTo(&vulkan->driver, stdout);
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_VULKAN_MODULE_NAME, 0, &options->moduleArgs, FF_VULKAN_NUM_FORMAT_ARGS, (FFformatarg[]) {
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->driver},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->apiVersion},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &vulkan->conformanceVersion}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ffInitVulkanOptions(FFVulkanOptions* options)
|
||||
{
|
||||
options->moduleName = FF_VULKAN_MODULE_NAME;
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
bool ffParseVulkanCommandOptions(FFVulkanOptions* options, const char* key, const char* value)
|
||||
{
|
||||
const char* subKey = ffOptionTestPrefix(key, FF_VULKAN_MODULE_NAME);
|
||||
if (!subKey) return false;
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ffDestroyVulkanOptions(FFVulkanOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
void ffParseVulkanJsonObject(FFinstance* instance, json_object* module)
|
||||
{
|
||||
FFVulkanOptions __attribute__((__cleanup__(ffDestroyVulkanOptions))) options;
|
||||
ffInitVulkanOptions(&options);
|
||||
|
||||
if (module)
|
||||
{
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_VULKAN_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintVulkan(instance, &options);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_VULKAN_MODULE_NAME "Vulkan"
|
||||
|
||||
void ffPrintVulkan(FFinstance* instance, FFVulkanOptions* options);
|
||||
void ffInitVulkanOptions(FFVulkanOptions* options);
|
||||
bool ffParseVulkanCommandOptions(FFVulkanOptions* options, const char* key, const char* value);
|
||||
void ffDestroyVulkanOptions(FFVulkanOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/jsonconfig.h"
|
||||
void ffParseVulkanJsonObject(FFinstance* instance, json_object* module);
|
||||
#endif
|
||||
Reference in New Issue
Block a user