aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-07-13 00:12:09 +0200
committerFederico Angelilli <code@fedang.net>2024-07-13 00:12:09 +0200
commitf10d68879e358a2642573d408bbc47f1c759d387 (patch)
tree629d317ccabb9f92adc0cab2d9f2e856fdc53826
parenta60a1a755598240f5a7705070179bfa707ad4c56 (diff)
Separate block infos
-rw-r--r--Makefile2
-rw-r--r--src/block.h1
-rw-r--r--src/blocks/group.c15
-rw-r--r--src/blocks/info.h10
-rw-r--r--src/blocks/text.c16
-rw-r--r--src/config.c40
6 files changed, 56 insertions, 28 deletions
diff --git a/Makefile b/Makefile
index cf55cc2..3d15574 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-SRC = $(wildcard src/*.c)
+SRC = $(shell find src/ -name '*.c')
OBJ = $(SRC:.c=.o)
BIN = comet.bin
diff --git a/src/block.h b/src/block.h
index 9c663b1..5301a7b 100644
--- a/src/block.h
+++ b/src/block.h
@@ -43,6 +43,7 @@ struct block {
struct timespec update_last;
block_update_t update_cb;
block_event_t event_cb;
+ void *info;
bool hidden;
color_t color;
diff --git a/src/blocks/group.c b/src/blocks/group.c
new file mode 100644
index 0000000..00afb00
--- /dev/null
+++ b/src/blocks/group.c
@@ -0,0 +1,15 @@
+#include "info.h"
+
+static const config_entry_t block_group_entries[] = {
+ { "spacing", CONFIG_INT, offsetof(block_t, group.spacing) },
+ { 0 },
+};
+
+// TODO
+const config_block_t block_group_info = {
+ .type_name = "group",
+ .type_size = 0,
+ .base = { 0 },
+ .entries = block_group_entries,
+ .apply = NULL,
+};
diff --git a/src/blocks/info.h b/src/blocks/info.h
new file mode 100644
index 0000000..c5ea38e
--- /dev/null
+++ b/src/blocks/info.h
@@ -0,0 +1,10 @@
+#ifndef COMET_BLOCKS_H
+#define COMET_BLOCKS_H
+
+#include "../config.h"
+
+extern const config_block_t block_text_info;
+
+extern const config_block_t block_group_info;
+
+#endif
diff --git a/src/blocks/text.c b/src/blocks/text.c
new file mode 100644
index 0000000..74df3c3
--- /dev/null
+++ b/src/blocks/text.c
@@ -0,0 +1,16 @@
+#include "info.h"
+
+static const config_entry_t block_text_entries[] = {
+ { "text", CONFIG_STRING, offsetof(block_t, text.text) },
+ { "text-color", CONFIG_COLOR, offsetof(block_t, text.text_color) },
+ { "text-size", CONFIG_INT, offsetof(block_t, text.text_size) },
+ { 0 },
+};
+
+const config_block_t block_text_info = {
+ .type_name = "text",
+ .type_size = 0,
+ .base = { 0 },
+ .entries = block_text_entries,
+ .apply = NULL,
+};
diff --git a/src/config.c b/src/config.c
index 9a2bc42..ff587da 100644
--- a/src/config.c
+++ b/src/config.c
@@ -9,6 +9,7 @@
#include "config.h"
#include "util.h"
#include "block.h"
+#include "blocks/info.h"
#define ANY_INI_IMPLEMENT
#include "any_ini.h"
@@ -24,7 +25,7 @@ static const config_entry_t bar_entries[] = {
{ "height", CONFIG_UINT, offsetof(config_t, height) },
{ "font", CONFIG_STRING, offsetof(config_t, font) },
{ "monitor", CONFIG_STRING, offsetof(config_t, monitor) },
- { "override_redirect", CONFIG_BOOL, offsetof(config_t, override_redirect) },
+ { "override-redirect", CONFIG_BOOL, offsetof(config_t, override_redirect) },
{ "background", CONFIG_COLOR, offsetof(config_t, background) },
{ 0 },
};
@@ -41,28 +42,6 @@ static const config_entry_t block_entries[] = {
{ 0 },
};
-static const config_entry_t block_text_entries[] = {
- { "text", CONFIG_STRING, offsetof(block_t, text.text) },
- { "text-color", CONFIG_COLOR, offsetof(block_t, text.text_color) },
- { "text-size", CONFIG_INT, offsetof(block_t, text.text_size) },
-};
-
-static const config_block_t block_infos[] = {
- {
- .type_name = "text",
- .type_size = 0,
- .base = { 0 },
- .entries = block_text_entries,
- .apply = NULL,
- },
- //{
- // "group",
- // 0,
- // block_group_entries,
- //},
- { 0 }
-};
-
static bool config_read_string(const char *value, char **result)
{
if (value == NULL)
@@ -325,15 +304,22 @@ void config_read(config_t *config, FILE *file)
goto skip_pair;
}
+
+ // FIXME: Move this somewhere else
+ const config_block_t block_infos[] = {
+ block_text_info,
+ block_group_info,
+ { 0 }
+ };
+
for (int i = 0; block_infos[i].type_name != NULL; i++) {
if (strcmp(block_infos[i].type_name, value))
continue;
info = &block_infos[i];
memcpy(block, &info->base, sizeof(block_t));
- result = !strcmp(value, "text")
- ? block
- : malloc(info->type_size);
-
+ block->info = result = !strcmp(value, "text")
+ ? block
+ : malloc(info->type_size);
goto skip_pair;
}