summaryrefslogtreecommitdiffstats
path: root/src/modules/theme
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/theme')
-rw-r--r--src/modules/theme/option.h9
-rw-r--r--src/modules/theme/theme.c102
-rw-r--r--src/modules/theme/theme.h11
3 files changed, 122 insertions, 0 deletions
diff --git a/src/modules/theme/option.h b/src/modules/theme/option.h
new file mode 100644
index 0000000..66a68ba
--- /dev/null
+++ b/src/modules/theme/option.h
@@ -0,0 +1,9 @@
+#pragma once
+
+#include "common/option.h"
+
+typedef struct FFThemeOptions {
+ FFModuleArgs moduleArgs;
+} FFThemeOptions;
+
+static_assert(sizeof(FFThemeOptions) <= FF_OPTION_MAX_SIZE, "FFThemeOptions size exceeds maximum allowed size");
diff --git a/src/modules/theme/theme.c b/src/modules/theme/theme.c
new file mode 100644
index 0000000..70cb778
--- /dev/null
+++ b/src/modules/theme/theme.c
@@ -0,0 +1,102 @@
+#include "common/printing.h"
+#include "common/jsonconfig.h"
+#include "common/strutil.h"
+#include "detection/theme/theme.h"
+#include "modules/theme/theme.h"
+
+bool ffPrintTheme(FFThemeOptions* options) {
+ FFThemeResult result = {
+ .theme1 = ffStrbufCreate(),
+ .theme2 = ffStrbufCreate()
+ };
+ const char* error = ffDetectTheme(&result);
+
+ if (error) {
+ ffPrintError(FF_THEME_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "%s", error);
+ return false;
+ }
+
+ if (options->moduleArgs.outputFormat.length == 0) {
+ ffPrintLogoAndKey(FF_THEME_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT);
+ if (result.theme1.length) {
+ ffStrbufWriteTo(&result.theme1, stdout);
+ }
+ if (result.theme2.length) {
+ if (result.theme1.length) {
+ fputs(", ", stdout);
+ }
+ ffStrbufWriteTo(&result.theme2, stdout);
+ }
+ putchar('\n');
+ } else {
+ FF_PRINT_FORMAT_CHECKED(FF_THEME_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, ((FFformatarg[]) {
+ FF_ARG(result.theme1, "theme1"),
+ FF_ARG(result.theme2, "theme2"),
+ }));
+ }
+
+ ffStrbufDestroy(&result.theme1);
+ ffStrbufDestroy(&result.theme2);
+ return true;
+}
+
+void ffParseThemeJsonObject(FFThemeOptions* 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_THEME_MODULE_NAME, 0, &options->moduleArgs, FF_PRINT_TYPE_DEFAULT, "Unknown JSON key %s", unsafe_yyjson_get_str(key));
+ }
+}
+
+void ffGenerateThemeJsonConfig(FFThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
+ ffJsonConfigGenerateModuleArgsConfig(doc, module, &options->moduleArgs);
+}
+
+bool ffGenerateThemeJsonResult(FF_A_UNUSED FFThemeOptions* options, yyjson_mut_doc* doc, yyjson_mut_val* module) {
+ FFThemeResult result = {
+ .theme1 = ffStrbufCreate(),
+ .theme2 = ffStrbufCreate()
+ };
+ const char* error = ffDetectTheme(&result);
+
+ if (error) {
+ yyjson_mut_obj_add_str(doc, module, "error", error);
+ return false;
+ }
+
+ yyjson_mut_val* theme = yyjson_mut_obj_add_obj(doc, module, "result");
+ yyjson_mut_obj_add_strbuf(doc, theme, "theme1", &result.theme1);
+ yyjson_mut_obj_add_strbuf(doc, theme, "theme2", &result.theme2);
+
+ ffStrbufDestroy(&result.theme1);
+ ffStrbufDestroy(&result.theme2);
+
+ return true;
+}
+
+void ffInitThemeOptions(FFThemeOptions* options) {
+ ffOptionInitModuleArg(&options->moduleArgs, "󰉼");
+}
+
+void ffDestroyThemeOptions(FFThemeOptions* options) {
+ ffOptionDestroyModuleArg(&options->moduleArgs);
+}
+
+FFModuleBaseInfo ffThemeModuleInfo = {
+ .name = FF_THEME_MODULE_NAME,
+ .description = "Print the current desktop environment theme",
+ .initOptions = (void*) ffInitThemeOptions,
+ .destroyOptions = (void*) ffDestroyThemeOptions,
+ .parseJsonObject = (void*) ffParseThemeJsonObject,
+ .printModule = (void*) ffPrintTheme,
+ .generateJsonResult = (void*) ffGenerateThemeJsonResult,
+ .generateJsonConfig = (void*) ffGenerateThemeJsonConfig,
+ .formatArgs = FF_FORMAT_ARG_LIST(((FFModuleFormatArg[]) {
+ { "Theme part 1", "theme1" },
+ { "Theme part 2", "theme2" },
+ }))
+};
diff --git a/src/modules/theme/theme.h b/src/modules/theme/theme.h
new file mode 100644
index 0000000..56ba49c
--- /dev/null
+++ b/src/modules/theme/theme.h
@@ -0,0 +1,11 @@
+#pragma once
+
+#include "option.h"
+
+#define FF_THEME_MODULE_NAME "Theme"
+
+bool ffPrintTheme(FFThemeOptions* options);
+void ffInitThemeOptions(FFThemeOptions* options);
+void ffDestroyThemeOptions(FFThemeOptions* options);
+
+extern FFModuleBaseInfo ffThemeModuleInfo;