1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
#include "common/printing.h"
#include "common/jsonconfig.h"
#include "common/strutil.h"
#include "detection/wmtheme/wmtheme.h"
#include "modules/wmtheme/wmtheme.h"
#define FF_WMTHEME_DISPLAY_NAME "WM Theme"
bool ffPrintWMTheme(FFWMThemeOptions* options) {
FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate();
if (!ffDetectWmTheme(&themeOrError)) {
ffPrintError(FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", themeOrError.chars);
return false;
}
if (options->moduleArgs.outputFormat.length == 0) {
ffPrintLogoAndKey(FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
puts(themeOrError.chars);
} else {
FF_PRINT_FORMAT_CHECKED(FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
FF_ARG(themeOrError, "result"),
}));
}
return true;
}
void ffParseWMThemeJsonObject(FFWMThemeOptions* options, yyjson_val* module) {
yyjson_val *key, *val;
size_t idx, max;
yyjson_obj_foreach (module, idx, max, key, val) {
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
continue;
}
ffPrintError(FF_WMTHEME_DISPLAY_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
}
}
void ffGenerateWMThemeJsonConfig(FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
}
bool ffGenerateWMThemeJsonResult(FF_A_UNUSED FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate();
if (!ffDetectWmTheme(&themeOrError)) {
yyjson_mut_obj_add_strbuf(doc, module, "error", &themeOrError);
return false;
}
yyjson_mut_obj_add_strbuf(doc, module, "result", &themeOrError);
return true;
}
void ffInitWMThemeOptions(FFWMThemeOptions* options) {
ffOptionInitModuleArg(&options->moduleArgs, "");
}
void ffDestroyWMThemeOptions(FFWMThemeOptions* options) {
ffOptionDestroyModuleArg(&options->moduleArgs);
}
FFModuleBaseInfo ffWMThemeModuleInfo = {
.name = FF_WMTHEME_MODULE_NAME,
.description = "Print the current window manager theme",
.initOptions = (void*) ffInitWMThemeOptions,
.destroyOptions = (void*) ffDestroyWMThemeOptions,
.parseJsonObject = (void*) ffParseWMThemeJsonObject,
.printModule = (void*) ffPrintWMTheme,
.generateJsonResult = (void*) ffGenerateWMThemeJsonResult,
.generateJsonConfig = (void*) ffGenerateWMThemeJsonConfig,
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
{ "WM theme", "result" },
}))
};
|