aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Angelilli <code@fedang.net>2024-07-12 12:34:39 +0200
committerFederico Angelilli <code@fedang.net>2024-07-12 12:34:39 +0200
commite45c7bc6b41fbcea84ca51d01b8661f93145ce7a (patch)
treee07c3a4733f7b221efa4130bad1db1e48ccc90f4
parente60937111eb8c7097e63da2bf253ea7425275636 (diff)
Add signal handler
-rw-r--r--src/block.h4
-rw-r--r--src/comet.c9
-rw-r--r--src/config.c20
3 files changed, 24 insertions, 9 deletions
diff --git a/src/block.h b/src/block.h
index c6046a7..9468373 100644
--- a/src/block.h
+++ b/src/block.h
@@ -36,6 +36,8 @@ typedef void (*block_update_t)(block_t *block);
// Block struct
//
struct block {
+ block_type_t type;
+ char *label;
bool hidden;
color_t color;
color_t line_color;
@@ -46,8 +48,6 @@ struct block {
struct timespec update_last;
block_update_t update_cb;
block_event_t event_cb;
- char *label;
- block_type_t type;
union {
struct {
char *text;
diff --git a/src/comet.c b/src/comet.c
index c4d9f17..752f147 100644
--- a/src/comet.c
+++ b/src/comet.c
@@ -1,5 +1,6 @@
#include <stdlib.h>
#include <locale.h>
+#include <signal.h>
#include <math.h>
#include "window.h"
@@ -23,6 +24,13 @@
#define ANY_LOG_IMPLEMENT
#include "any_log.h"
+static sig_atomic_t running = true;
+
+void signal_quit(int status)
+{
+ running = false;
+}
+
static cairo_surface_t *render_all(layout_t *layout, config_t *config, layout_info_t info)
{
cairo_surface_t *surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32,
@@ -117,6 +125,7 @@ int main(int argc, char **argv)
nanosleep(&diff, NULL);
}
+ log_debug("Quitting");
g_object_unref(info.context);
pango_font_description_free(fontdesc);
diff --git a/src/config.c b/src/config.c
index 5af05f7..d636c31 100644
--- a/src/config.c
+++ b/src/config.c
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <limits.h>
#include <string.h>
+#include <assert.h>
#include "any_log.h"
#include "config.h"
@@ -37,6 +38,8 @@ static const config_entry_t bar_entries[] = {
};
static const config_entry_t block_entries[] = {
+ { "type", CONFIG_INT, offsetof(block_t, type) },
+ { "text", CONFIG_STRING, offsetof(block_t, text.text) },
{ 0 },
};
@@ -156,7 +159,7 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l
const char *types[] = {
"string",
"integer",
- "positive integer",
+ "unsigned integer",
"double float",
};
@@ -178,35 +181,35 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l
case CONFIG_STRING:
// NOTE: The previous string is freed by config_read_string
if (config_read_string(value, (char **)result)) {
- log_debug("Config '%s' set to '%s'", key, *(char **)result);
+ log_debug("Set '%s.%s' to '%s'", section, key, *(char **)result);
return true;
}
break;
case CONFIG_INT:
if (config_read_int(value, (int *)result)) {
- log_debug("Config '%s' set to '%d'", key, *(int *)result);
+ log_debug("Set '%s.%s' to '%d'", section, key, *(int *)result);
return true;
}
break;
case CONFIG_UINT:
if (config_read_uint(value, (unsigned int *)result)) {
- log_debug("Config '%s' set to '%u'", key, *(unsigned int *)result);
+ log_debug("Set '%s.%s' to '%u'", section, key, *(unsigned int *)result);
return true;
}
break;
case CONFIG_DOUBLE:
if (config_read_double(value, (double *)result)) {
- log_debug("Config '%s' set to '%lf'", key, *(double *)result);
+ log_debug("Set '%s.%s' to '%lf'", section, key, *(double *)result);
return true;
}
break;
case CONFIG_BOOL:
if (config_read_bool(value, (bool *)result)) {
- log_debug("Config '%s' set to '%s'", key, *(bool *)result ? "true" : "false");
+ log_debug("Set '%s.%s' to '%s'", section, key, *(bool *)result ? "true" : "false");
return true;
}
break;
@@ -214,7 +217,7 @@ static bool config_read_entry(const config_entry_t *entries, void *result, int l
case CONFIG_COLOR:
if (config_read_color(value, (color_t *)result)) {
char *color = color_to_string((color_t *)result);
- log_debug("Config '%s' set to '%s'", key, color);
+ log_debug("Set '%s.%s' to '%s'", section, key, color);
free(color);
return true;
}
@@ -281,6 +284,9 @@ void config_read(config_t *config, FILE *file)
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];
} else if (!strcmp(section, "bar")) {
entries = bar_entries;
result = config;