From 8c2c0472cb0537ba74023db73ca11a541422f409 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?P=C5=99emysl=20Janouch?=
Date: Sun, 5 Jul 2015 16:28:27 +0200
Subject: [PATCH] degesch: add some trivial "on_change" callbacks
---
degesch.c | 27 ++++++++++++++++++---------
1 file changed, 18 insertions(+), 9 deletions(-)
diff --git a/degesch.c b/degesch.c
index 14f6476..5bdb58d 100644
--- a/degesch.c
+++ b/degesch.c
@@ -1288,14 +1288,15 @@ server_destroy (void *self)
struct app_context
{
+ bool no_colors; ///< Disable attribute printing
char *attrs_defaults[ATTR_COUNT]; ///< Default terminal attributes
// Configuration:
struct config config; ///< Program configuration
char *attrs[ATTR_COUNT]; ///< Terminal attributes
- bool no_colors; ///< Colour output mode
bool isolate_buffers; ///< Isolate global/server buffers
+ bool beep_on_highlight; ///< Beep on highlight
struct str_map servers; ///< Our servers
@@ -1416,9 +1417,19 @@ static bool irc_is_this_us (struct server *s, const char *prefix);
// --- Configuration -----------------------------------------------------------
-// TODO: "on_change" callbacks for everything
static void on_config_attribute_change (struct config_item_ *item);
+#define TRIVIAL_BOOLEAN_ON_CHANGE(name) \
+ static void \
+ on_config_ ## name ## _change (struct config_item_ *item) \
+ { \
+ struct app_context *ctx = item->user_data; \
+ ctx->name = item->value.boolean; \
+ }
+
+TRIVIAL_BOOLEAN_ON_CHANGE (isolate_buffers)
+TRIVIAL_BOOLEAN_ON_CHANGE (beep_on_highlight)
+
static bool
config_validate_nonjunk_string
(const struct config_item_ *item, struct error **e)
@@ -1557,11 +1568,13 @@ static struct config_schema g_config_behaviour[] =
{ .name = "isolate_buffers",
.comment = "Don't leak messages from the server and global buffers",
.type = CONFIG_ITEM_BOOLEAN,
- .default_ = "off" },
+ .default_ = "off",
+ .on_change = on_config_isolate_buffers_change },
{ .name = "beep_on_highlight",
.comment = "Beep when highlighted or on a new invisible PM",
.type = CONFIG_ITEM_BOOLEAN,
- .default_ = "on" },
+ .default_ = "on",
+ .on_change = on_config_beep_on_highlight_change },
{ .name = "logging",
.comment = "Log buffer contents to file",
.type = CONFIG_ITEM_BOOLEAN,
@@ -2593,7 +2606,7 @@ log_formatter (struct app_context *ctx,
if (buffer->log_file)
buffer_line_write_to_log (ctx, line, buffer->log_file);
- if (get_config_boolean (ctx->config.root, "behaviour.beep_on_highlight"))
+ if (ctx->beep_on_highlight)
if ((flags & BUFFER_LINE_HIGHLIGHT)
|| (buffer->type == BUFFER_PM && buffer != ctx->current_buffer))
input_ding (&ctx->input);
@@ -8748,10 +8761,6 @@ main (int argc, char *argv[])
init_poller_events (&ctx);
load_configuration (&ctx);
- // TODO: this won't be needed after adding an "on_change" callback
- ctx.isolate_buffers =
- get_config_boolean (ctx.config.root, "behaviour.isolate_buffers");
-
// At this moment we can safely call any "on_change" callbacks
config_schema_call_changed (ctx.config.root);