mirror of
https://github.com/fastfetch-cli/fastfetch.git
synced 2026-10-30 00:37:23 +01:00
WM: add JSON config support
This commit is contained in:
@@ -140,6 +140,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_WM_MODULE_NAME, ffParseWMJsonObject) ||
|
||||
tryModule(instance, type, module, FF_WIFI_MODULE_NAME, ffParseWifiJsonObject) ||
|
||||
tryModule(instance, type, module, FF_WMTHEME_MODULE_NAME, ffParseWMThemeJsonObject) ||
|
||||
false;
|
||||
|
||||
@@ -41,4 +41,5 @@
|
||||
#include "modules/uptime/uptime.h"
|
||||
#include "modules/wallpaper/wallpaper.h"
|
||||
#include "modules/wifi/wifi.h"
|
||||
#include "modules/wm/wm.h"
|
||||
#include "modules/wmtheme/wmtheme.h"
|
||||
|
||||
@@ -38,4 +38,5 @@
|
||||
#include "modules/uptime/option.h"
|
||||
#include "modules/wallpaper/option.h"
|
||||
#include "modules/wifi/option.h"
|
||||
#include "modules/wm/option.h"
|
||||
#include "modules/wmtheme/option.h"
|
||||
|
||||
@@ -1,46 +0,0 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/displayserver/displayserver.h"
|
||||
|
||||
#define FF_WM_MODULE_NAME "WM"
|
||||
#define FF_WM_NUM_FORMAT_ARGS 3
|
||||
|
||||
void ffPrintWM(FFinstance* instance)
|
||||
{
|
||||
#ifdef __ANDROID__
|
||||
ffPrintError(instance, FF_WM_MODULE_NAME, 0, &instance->config.wm, "WM detection is not supported on Android");
|
||||
return;
|
||||
#endif
|
||||
|
||||
const FFDisplayServerResult* result = ffConnectDisplayServer(instance);
|
||||
|
||||
if(result->wmPrettyName.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_WM_MODULE_NAME, 0, &instance->config.wm, "No WM found");
|
||||
return;
|
||||
}
|
||||
|
||||
if(instance->config.wm.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_WM_MODULE_NAME, 0, &instance->config.wm.key);
|
||||
|
||||
ffStrbufWriteTo(&result->wmPrettyName, stdout);
|
||||
|
||||
if(result->wmProtocolName.length > 0)
|
||||
{
|
||||
fputs(" (", stdout);
|
||||
ffStrbufWriteTo(&result->wmProtocolName, stdout);
|
||||
putchar(')');
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_WM_MODULE_NAME, 0, &instance->config.wm, FF_WM_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProcessName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmPrettyName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProtocolName}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -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 FFWMOptions
|
||||
{
|
||||
const char* moduleName;
|
||||
FFModuleArgs moduleArgs;
|
||||
} FFWMOptions;
|
||||
@@ -0,0 +1,83 @@
|
||||
#include "fastfetch.h"
|
||||
#include "common/printing.h"
|
||||
#include "detection/displayserver/displayserver.h"
|
||||
#include "modules/wm/wm.h"
|
||||
|
||||
#define FF_WM_NUM_FORMAT_ARGS 3
|
||||
|
||||
void ffPrintWM(FFinstance* instance, FFWMOptions* options)
|
||||
{
|
||||
const FFDisplayServerResult* result = ffConnectDisplayServer(instance);
|
||||
|
||||
if(result->wmPrettyName.length == 0)
|
||||
{
|
||||
ffPrintError(instance, FF_WM_MODULE_NAME, 0, &options->moduleArgs, "No WM found");
|
||||
return;
|
||||
}
|
||||
|
||||
if(options->moduleArgs.outputFormat.length == 0)
|
||||
{
|
||||
ffPrintLogoAndKey(instance, FF_WM_MODULE_NAME, 0, &options->moduleArgs.key);
|
||||
|
||||
ffStrbufWriteTo(&result->wmPrettyName, stdout);
|
||||
|
||||
if(result->wmProtocolName.length > 0)
|
||||
{
|
||||
fputs(" (", stdout);
|
||||
ffStrbufWriteTo(&result->wmProtocolName, stdout);
|
||||
putchar(')');
|
||||
}
|
||||
|
||||
putchar('\n');
|
||||
}
|
||||
else
|
||||
{
|
||||
ffPrintFormat(instance, FF_WM_MODULE_NAME, 0, &options->moduleArgs, FF_WM_NUM_FORMAT_ARGS, (FFformatarg[]){
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProcessName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmPrettyName},
|
||||
{FF_FORMAT_ARG_TYPE_STRBUF, &result->wmProtocolName}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
void ffInitWMOptions(FFWMOptions* options)
|
||||
{
|
||||
options->moduleName = FF_WM_MODULE_NAME;
|
||||
ffOptionInitModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
bool ffParseWMCommandOptions(FFWMOptions* options, const char* key, const char* value)
|
||||
{
|
||||
const char* subKey = ffOptionTestPrefix(key, FF_WM_MODULE_NAME);
|
||||
if (!subKey) return false;
|
||||
if (ffOptionParseModuleArgs(key, subKey, value, &options->moduleArgs))
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void ffDestroyWMOptions(FFWMOptions* options)
|
||||
{
|
||||
ffOptionDestroyModuleArg(&options->moduleArgs);
|
||||
}
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
void ffParseWMJsonObject(FFinstance* instance, json_object* module)
|
||||
{
|
||||
FFWMOptions __attribute__((__cleanup__(ffDestroyWMOptions))) options;
|
||||
ffInitWMOptions(&options);
|
||||
|
||||
if (module)
|
||||
{
|
||||
json_object_object_foreach(module, key, val)
|
||||
{
|
||||
if (ffJsonConfigParseModuleArgs(key, val, &options.moduleArgs))
|
||||
continue;
|
||||
|
||||
ffPrintError(instance, FF_WM_MODULE_NAME, 0, &options.moduleArgs, "Unknown JSON key %s", key);
|
||||
}
|
||||
}
|
||||
|
||||
ffPrintWM(instance, &options);
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,15 @@
|
||||
#pragma once
|
||||
|
||||
#include "fastfetch.h"
|
||||
|
||||
#define FF_WM_MODULE_NAME "WM"
|
||||
|
||||
void ffPrintWM(FFinstance* instance, FFWMOptions* options);
|
||||
void ffInitWMOptions(FFWMOptions* options);
|
||||
bool ffParseWMCommandOptions(FFWMOptions* options, const char* key, const char* value);
|
||||
void ffDestroyWMOptions(FFWMOptions* options);
|
||||
|
||||
#ifdef FF_HAVE_JSONC
|
||||
#include "common/jsonconfig.h"
|
||||
void ffParseWMJsonObject(FFinstance* instance, json_object* module);
|
||||
#endif
|
||||
Reference in New Issue
Block a user