2023-06-07 10:50:52 +08:00
|
|
|
#include "common/printing.h"
|
2023-06-10 15:01:54 +08:00
|
|
|
#include "common/jsonconfig.h"
|
2023-06-07 10:50:52 +08:00
|
|
|
#include "detection/displayserver/displayserver.h"
|
|
|
|
|
#include "modules/wm/wm.h"
|
2023-06-19 15:21:49 +08:00
|
|
|
#include "util/stringUtils.h"
|
2023-06-07 10:50:52 +08:00
|
|
|
|
|
|
|
|
#define FF_WM_NUM_FORMAT_ARGS 3
|
|
|
|
|
|
2023-06-24 10:59:53 +08:00
|
|
|
void ffPrintWM(FFWMOptions* options)
|
2023-06-07 10:50:52 +08:00
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
const FFDisplayServerResult* result = ffConnectDisplayServer();
|
2023-06-07 10:50:52 +08:00
|
|
|
|
|
|
|
|
if(result->wmPrettyName.length == 0)
|
|
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
ffPrintError(FF_WM_MODULE_NAME, 0, &options->moduleArgs, "No WM found");
|
2023-06-07 10:50:52 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(options->moduleArgs.outputFormat.length == 0)
|
|
|
|
|
{
|
2023-08-15 21:40:22 +08:00
|
|
|
ffPrintLogoAndKey(FF_WM_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
2023-06-07 10:50:52 +08:00
|
|
|
|
|
|
|
|
ffStrbufWriteTo(&result->wmPrettyName, stdout);
|
|
|
|
|
|
|
|
|
|
if(result->wmProtocolName.length > 0)
|
|
|
|
|
{
|
|
|
|
|
fputs(" (", stdout);
|
|
|
|
|
ffStrbufWriteTo(&result->wmProtocolName, stdout);
|
|
|
|
|
putchar(')');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2023-06-24 10:59:53 +08:00
|
|
|
ffPrintFormat(FF_WM_MODULE_NAME, 0, &options->moduleArgs, FF_WM_NUM_FORMAT_ARGS, (FFformatarg[]){
|
2023-06-07 10:50:52 +08:00
|
|
|
{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)
|
|
|
|
|
{
|
2023-09-13 14:22:04 +08:00
|
|
|
ffOptionInitModuleBaseInfo(&options->moduleInfo, FF_WM_MODULE_NAME, ffParseWMCommandOptions, ffParseWMJsonObject, ffPrintWM, ffGenerateWMJson);
|
2023-06-07 10:50:52 +08:00
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-17 10:56:54 +08:00
|
|
|
void ffParseWMJsonObject(FFWMOptions* options, yyjson_val* module)
|
2023-06-07 10:50:52 +08:00
|
|
|
{
|
2023-08-17 16:09:41 +08:00
|
|
|
yyjson_val *key_, *val;
|
|
|
|
|
size_t idx, max;
|
|
|
|
|
yyjson_obj_foreach(module, idx, max, key_, val)
|
2023-06-07 10:50:52 +08:00
|
|
|
{
|
2023-08-17 16:09:41 +08:00
|
|
|
const char* key = yyjson_get_str(key_);
|
|
|
|
|
if(ffStrEqualsIgnCase(key, "type"))
|
|
|
|
|
continue;
|
2023-06-10 15:01:54 +08:00
|
|
|
|
2023-08-17 16:09:41 +08:00
|
|
|
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs))
|
|
|
|
|
continue;
|
2023-06-07 10:50:52 +08:00
|
|
|
|
2023-08-17 16:09:41 +08:00
|
|
|
ffPrintError(FF_WM_MODULE_NAME, 0, &options->moduleArgs, "Unknown JSON key %s", key);
|
2023-06-07 10:50:52 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-13 14:22:04 +08:00
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|