2026-01-06 09:48:38 +08:00
|
|
|
#include "common/printing.h"
|
|
|
|
|
#include "common/jsonconfig.h"
|
2026-05-28 15:58:08 +08:00
|
|
|
#include "common/strutil.h"
|
2023-04-28 19:11:55 +08:00
|
|
|
#include "detection/wmtheme/wmtheme.h"
|
|
|
|
|
#include "modules/wmtheme/wmtheme.h"
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
bool ffPrintWMTheme(FFWMThemeOptions* options) {
|
2023-04-28 19:11:55 +08:00
|
|
|
FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate();
|
2026-03-29 09:28:49 +08:00
|
|
|
if (!ffDetectWmTheme(&themeOrError)) {
|
2026-08-14 23:33:54 +08:00
|
|
|
ffPrintError(FF_MODULE_GET_DISPLAY_NAME(WMTheme), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", themeOrError.chars);
|
2025-08-18 13:38:30 +08:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
if (options->moduleArgs.outputFormat.length == 0) {
|
2026-08-14 23:33:54 +08:00
|
|
|
ffPrintLogoAndKey(FF_MODULE_GET_DISPLAY_NAME(WMTheme), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
|
2025-08-18 13:38:30 +08:00
|
|
|
puts(themeOrError.chars);
|
2026-03-29 09:28:49 +08:00
|
|
|
} else {
|
2026-08-14 23:33:54 +08:00
|
|
|
FF_PRINT_FORMAT_CHECKED(FF_MODULE_GET_DISPLAY_NAME(WMTheme), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
|
2026-03-29 09:28:49 +08:00
|
|
|
FF_ARG(themeOrError, "result"),
|
|
|
|
|
}));
|
2023-04-28 19:11:55 +08:00
|
|
|
}
|
2025-08-18 13:38:30 +08:00
|
|
|
|
|
|
|
|
return true;
|
2023-04-28 19:11:55 +08:00
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffParseWMThemeJsonObject(FFWMThemeOptions* options, yyjson_val* module) {
|
2025-08-02 18:51:03 +08:00
|
|
|
yyjson_val *key, *val;
|
2023-08-17 16:09:41 +08:00
|
|
|
size_t idx, max;
|
2026-03-29 09:28:49 +08:00
|
|
|
yyjson_obj_foreach (module, idx, max, key, val) {
|
|
|
|
|
if (ffJsonConfigParseModuleArgs(key, val, &options->moduleArgs)) {
|
2023-08-17 16:09:41 +08:00
|
|
|
continue;
|
2026-03-29 09:28:49 +08:00
|
|
|
}
|
2023-04-28 19:11:55 +08:00
|
|
|
|
2026-08-14 23:33:54 +08:00
|
|
|
ffPrintError(FF_MODULE_GET_DISPLAY_NAME(WMTheme), 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
|
2023-04-28 19:11:55 +08:00
|
|
|
}
|
|
|
|
|
}
|
2023-09-13 14:25:00 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffGenerateWMThemeJsonConfig(FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
2025-08-04 16:46:28 +08:00
|
|
|
ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
|
2023-10-24 14:41:29 +08:00
|
|
|
}
|
|
|
|
|
|
2026-07-10 21:13:03 +08:00
|
|
|
bool ffGenerateWMThemeJsonResult([[maybe_unused]] FFWMThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
|
2023-09-13 14:25:00 +08:00
|
|
|
FF_STRBUF_AUTO_DESTROY themeOrError = ffStrbufCreate();
|
2026-03-29 09:28:49 +08:00
|
|
|
if (!ffDetectWmTheme(&themeOrError)) {
|
2023-09-13 14:25:00 +08:00
|
|
|
yyjson_mut_obj_add_strbuf(doc, module, "error", &themeOrError);
|
2025-08-18 13:38:30 +08:00
|
|
|
return false;
|
2023-09-13 14:25:00 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yyjson_mut_obj_add_strbuf(doc, module, "result", &themeOrError);
|
2025-08-18 13:38:30 +08:00
|
|
|
return true;
|
2023-09-13 14:25:00 +08:00
|
|
|
}
|
2023-10-07 13:40:40 +08:00
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffInitWMThemeOptions(FFWMThemeOptions* options) {
|
2025-08-04 14:25:14 +08:00
|
|
|
ffOptionInitModuleArg(&options->moduleArgs, "");
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-29 09:28:49 +08:00
|
|
|
void ffDestroyWMThemeOptions(FFWMThemeOptions* options) {
|
2025-08-04 14:25:14 +08:00
|
|
|
ffOptionDestroyModuleArg(&options->moduleArgs);
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-03 22:50:56 +08:00
|
|
|
FFModuleBaseInfo ffWMThemeModuleInfo = {
|
2026-08-14 23:33:54 +08:00
|
|
|
.name = "WMTheme",
|
2026-04-16 18:27:11 +08:00
|
|
|
.description = "Print the current window manager theme",
|
2026-08-14 20:38:58 +08:00
|
|
|
.displayName = {
|
|
|
|
|
.en = "WM Theme",
|
|
|
|
|
.de = "Fenstermanager-Thema",
|
|
|
|
|
.es = "Tema del gestor de ventanas",
|
|
|
|
|
.fr = "Thème du gestionnaire de fenêtres",
|
|
|
|
|
.it = "Tema del gestore finestre",
|
|
|
|
|
.ja = "ウィンドウマネージャのテーマ",
|
|
|
|
|
.ko = "윈도우 관리자 테마",
|
|
|
|
|
.pl = "Motyw menedżera okien",
|
|
|
|
|
.pt_BR = "Tema do gerenciador de janelas",
|
|
|
|
|
.ru = "Тема менеджера окон",
|
|
|
|
|
.zh_CN = "窗口管理器主题",
|
|
|
|
|
.zh_TW = "視窗管理員主題",
|
|
|
|
|
},
|
2025-08-03 18:39:41 +08:00
|
|
|
.initOptions = (void*) ffInitWMThemeOptions,
|
|
|
|
|
.destroyOptions = (void*) ffDestroyWMThemeOptions,
|
2024-12-11 10:47:02 +08:00
|
|
|
.parseJsonObject = (void*) ffParseWMThemeJsonObject,
|
|
|
|
|
.printModule = (void*) ffPrintWMTheme,
|
|
|
|
|
.generateJsonResult = (void*) ffGenerateWMThemeJsonResult,
|
|
|
|
|
.generateJsonConfig = (void*) ffGenerateWMThemeJsonConfig,
|
|
|
|
|
.formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
|
2026-03-30 10:27:23 +08:00
|
|
|
{ "WM theme", "result" },
|
2026-07-31 10:56:13 +08:00
|
|
|
})),
|
|
|
|
|
.defaultOrder = 23,
|
2026-03-30 10:17:45 +08:00
|
|
|
};
|