From 804463a4708efd00bbf21e930a8d97481fd3e581 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Wed, 13 Sep 2023 14:22:04 +0800 Subject: [PATCH] WM: support JSON format --- src/modules/wm/wm.c | 17 ++++++++++++++++- src/modules/wm/wm.h | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/modules/wm/wm.c b/src/modules/wm/wm.c index 3c7f53295..371b48deb 100644 --- a/src/modules/wm/wm.c +++ b/src/modules/wm/wm.c @@ -43,7 +43,7 @@ void ffPrintWM(FFWMOptions* options) void ffInitWMOptions(FFWMOptions* options) { - ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WM_MODULE_NAME, ffParseWMCommandOptions, ffParseWMJsonObject, ffPrintWM, NULL); + ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WM_MODULE_NAME, ffParseWMCommandOptions, ffParseWMJsonObject, ffPrintWM, ffGenerateWMJson); ffOptionInitModuleArg(&options->moduleArgs); } @@ -78,3 +78,18 @@ void ffParseWMJsonObject(FFWMOptions* options, yyjson_val* module) ffPrintError(FF_WM_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key); } } + +void ffGenerateWMJson(FF_MAYBE_UNUSED FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) +{ + const FFDisplayServerResult* result = ffConnectDisplayServer(); + + if(result->wmPrettyName.length == 0) + { + yyjson_mut_obj_add_str(doc, module, "error", "No WM found"); + return; + } + yyjson_mut_val* obj = yyjson_mut_obj_add_obj(doc, module, "result"); + yyjson_mut_obj_add_strbuf(doc, obj, "processName", &result->wmProcessName); + yyjson_mut_obj_add_strbuf(doc, obj, "prettyName", &result->wmPrettyName); + yyjson_mut_obj_add_strbuf(doc, obj, "protocolName", &result->wmProtocolName); +} diff --git a/src/modules/wm/wm.h b/src/modules/wm/wm.h index 607732d72..fe960b688 100644 --- a/src/modules/wm/wm.h +++ b/src/modules/wm/wm.h @@ -9,3 +9,4 @@ void ffInitWMOptions(FFWMOptions* options); bool ffParseWMCommandOptions(FFWMOptions* options, const char* key, const char* value); void ffDestroyWMOptions(FFWMOptions* options); void ffParseWMJsonObject(FFWMOptions* options, yyjson_val* module); +void ffGenerateWMJson(FFWMOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module);