mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-09-13 02:42:09 +02:00
WMTheme: add JSON config support
This commit is contained in:
+1
-1
@@ -312,7 +312,7 @@ set(LIBFASTFETCH_SRC
|
||||
src/modules/weather.c
|
||||
src/modules/wifi.c
|
||||
src/modules/wm.c
|
||||
src/modules/wmtheme.c
|
||||
src/modules/wmtheme/wmtheme.c
|
||||
src/modules/jsonconfig/jsonconfig.c
|
||||
src/util/FFlist.c
|
||||
src/util/FFstrbuf.c
|
||||
|
||||
+2
-2
@@ -74,7 +74,7 @@ static void defaultConfig(FFinstance* instance)
|
||||
ffInitDisplayOptions(&instance->config.display);
|
||||
initModuleArg(&instance->config.de);
|
||||
initModuleArg(&instance->config.wm);
|
||||
initModuleArg(&instance->config.wmTheme);
|
||||
ffInitWMThemeOptions(&instance->config.wmTheme);
|
||||
initModuleArg(&instance->config.theme);
|
||||
initModuleArg(&instance->config.icons);
|
||||
ffInitFontOptions(&instance->config.font);
|
||||
@@ -296,7 +296,7 @@ static void destroyConfig(FFinstance* instance)
|
||||
ffDestroyDisplayOptions(&instance->config.display);
|
||||
destroyModuleArg(&instance->config.de);
|
||||
destroyModuleArg(&instance->config.wm);
|
||||
destroyModuleArg(&instance->config.wmTheme);
|
||||
ffDestroyWMThemeOptions(&instance->config.wmTheme);
|
||||
destroyModuleArg(&instance->config.theme);
|
||||
destroyModuleArg(&instance->config.icons);
|
||||
ffDestroyFontOptions(&instance->config.font);
|
||||
|
||||
+3
-3
@@ -991,7 +991,7 @@ static void parseOption(FFinstance* instance, FFdata* data, const char* key, con
|
||||
else if(optionParseModuleArgs(key, value, "de", &instance->config.de)) {}
|
||||
else if(optionParseModuleArgs(key, value, "wifi", &instance->config.wifi)) {}
|
||||
else if(optionParseModuleArgs(key, value, "wm", &instance->config.wm)) {}
|
||||
else if(optionParseModuleArgs(key, value, "wm-theme", &instance->config.wmTheme)) {}
|
||||
else if(ffParseWMThemeCommandOptions(&instance->config.wmTheme, key, value)) {}
|
||||
else if(optionParseModuleArgs(key, value, "theme", &instance->config.theme)) {}
|
||||
else if(optionParseModuleArgs(key, value, "icons", &instance->config.icons)) {}
|
||||
else if(optionParseModuleArgs(key, value, "wallpaper", &instance->config.wallpaper)) {}
|
||||
@@ -1202,8 +1202,8 @@ static void parseStructureCommand(FFinstance* instance, const char* line)
|
||||
ffPrintWM(instance);
|
||||
else if(strcasecmp(line, "theme") == 0)
|
||||
ffPrintTheme(instance);
|
||||
else if(strcasecmp(line, "wmtheme") == 0)
|
||||
ffPrintWMTheme(instance);
|
||||
else if(strcasecmp(line, FF_WMTHEME_MODULE_NAME) == 0)
|
||||
ffPrintWMTheme(instance, &instance->config.wmTheme);
|
||||
else if(strcasecmp(line, "icons") == 0)
|
||||
ffPrintIcons(instance);
|
||||
else if(strcasecmp(line, "wallpaper") == 0)
|
||||
|
||||
+1
-2
@@ -74,7 +74,7 @@ typedef struct FFconfig
|
||||
FFModuleArgs wallpaper;
|
||||
FFModuleArgs wifi;
|
||||
FFModuleArgs wm;
|
||||
FFModuleArgs wmTheme;
|
||||
FFWMThemeOptions wmTheme;
|
||||
FFModuleArgs theme;
|
||||
FFModuleArgs icons;
|
||||
FFFontOptions font;
|
||||
@@ -205,7 +205,6 @@ void ffPrintPackages(FFinstance* instance);
|
||||
void ffPrintShell(FFinstance* instance);
|
||||
void ffPrintDesktopEnvironment(FFinstance* instance);
|
||||
void ffPrintWM(FFinstance* instance);
|
||||
void ffPrintWMTheme(FFinstance* instance);
|
||||
void ffPrintTheme(FFinstance* instance);
|
||||
void ffPrintIcons(FFinstance* instance);
|
||||
void ffPrintWallpaper(FFinstance* instance);
|
||||
|
||||
+1
-1
@@ -36,7 +36,7 @@ int main(int argc, char** argv)
|
||||
// ffPrintBrightness(&instance);
|
||||
ffPrintDesktopEnvironment(&instance);
|
||||
ffPrintWM(&instance);
|
||||
ffPrintWMTheme(&instance);
|
||||
ffPrintWMTheme(&instance, &instance.config.wmTheme);
|
||||
ffPrintTheme(&instance);
|
||||
ffPrintIcons(&instance);
|
||||
ffPrintFont(&instance, &instance.config.font);
|
||||
|
||||
@@ -113,6 +113,12 @@ static bool parseModuleJsonObject(FFinstance* instance, const char* type, json_o
|
||||
false;
|
||||
}
|
||||
|
||||
case 'W': {
|
||||
return
|
||||
tryModule(instance, type, module, FF_WMTHEME_MODULE_NAME, ffParseWMThemeJsonObject) ||
|
||||
false;
|
||||
}
|
||||
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -30,3 +30,4 @@
|
||||
#include "modules/title/title.h"
|
||||
#include "modules/jsonconfig/jsonconfig.h"
|
||||
#include "modules/uptime/uptime.h"
|
||||
#include "modules/wmtheme/wmtheme.h"
|
||||
|
||||
@@ -27,3 +27,4 @@
|
||||
#include "modules/sound/option.h"
|
||||
#include "modules/title/option.h"
|
||||
#include "modules/uptime/option.h"
|
||||
#include "modules/wmtheme/option.h"
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/wmtheme/wmtheme.h"
|
||||
|
||||
#define FF_WMTHEME_MODULE_NAME "WM Theme"
|
||||
#define FF_WMTHEME_NUM_FORMAT_ARGS 1
|
||||
|
||||
void ffPrintWMTheme(FFinstance* instance)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate();
|
||||
if(ffDetectWmTheme(instance, &themeOrError))
|
||||
{
|
||||
if(instance->config.wmTheme.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme.key);
|
||||
puts(themeOrError.chars);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, FF_WMTHEME_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &themeOrError}
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintError(instance, FF_WMTHEME_MODULE_NAME, 0, &instance->config.wmTheme, "%*s", themeOrError.length, themeOrError.chars);
|
||||
}
|
||||
}
|
||||
@@ -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 FFWMThemeOptions
|
||||
{
|
||||
const char* moduleName;
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFWMThemeOptions;
|
||||
@@ -0,0 +1,72 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/wmtheme/wmtheme.h"
|
||||
#include "modules/wmtheme/wmtheme.h"
|
||||
|
||||
#define FF_WMTHEME_DISPLAY_NAME "WM Theme"
|
||||
#define FF_WMTHEME_NUM_FORMAT_ARGS 1
|
||||
|
||||
void ffPrintWMTheme(FFinstance* instance, FFWMThemeOptions* options)
|
||||
{
|
||||
FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate();
|
||||
if(ffDetectWmTheme(instance, &themeOrError))
|
||||
{
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs.key);
|
||||
puts(themeOrError.chars);
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_WMTHEME_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &themeOrError}
|
||||
});
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintError(instance, FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, "%*s", themeOrError.length, themeOrError.chars);
|
||||
}
|
||||
}
|
||||
|
||||
void ffInitWMThemeOptions(FFWMThemeOptions* options)
|
||||
{
|
||||
options->moduleName = FF_WMTHEME_MODULE_NAME;
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
bool ffParseWMThemeCommandOptions(FFWMThemeOptions* options, const char* key, const char* value)
|
||||
{
|
||||
const char* subKey = ffOptionTestPrefix(key, FF_WMTHEME_MODULE_NAME);
|
||||
if (!subKey) return false;
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ffDestroyWMThemeOptions(FFWMThemeOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
void ffParseWMThemeJsonObject(FFinstance* instance, json_object* module)
|
||||
{
|
||||
FFWMThemeOptions __attribute__((__cleanup__(ffDestroyWMThemeOptions))) options;
|
||||
ffInitWMThemeOptions(&options);
|
||||
|
||||
if (module)
|
||||
{
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_WMTHEME_DISPLAY_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintWMTheme(instance, &options);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
#include "modules/wmtheme/option.h"
|
||||
|
||||
#define FF_WMTHEME_MODULE_NAME "WMTheme"
|
||||
|
||||
void ffPrintWMTheme(FFinstance* instance, FFWMThemeOptions* options);
|
||||
void ffInitWMThemeOptions(FFWMThemeOptions* options);
|
||||
bool ffParseWMThemeCommandOptions(FFWMThemeOptions* options, const char* key, const char* value);
|
||||
void ffDestroyWMThemeOptions(FFWMThemeOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/jsonconfig.h"
|
||||
void ffParseWMThemeJsonObject(FFinstance* instance, json_object* module);
|
||||
#endif
|
||||
Reference in New Issue
Block a user