mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:14:37 +02:00
Wallpaper: add JSON config support
This commit is contained in:
+1
-1
@@ -308,7 +308,7 @@ set(LIBFASTFETCH_SRC
|
||||
src/modules/uptime/uptime.c
|
||||
src/modules/users.c
|
||||
src/modules/vulkan.c
|
||||
src/modules/wallpaper.c
|
||||
src/modules/wallpaper/wallpaper.c
|
||||
src/modules/weather.c
|
||||
src/modules/wifi/wifi.c
|
||||
src/modules/wm.c
|
||||
|
||||
+2
-2
@@ -98,7 +98,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
initModuleArg(&instance->config.media);
|
||||
ffInitDateTimeOptions(&instance->config.dateTime);
|
||||
initModuleArg(&instance->config.vulkan);
|
||||
initModuleArg(&instance->config.wallpaper);
|
||||
ffInitWallpaperOptions(&instance->config.wallpaper);
|
||||
initModuleArg(&instance->config.openGL);
|
||||
initModuleArg(&instance->config.openCL);
|
||||
initModuleArg(&instance->config.users);
|
||||
@@ -311,7 +311,7 @@ static void destroyConfig(FFinstance* instance)
|
||||
ffDestroyLocaleOptions(&instance->config.locale);
|
||||
ffDestroyLocalIpOptions(&instance->config.localIP);
|
||||
destroyModuleArg(&instance->config.publicIP);
|
||||
destroyModuleArg(&instance->config.wallpaper);
|
||||
ffDestroyWallpaperOptions(&instance->config.wallpaper);
|
||||
destroyModuleArg(&instance->config.weather);
|
||||
ffDestroyWifiOptions(&instance->config.wifi);
|
||||
destroyModuleArg(&instance->config.player);
|
||||
|
||||
+3
-3
@@ -994,7 +994,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
else if(ffParseWMThemeCommandOptions(&instance->config.wmTheme, key, value)) {}
|
||||
else if(optionParseModuleArgs(key, value, "theme", &instance->config.theme)) {}
|
||||
else if(ffParseIconsCommandOptions(&instance->config.icons, key, value)) {}
|
||||
else if(optionParseModuleArgs(key, value, "wallpaper", &instance->config.wallpaper)) {}
|
||||
else if(ffParseWallpaperCommandOptions(&instance->config.wallpaper, key, value)) {}
|
||||
else if(ffParseFontCommandOptions(&instance->config.font, key, value)) {}
|
||||
else if(ffParseCursorCommandOptions(&instance->config.cursor, key, value)) {}
|
||||
else if(ffParseTerminalCommandOptions(&instance->config.terminal, key, value)) {}
|
||||
@@ -1202,8 +1202,8 @@ static void parseStructureCommand(FFinstance* instance, const char* line)
|
||||
ffPrintWMTheme(instance, &instance->config.wmTheme);
|
||||
else if(strcasecmp(line, FF_ICONS_MODULE_NAME) == 0)
|
||||
ffPrintIcons(instance, &instance->config.icons);
|
||||
else if(strcasecmp(line, "wallpaper") == 0)
|
||||
ffPrintWallpaper(instance);
|
||||
else if(strcasecmp(line, FF_WALLPAPER_MODULE_NAME) == 0)
|
||||
ffPrintWallpaper(instance, &instance->config.wallpaper);
|
||||
else if(strcasecmp(line, FF_FONT_MODULE_NAME) == 0)
|
||||
ffPrintFont(instance, &instance->config.font);
|
||||
else if(strcasecmp(line, FF_CURSOR_MODULE_NAME) == 0)
|
||||
|
||||
+1
-2
@@ -71,7 +71,7 @@ typedef struct FFconfig
|
||||
FFShellOptions shell;
|
||||
FFDisplayOptions display;
|
||||
FFModuleArgs de;
|
||||
FFModuleArgs wallpaper;
|
||||
FFWallpaperOptions wallpaper;
|
||||
FFWifiOptions wifi;
|
||||
FFModuleArgs wm;
|
||||
FFWMThemeOptions wmTheme;
|
||||
@@ -201,7 +201,6 @@ void ffPrintProcesses(FFinstance* instance);
|
||||
void ffPrintDesktopEnvironment(FFinstance* instance);
|
||||
void ffPrintWM(FFinstance* instance);
|
||||
void ffPrintTheme(FFinstance* instance);
|
||||
void ffPrintWallpaper(FFinstance* instance);
|
||||
void ffPrintPlayer(FFinstance* instance);
|
||||
void ffPrintMedia(FFinstance* instance);
|
||||
void ffPrintPublicIp(FFinstance* instance);
|
||||
|
||||
@@ -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