From 76424950e373d3b04ac3dd13019151bfba3e8423 Mon Sep 17 00:00:00 2001 From: sumuel Date: Mon, 17 Aug 2026 20:44:55 +0000 Subject: Add the files --- src/modules/wmtheme/wmtheme.c | 75 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/modules/wmtheme/wmtheme.c (limited to 'src/modules/wmtheme/wmtheme.c') diff --git a/src/modules/wmtheme/wmtheme.c b/src/modules/wmtheme/wmtheme.c new file mode 100644 index 0000000..775e88a --- /dev/null +++ b/src/modules/wmtheme/wmtheme.c @@ -0,0 +1,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" }, + })) +}; -- cgit v1.2.3