ohmu
·
2026-10-15
1#include "common/printing.h"
2#include "common/jsonconfig.h"
3#include "common/strutil.h"
4#include "detection/wmtheme/wmtheme.h"
5#include "modules/wmtheme/wmtheme.h"
6
7bool ffPrintWMTheme(FFWMThemeOptions* options) {
8 FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate();
9 if (!ffDetectWmTheme(&themeOrError)) {
10 ffPrintError(FF_MODULE_GET_DISPLAY_NAME(WMTheme), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", themeOrError.chars);
11 return false;
12 }
13
14 if (options->moduleArgs.outputFormat.length == 0) {
15 ffPrintLogoAndKey(FF_MODULE_GET_DISPLAY_NAME(WMTheme), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
16 puts(themeOrError.chars);
17 } else {
18 FF_PRINT_FORMAT_CHECKED(FF_MODULE_GET_DISPLAY_NAME(WMTheme), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
19 FF_ARG(themeOrError, "result"),
20 }));
21 }
22
23 return true;
24}
25
26void ffParseWMThemeJsonObject(FFWMThemeOptions* options, yyjson_val* module) {
27 yyjson_val *key, *val;
28 size_t idx, max;
29 yyjson_obj_foreach (module, idx, max, key, val) {
30 if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
31 continue;
32 }
33
34 ffPrintError(FF_MODULE_GET_DISPLAY_NAME(WMTheme), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
35 }
36}
37
38[[gnu::cold]]
39void ffGenerateWMThemeJsonConfig(FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
40 ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
41}
42
43bool ffGenerateWMThemeJsonResult([[maybe_unused]] FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
44 FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate();
45 if (!ffDetectWmTheme(&themeOrError)) {
46 yyjson_mut_obj_add_strbuf(doc, module, "error", &themeOrError);
47 return false;
48 }
49
50 yyjson_mut_obj_add_strbuf(doc, module, "result", &themeOrError);
51 return true;
52}
53
54void ffInitWMThemeOptions(FFWMThemeOptions* options) {
55 ffOptionInitModuleArg(&options->moduleArgs, "");
56}
57
58void ffDestroyWMThemeOptions(FFWMThemeOptions* options) {
59 ffOptionDestroyModuleArg(&options->moduleArgs);
60}
61
62FFModuleBaseInfo ffWMThemeModuleInfo = {
63 .name = "WMTheme",
64 .description = "Print the current window manager theme",
65 .displayName = {
66 .en = "WM Theme",
67 .ar = "سمة مدير النوافذ",
68 .cs = "Motiv správce oken",
69 .de = "Fenstermanager-Thema",
70 .es = "Tema del gestor de ventanas",
71 .fi = "Ikkunointijärjestelmän Teema",
72 .fr = "Thème du gestionnaire de fenêtres",
73 .gl = "Tema do xestor de xanelas",
74 .he = "ערכת נושא של מנהל חלונות",
75 .id = "Tema Manajer Jendela",
76 .it = "Tema del gestore finestre",
77 .ja = "ウィンドウマネージャのテーマ",
78 .ko = "윈도우 관리자 테마",
79 .pl = "Motyw menedżera okien",
80 .pt = "Tema do gerenciador de janelas",
81 .ru = "Тема менеджера окон",
82 .tr = "WM Teması",
83 .uk = "Тема менеджера вікон",
84 .vi = "Chủ đề trình quản lý cửa sổ",
85 .zh_CN = "窗口管理器主题",
86 .zh_TW = "視窗管理員主題",
87 },
88 .initOptions = (void*) ffInitWMThemeOptions,
89 .destroyOptions = (void*) ffDestroyWMThemeOptions,
90 .parseJsonObject = (void*) ffParseWMThemeJsonObject,
91 .printModule = (void*) ffPrintWMTheme,
92 .generateJsonResult = (void*) ffGenerateWMThemeJsonResult,
93 .generateJsonConfig = (void*) ffGenerateWMThemeJsonConfig,
94 .formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
95 { "WM theme", "result" },
96 })),
97 .defaultOrder = 23,
98};