mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-29 16:26:39 +01:00
Wallpaper: add JSON config support
This commit is contained in:
@@ -138,6 +138,7 @@ static bool parseModuleJsonObject(FFinstance* instance, const char* type, json_o
|
||||
|
||||
case 'W': {
|
||||
return
|
||||
tryModule(instance, type, module, FF_WALLPAPER_MODULE_NAME, ffParseWallpaperJsonObject) ||
|
||||
tryModule(instance, type, module, FF_WIFI_MODULE_NAME, ffParseWifiJsonObject) ||
|
||||
tryModule(instance, type, module, FF_WMTHEME_MODULE_NAME, ffParseWMThemeJsonObject) ||
|
||||
false;
|
||||
|
||||
@@ -38,5 +38,6 @@
|
||||
#include "modules/title/title.h"
|
||||
#include "modules/jsonconfig/jsonconfig.h"
|
||||
#include "modules/uptime/uptime.h"
|
||||
#include "modules/wallpaper/wallpaper.h"
|
||||
#include "modules/wifi/wifi.h"
|
||||
#include "modules/wmtheme/wmtheme.h"
|
||||
|
||||
@@ -35,5 +35,6 @@
|
||||
#include "modules/terminalfont/option.h"
|
||||
#include "modules/title/option.h"
|
||||
#include "modules/uptime/option.h"
|
||||
#include "modules/wallpaper/option.h"
|
||||
#include "modules/wifi/option.h"
|
||||
#include "modules/wmtheme/option.h"
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/wallpaper/wallpaper.h"
|
||||
|
||||
#define FF_WALLPAPER_MODULE_NAME "Wallpaper"
|
||||
#define FF_WALLPAPER_NUM_FORMAT_ARGS 1
|
||||
|
||||
void ffPrintWallpaper(FFinstance* instance)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY wallpaper = ffStrbufCreate();
|
||||
const char* error = ffDetectWallpaper(instance, &wallpaper);
|
||||
|
||||
if(error)
|
||||
{
|
||||
ffPrintError(instance, FF_WALLPAPER_MODULE_NAME, 0, &instance->config.wallpaper, "%s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(instance->config.wallpaper.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_WALLPAPER_MODULE_NAME, 0, &instance->config.wallpaper.key);
|
||||
ffStrbufPutTo(&wallpaper, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_WALLPAPER_MODULE_NAME, 0, &instance->config.wallpaper, FF_WALLPAPER_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &wallpaper}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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 FFWallpaperOptions
|
||||
{
|
||||
const char* moduleName;
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFWallpaperOptions;
|
||||
@@ -0,0 +1,72 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/wallpaper/wallpaper.h"
|
||||
#include "modules/wallpaper/wallpaper.h"
|
||||
|
||||
#define FF_WALLPAPER_NUM_FORMAT_ARGS 1
|
||||
|
||||
void ffPrintWallpaper(FFinstance* instance, FFWallpaperOptions* options)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY wallpaper = ffStrbufCreate();
|
||||
const char* error = ffDetectWallpaper(instance, &wallpaper);
|
||||
|
||||
if(error)
|
||||
{
|
||||
ffPrintError(instance, FF_WALLPAPER_MODULE_NAME, 0, &options->moduleArgs, "%s", error);
|
||||
return;
|
||||
}
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_WALLPAPER_MODULE_NAME, 0, &options->moduleArgs.key);
|
||||
ffStrbufPutTo(&wallpaper, stdout);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_WALLPAPER_MODULE_NAME, 0, &options->moduleArgs, FF_WALLPAPER_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &wallpaper}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ffInitWallpaperOptions(FFWallpaperOptions* options)
|
||||
{
|
||||
options->moduleName = FF_WALLPAPER_MODULE_NAME;
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
bool ffParseWallpaperCommandOptions(FFWallpaperOptions* options, const char* key, const char* value)
|
||||
{
|
||||
const char* subKey = ffOptionTestPrefix(key, FF_WALLPAPER_MODULE_NAME);
|
||||
if (!subKey) return false;
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ffDestroyWallpaperOptions(FFWallpaperOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
void ffParseWallpaperJsonObject(FFinstance* instance, json_object* module)
|
||||
{
|
||||
FFWallpaperOptions __attribute__((__cleanup__(ffDestroyWallpaperOptions))) options;
|
||||
ffInitWallpaperOptions(&options);
|
||||
|
||||
if (module)
|
||||
{
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_WALLPAPER_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintWallpaper(instance, &options);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_WALLPAPER_MODULE_NAME "Wallpaper"
|
||||
|
||||
void ffPrintWallpaper(FFinstance* instance, FFWallpaperOptions* options);
|
||||
void ffInitWallpaperOptions(FFWallpaperOptions* options);
|
||||
bool ffParseWallpaperCommandOptions(FFWallpaperOptions* options, const char* key, const char* value);
|
||||
void ffDestroyWallpaperOptions(FFWallpaperOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/jsonconfig.h"
|
||||
void ffParseWallpaperJsonObject(FFinstance* instance, json_object* module);
|
||||
#endif
|
||||
Reference in New Issue
Block a user