diff options
| author | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
|---|---|---|
| committer | sumuel <samuel@yakubos.org> | 2026-08-17 20:44:55 +0000 |
| commit | 76424950e373d3b04ac3dd13019151bfba3e8423 (patch) | |
| tree | 4c3cfdbda039e592b9186be3e28f8d7cfd439e8a /src/modules/wmtheme | |
Add the files
Diffstat (limited to 'src/modules/wmtheme')
| -rw-r--r-- | src/modules/wmtheme/option.h | 9 | ||||
| -rw-r--r-- | src/modules/wmtheme/wmtheme.c | 75 | ||||
| -rw-r--r-- | src/modules/wmtheme/wmtheme.h | 11 |
3 files changed, 95 insertions, 0 deletions
diff --git a/src/modules/wmtheme/option.h b/src/modules/wmtheme/option.h new file mode 100644 index 0000000..5b0af07 --- /dev/null +++ b/src/modules/wmtheme/option.h @@ -0,0 +1,9 @@ +#pragma once + +#include "common/option.h" + +typedef struct FFWMThemeOptions { + FFModuleArgs moduleArgs; +} FFWMThemeOptions; + +static_assert(sizeof(FFWMThemeOptions) <= FF_OPTION_MAX_SIZE, "FFWMThemeOptions size exceeds maximum allowed size"); 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" }, + })) +}; diff --git a/src/modules/wmtheme/wmtheme.h b/src/modules/wmtheme/wmtheme.h new file mode 100644 index 0000000..5142ca4 --- /dev/null +++ b/src/modules/wmtheme/wmtheme.h @@ -0,0 +1,11 @@ +#pragma once + +#include "option.h" + +#define FF_WMTHEME_MODULE_NAME "WMTheme" + +bool ffPrintWMTheme(FFWMThemeOptions* options); +void ffInitWMThemeOptions(FFWMThemeOptions* options); +void ffDestroyWMThemeOptions(FFWMThemeOptions* options); + +extern FFModuleBaseInfo ffWMThemeModuleInfo; |