aboutsummaryrefslogtreecommitdiff
path: root/i3bar
diff options
context:
space:
mode:
authorOrestis Floros <orestisflo@gmail.com>2021-01-12 08:41:19 +0100
committerOrestis Floros <orestisflo@gmail.com>2021-01-12 08:56:38 +0100
commit6e0b29a65b99cdf193a615cb890f11aa1d17a97f (patch)
tree41df1c6d88ddd1ea3c109b2fff7688b3956fcf4b /i3bar
parent0370c5e29721f47159aa4ef13ce8df1395771a04 (diff)
downloadi3-6e0b29a65b99cdf193a615cb890f11aa1d17a97f.tar.gz
i3-6e0b29a65b99cdf193a615cb890f11aa1d17a97f.zip
i3bar: properly restart status command after config change
Diffstat (limited to 'i3bar')
-rw-r--r--i3bar/include/child.h6
-rw-r--r--i3bar/src/child.c4
-rw-r--r--i3bar/src/config.c1
-rw-r--r--i3bar/src/ipc.c17
4 files changed, 23 insertions, 5 deletions
diff --git a/i3bar/include/child.h b/i3bar/include/child.h
index adc638be..ae523bc0 100644
--- a/i3bar/include/child.h
+++ b/i3bar/include/child.h
@@ -43,6 +43,12 @@ typedef struct {
} i3bar_child;
/*
+ * Remove all blocks from the given statusline.
+ * If free_resources is set, the fields of each status block will be free'd.
+ */
+void clear_statusline(struct statusline_head *head, bool free_resources);
+
+/*
* Start a child process with the specified command and reroute stdin.
* We actually start a $SHELL to execute the command so we don't have to care
* about arguments and such
diff --git a/i3bar/src/child.c b/i3bar/src/child.c
index 1198186b..df4c6601 100644
--- a/i3bar/src/child.c
+++ b/i3bar/src/child.c
@@ -27,7 +27,7 @@
#include <yajl/yajl_parse.h>
/* Global variables for child_*() */
-i3bar_child child;
+i3bar_child child = {0};
#define DLOG_CHILD DLOG("%s: pid=%ld stopped=%d stop_signal=%d cont_signal=%d click_events=%d click_events_init=%d\n", \
__func__, (long)child.pid, child.stopped, child.stop_signal, child.cont_signal, child.click_events, child.click_events_init)
@@ -66,7 +66,7 @@ int child_stdin;
* Remove all blocks from the given statusline.
* If free_resources is set, the fields of each status block will be free'd.
*/
-static void clear_statusline(struct statusline_head *head, bool free_resources) {
+void clear_statusline(struct statusline_head *head, bool free_resources) {
struct status_block *first;
while (!TAILQ_EMPTY(head)) {
first = TAILQ_FIRST(head);
diff --git a/i3bar/src/config.c b/i3bar/src/config.c
index 10847cd1..1cff085e 100644
--- a/i3bar/src/config.c
+++ b/i3bar/src/config.c
@@ -184,7 +184,6 @@ static int config_string_cb(void *params_, const unsigned char *val, size_t _len
if (!strcmp(cur_key, "status_command")) {
DLOG("command = %.*s\n", len, val);
- FREE(config.command);
sasprintf(&config.command, "%.*s", len, val);
return 1;
}
diff --git a/i3bar/src/ipc.c b/i3bar/src/ipc.c
index ec5fc06a..b3de145d 100644
--- a/i3bar/src/ipc.c
+++ b/i3bar/src/ipc.c
@@ -170,6 +170,15 @@ static void got_mode_event(char *event) {
draw_bars(false);
}
+static bool strings_differ(char *a, char *b) {
+ const bool a_null = (a == NULL);
+ const bool b_null = (b == NULL);
+ if (a_null != b_null) {
+ return true;
+ }
+ return strcmp(a, b) != 0;
+}
+
/*
* Called, when a barconfig_update event arrives (i.e. i3 changed the bar hidden_state or mode)
*
@@ -190,8 +199,11 @@ static void got_bar_config_update(char *event) {
/* update the configuration with the received settings */
DLOG("Received bar config update \"%s\"\n", event);
- char *old_command = config.command ? sstrdup(config.command) : NULL;
+
+ char *old_command = config.command;
+ config.command = NULL;
bar_display_mode_t old_mode = config.hide_on_modifier;
+
parse_config_json(event);
if (old_mode != config.hide_on_modifier) {
reconfig_windows(true);
@@ -202,8 +214,9 @@ static void got_bar_config_update(char *event) {
init_colors(&(config.colors));
/* restart status command process */
- if (old_command && strcmp(old_command, config.command) != 0) {
+ if (strings_differ(old_command, config.command)) {
kill_child();
+ clear_statusline(&statusline_head, true);
start_child(config.command);
}
free(old_command);