aboutsummaryrefslogtreecommitdiff
path: root/src/block.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/block.h')
-rw-r--r--src/block.h52
1 files changed, 35 insertions, 17 deletions
diff --git a/src/block.h b/src/block.h
index b310a36..71db95e 100644
--- a/src/block.h
+++ b/src/block.h
@@ -8,6 +8,7 @@
#include "event.h"
#include "util.h"
#include "layout.h"
+#include "config.h"
// Element or text alignment
//
@@ -27,18 +28,7 @@ typedef enum {
typedef struct block block_t;
-// Triggered when an event is directed towards the block
-//
-typedef void (*block_event_t)(block_t *block, event_t event);
-
-// Regularly called depending on the inverval passed from the last update
-//
-typedef void (*block_update_t)(block_t *block);
-
-// Called to cleanup a block and free its memory
-// NOTE: This should NOT free any other block!
-//
-typedef void (*block_clean_t)(block_t *block);
+typedef struct block_scheme block_scheme_t;
// Called in layout_init
//
@@ -48,24 +38,27 @@ typedef void (*block_layout_t)(block_t *block, layout_t *layout, layout_info_t i
//
typedef void (*block_render_t)(layout_t *layout, cairo_t *cr);
-// Called in config_resolve_children
+// Triggered when an event is directed towards the block
//
-typedef struct config config_t;
+typedef void (*block_event_t)(block_t *block, event_t event);
-typedef bool (*block_resolve_t)(block_t *block, config_t *config);
+// Regularly called depending on the inverval passed from the last update
+//
+typedef void (*block_update_t)(block_t *block);
// The block struct
//
struct block {
block_type_t type;
char *label;
+ const block_scheme_t *scheme;
+ bool validated;
bool resolved;
bool hidden;
struct timespec update_interval;
struct timespec update_last;
block_update_t update_fn;
block_event_t event_fn;
- block_clean_t clean_fn;
// TODO
//gradient_t bg_color;
//gradient_t line_color;
@@ -96,9 +89,34 @@ typedef struct {
block_t block;
block_layout_t layout_fn;
block_render_t render_fn;
- block_resolve_t resolve_fn;
} block_spec_t;
+// Called to allocate a block with its default state
+//
+typedef block_t *(*block_alloc_t)(const block_scheme_t *scheme);
+
+// Called to cleanup a block and free its memory
+// NOTE: This should NOT free any other block!
+//
+typedef void (*block_clean_t)(block_t *block);
+
+// Called to validate the block after parsing the config
+//
+typedef bool (*block_validate_t)(block_t *block, const block_scheme_t *scheme);
+
+typedef bool (*block_resolve_t)(block_t *block, config_t *config);
+
+struct block_scheme {
+ const char *name;
+ const config_entry_t *entries;
+ block_alloc_t alloc_fn;
+ block_clean_t clean_fn;
+ block_validate_t validate_fn;
+ block_resolve_t resolve_fn;
+};
+
+extern const block_scheme_t *block_schemes[];
+
void block_update(block_t *block);
void block_free(block_t *block);