diff options
| author | Federico Angelilli <code@fedang.net> | 2024-07-12 13:33:28 +0200 |
|---|---|---|
| committer | Federico Angelilli <code@fedang.net> | 2024-07-12 13:33:28 +0200 |
| commit | e98943f9eb5cea2921969501e52e8c319323ed4c (patch) | |
| tree | f7879c77e85d4cdea19c53bef2d1ae3dc192c20c | |
| parent | e45c7bc6b41fbcea84ca51d01b8661f93145ce7a (diff) | |
Start working on special sections
| -rw-r--r-- | comet.conf | 42 | ||||
| -rw-r--r-- | src/comet.c | 15 | ||||
| -rw-r--r-- | src/config.c | 76 | ||||
| -rw-r--r-- | src/config.h | 32 | ||||
| -rw-r--r-- | src/util.c | 12 | ||||
| -rw-r--r-- | src/util.h | 9 |
6 files changed, 156 insertions, 30 deletions
@@ -10,5 +10,45 @@ sus = false [block.cpu] - type = text + ;type = text + type = 0 text = CPU + +[block.main] + type = 0 + text = CIAO + color = #123 + text-color = #fff + + event-click-left = ex + +;;[action.] +;; err = true + +[action.ex] + + animation = shine + prop = newvalue + ;text = ${shell: tail -f /file } + +;[block.label] +; type = text | group +; x-padding = 0 +; y-padding = 0 +; color = col +; line-width = 0 +; line-color = col +; hidden = false +; interval = 1111 +; min-width = 0 +; max-width = 0 +; +; ; only text +; text = ... +; text-color = col +; text-align = right | center | left +; text-size = 1 +; +; ; only group +; spacing = 10 +; children = label2 another blockus diff --git a/src/comet.c b/src/comet.c index 752f147..53be0b2 100644 --- a/src/comet.c +++ b/src/comet.c @@ -73,15 +73,15 @@ int main(int argc, char **argv) config_read(&config, config_file); } + signal(SIGINT, signal_quit); + signal(SIGTERM, signal_quit); + display_t display; display_init(&display); window_t window; window_init(&window, &display, &config); - // FIXME - config.main_block.min_width = config.main_block.max_width = config.width; - int x_padding = 10; int y_padding = 8; @@ -98,6 +98,9 @@ int main(int argc, char **argv) window_resize(&window, config.width, config.height); window_move(&window, x_padding, y_padding); + block_t main_block = { 0 }; + config_resolve(&config, &main_block); + // TODO: Allow ondemand rendering struct timespec rate, start, end, diff; @@ -105,13 +108,13 @@ int main(int argc, char **argv) rate.tv_sec = (long)freq; rate.tv_nsec = (freq - rate.tv_sec) * 1000000000ul; - while (true) { + while (running) { timespec_get(&start, TIME_UTC); - block_update(&config.main_block); + block_update(&main_block); layout_t layout; - layout_init(&layout, &config.main_block, info); + layout_init(&layout, &main_block, info); event_dispatch(&display, &layout); diff --git a/src/config.c b/src/config.c index d636c31..4451341 100644 --- a/src/config.c +++ b/src/config.c @@ -37,11 +37,15 @@ static const config_entry_t bar_entries[] = { { 0 }, }; -static const config_entry_t block_entries[] = { - { "type", CONFIG_INT, offsetof(block_t, type) }, - { "text", CONFIG_STRING, offsetof(block_t, text.text) }, - { 0 }, -}; +//static const config_entry_t block_entries[] = { +// { "type", CONFIG_INT, offsetof(config_block_t, type) }, +// { "x-padding", CONFIG_UINT, offsetof(config_block_t, x_padding) }, +// { "y-padding", CONFIG_UINT, offsetof(config_block_t, y_padding) }, +// { "text-color", CONFIG_STRING, offsetof(config_block_t, text_color) }, +// { "text", CONFIG_STRING, offsetof(config_block_t, text) }, +// { "color", CONFIG_STRING, offsetof(config_block_t, color) }, +// { 0 }, +//}; static bool config_read_string(const char *value, char **result) { @@ -250,11 +254,6 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l void config_init(config_t *config) { const config_t config_default = { - .main_block = { - .label = "main_block", - .color = color_rgb(100, 100, 100), - .type = BLOCK_GROUP, - }, .font = "monospace 10", .monitor = NULL, .height = 50, @@ -263,8 +262,6 @@ void config_init(config_t *config) }; memcpy(config, &config_default, sizeof(config_t)); - block_copy(&config->main_block, &config_default.main_block); - config->font = strcopy(config_default.font); config->monitor = strcopy(config_default.monitor); } @@ -281,12 +278,19 @@ void config_read(config_t *config, FILE *file) const config_entry_t *entries = NULL; void *result = NULL; + config_section_t **section_ptr = NULL; + size_t *section_size = NULL; + char *section_label = NULL; + if (section != NULL) { if (!strncmp(section, "block.", 6)) { - entries = block_entries; - config->blocks = realloc(config->blocks, ++config->n_blocks * sizeof(block_t)); - assert(config->blocks != NULL); - result = &config->blocks[config->n_blocks - 1]; + section_ptr = &config->blocks; + section_size = &config->n_blocks; + section_label = strcopy(section + 6); + } else if (!strncmp(section, "action.", 7)) { + section_ptr = &config->actions; + section_size = &config->n_actions; + section_label = strcopy(section + 7); } else if (!strcmp(section, "bar")) { entries = bar_entries; result = config; @@ -294,6 +298,19 @@ void config_read(config_t *config, FILE *file) log_warn("Unknown section '%s'", section); } + if (section_ptr != NULL) { + if (*section_label == '\0') { + ++errors; + log_value_error("Sections must have a non-empty label", + "s:section", section, + "i:line", ini.line); + } + + *section_ptr = realloc(*section_ptr, ++(*section_size) * sizeof(config_section_t)); + assert(*section_ptr != NULL); + (*section_ptr)[*section_size - 1].label = section_label; + } + char *key; while ((key = any_ini_stream_next_key(&ini)) != NULL) { char *value = any_ini_stream_next_value(&ini); @@ -318,13 +335,34 @@ void config_read(config_t *config, FILE *file) log_panic("Config file contained %d errors", errors); } +void config_resolve(config_t *config, block_t *block) +{ + int errors = 1; + + if (errors > 0) + log_panic("Failed to resolve config"); +} + void config_free(config_t *config) { - block_free(&config->main_block); + for (int i = 0; i < config->n_blocks; i++) { + for (int j = 0; j < config->blocks[i].n_pairs; j++) + pair_free(&config->blocks[i].pairs[j]); - for (int i = 0; i < config->n_blocks; i++) - block_free(&config->blocks[i]); + free(config->blocks[i].pairs); + free(config->blocks[i].label); + } + + for (int i = 0; i < config->n_actions; i++) { + for (int j = 0; j < config->actions[i].n_pairs; j++) + pair_free(&config->actions[i].pairs[j]); + + free(config->actions[i].pairs); + free(config->actions[i].label); + } + free(config->blocks); + free(config->actions); free(config->font); free(config->monitor); } diff --git a/src/config.h b/src/config.h index 8e4098c..c24c968 100644 --- a/src/config.h +++ b/src/config.h @@ -2,17 +2,39 @@ #define COMET_CONFIG_H #include <stdio.h> +#include <stdint.h> #include "block.h" +//typedef struct { +// char *label; +// char *type; +// int x_padding, y_padding; +// color_t color; +// char *text; +// color_t text_color; +// int line_width; +// color_t line_color; +// bool hidden; +// double interval; +// int min_width, max_width; +//} config_block_t; + +typedef struct { + char *label; + size_t n_pairs; + pair_t *pairs; +} config_section_t; + typedef struct { - block_t main_block; size_t n_blocks; - block_t *blocks; + config_section_t *blocks; + size_t n_actions; + config_section_t *actions; char *font; char *monitor; - unsigned int height; - unsigned int width; + uint32_t height; + uint32_t width; bool override_redirect; color_t background; } config_t; @@ -21,6 +43,8 @@ void config_init(config_t *config); void config_read(config_t *config, FILE *file); +void config_resolve(config_t *config, block_t *block); + void config_free(config_t *config); #endif @@ -5,6 +5,18 @@ #include "util.h" +void pair_copy(pair_t *copy, const pair_t *pair) +{ + copy->key = strcopy(pair->key); + copy->value = strcopy(pair->value); +} + +void pair_free(pair_t *pair) +{ + free(pair->key); + free(pair->value); +} + char *color_to_string(color_t *color) { unsigned int r = color->r * 255, @@ -6,6 +6,15 @@ #include <stdbool.h> #include <stdio.h> +typedef struct { + char *key; + char *value; +} pair_t; + +void pair_copy(pair_t *copy, const pair_t *pair); + +void pair_free(pair_t *pair); + // Color representation normalized to [0, 1] // typedef struct { |
