aboutsummaryrefslogtreecommitdiff
path: root/src/blocks
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-11-24 19:39:19 +0100
committerFederico Angelilli <code@fedang.net>2024-11-24 19:39:19 +0100
commitdef1e18d86579cf77649d1b8aa596d0877b822bb (patch)
tree0e6deebdef1575b4b74472bc4367b294f7551753 /src/blocks
parent76ad6b0d404d40f08b73d90ac5f66564c29feb95 (diff)
Refactor block_change_fn
Diffstat (limited to 'src/blocks')
-rw-r--r--src/blocks/fs.c15
-rw-r--r--src/blocks/group.c13
-rw-r--r--src/blocks/ram.c15
-rw-r--r--src/blocks/slider.c22
-rw-r--r--src/blocks/text.c9
5 files changed, 44 insertions, 30 deletions
diff --git a/src/blocks/fs.c b/src/blocks/fs.c
index 1196c68..a52e491 100644
--- a/src/blocks/fs.c
+++ b/src/blocks/fs.c
@@ -152,12 +152,15 @@ static int block_fs_validate(block_t *block, config_t *config)
int marked = format_remark(&fs->format, block->label, block_fs_options);
if (marked < 0)
errors += -marked;
-
- if (marked == 0) {
- log_warn("Block '%s' does not use any fs option", block->label);
-
- block->update_fn = NULL;
- log_debug("Disabled updates for block '%s'", block->label);
+ else if (marked > 0)
+ block->update_fn = block_fs_update;
+ else {
+ log_warn("Block '%s' does not use any 'fs' option", block->label);
+
+ if (block->update_fn != NULL) {
+ block->update_fn = NULL;
+ log_debug("Disabled updates for block '%s'", block->label);
+ }
}
}
diff --git a/src/blocks/group.c b/src/blocks/group.c
index febefe4..eeac132 100644
--- a/src/blocks/group.c
+++ b/src/blocks/group.c
@@ -1,4 +1,5 @@
#include "../block.h"
+#include "../any_log.h"
static void block_group_init(block_t *block)
{
@@ -11,6 +12,17 @@ static void block_group_clean(block_t *block)
free(group->children);
}
+static config_status_t block_group_change(block_t *block, config_t *config, const char *key, const char *value)
+{
+ if (!strcmp(key, "blocks")) {
+ log_error("Block '%s' option '%s' cannot be changed", block->label, "blocks");
+ return CONFIG_INVALID;
+ }
+
+ extern const config_entry_t block_group_entries[];
+ return config_read_entry(block_group_entries, block, NULL, "block", block->label, key, value);
+}
+
const block_scheme_t block_group_scheme = {
.name = "group",
.entries = NULL,
@@ -18,4 +30,5 @@ const block_scheme_t block_group_scheme = {
.init_fn = block_group_init,
.clean_fn = block_group_clean,
.validate_fn = NULL,
+ .change_fn = block_group_change,
};
diff --git a/src/blocks/ram.c b/src/blocks/ram.c
index 28af60c..89cd196 100644
--- a/src/blocks/ram.c
+++ b/src/blocks/ram.c
@@ -160,12 +160,15 @@ static int block_ram_validate(block_t *block, config_t *config)
int marked = format_remark(&ram->format, block->label, block_ram_options);
if (marked < 0)
errors += -marked;
-
- if (marked == 0) {
- log_warn("Block '%s' does not use any ram option", block->label);
-
- block->update_fn = NULL;
- log_debug("Disabled updates for block '%s'", block->label);
+ else if (marked > 0)
+ block->update_fn = block_ram_update;
+ else {
+ log_warn("Block '%s' does not use any 'ram' option", block->label);
+
+ if (block->update_fn != NULL) {
+ block->update_fn = NULL;
+ log_debug("Disabled updates for block '%s'", block->label);
+ }
}
}
diff --git a/src/blocks/slider.c b/src/blocks/slider.c
index f568105..6ad5211 100644
--- a/src/blocks/slider.c
+++ b/src/blocks/slider.c
@@ -91,7 +91,10 @@ static void block_slider_render(layout_t *layout, cairo_t *cr)
int knob_width = slider->knob_width;
int knob_radius = knob_height / 2;
- int knob_rw = knob_width * cos(slider->knob_rotation) + knob_height * sin(slider->knob_rotation);
+ const double degree = M_PI / 180.0;
+ double knob_rotation = slider->knob_rotation * degree;
+
+ int knob_rw = knob_width * cos(knob_rotation) + knob_height * sin(knob_rotation);
int current = (slider->value * (slider->width - knob_rw)) / 100;
int knob_x = bar_x + slider->line_width + slider->knob_x_offset + current - knob_rw / 2;
@@ -107,7 +110,7 @@ static void block_slider_render(layout_t *layout, cairo_t *cr)
cairo_save(cr);
cairo_translate(cr, t_x, t_y);
- cairo_rotate(cr, slider->knob_rotation);
+ cairo_rotate(cr, knob_rotation);
cairo_translate(cr, -t_x, -t_y);
switch (slider->knob) {
@@ -139,7 +142,7 @@ static void block_slider_render(layout_t *layout, cairo_t *cr)
cairo_save(cr);
cairo_translate(cr, t_x, t_y);
- cairo_rotate(cr, slider->knob_rotation);
+ cairo_rotate(cr, knob_rotation);
cairo_translate(cr, -t_x, -t_y);
switch (slider->knob) {
@@ -236,17 +239,9 @@ static int block_slider_validate(block_t *block, config_t *config)
errors++;
}
- const double degree = M_PI / 180.0;
- slider->knob_rotation *= degree;
-
return errors;
}
-static config_status_t block_slider_change(block_t *block, config_t *config, const char *key, const char *value)
-{
- return 0;
-}
-
static config_enum_t knob_shape_enum[] = {
{ "none", KNOB_NONE },
{ "capsule", KNOB_CAPSULE },
@@ -277,6 +272,11 @@ static const config_entry_t block_slider_entries[] = {
{ 0 },
};
+static config_status_t block_slider_change(block_t *block, config_t *config, const char *key, const char *value)
+{
+ return config_read_entry(block_slider_entries, block, NULL, "block", block->label, key, value);
+}
+
const block_scheme_t block_slider_scheme = {
.name = "slider",
.entries = block_slider_entries,
diff --git a/src/blocks/text.c b/src/blocks/text.c
index bfaefe8..4046186 100644
--- a/src/blocks/text.c
+++ b/src/blocks/text.c
@@ -28,13 +28,8 @@ static int block_text_validate(block_t *block, config_t *config)
static config_status_t block_text_change(block_t *block, config_t *config, const char *key, const char *value)
{
-
- // text
- // text_color
- // text_align
- // text_size
-
- return CONFIG_UNKNOWN;
+ extern const config_entry_t block_text_entries[];
+ return config_read_entry(block_text_entries, block, NULL, "block", block->label, key, value);
}
const block_scheme_t block_text_scheme = {