i3bar_child child;
/* stdin- and sigchild-watchers */
-ev_io *stdin_io;
+ev_io *stdin_io;
ev_child *child_sig;
/* JSON parser for stdin */
/* The buffer statusline points to */
struct statusline_head statusline_head = TAILQ_HEAD_INITIALIZER(statusline_head);
-char *statusline_buffer = NULL;
int child_stdin;
* `draw_bars' is called, the error message text will be drawn on the bar in
* the space allocated for the statusline.
*/
-__attribute__ ((format (printf, 1, 2))) static void set_statusline_error(const char *format, ...) {
+__attribute__((format(printf, 1, 2))) static void set_statusline_error(const char *format, ...) {
clear_status_blocks();
char *message;
if (stdin_io != NULL) {
ev_io_stop(main_loop, stdin_io);
FREE(stdin_io);
- FREE(statusline_buffer);
- /* statusline pointed to memory within statusline_buffer */
- statusline = NULL;
}
if (child_sig != NULL) {
sasprintf(&(ctx->block.color), "%.*s", len, val);
}
if (strcasecmp(ctx->last_map_key, "align") == 0) {
- if (len == strlen("left") && !strncmp((const char*)val, "left", strlen("left"))) {
- ctx->block.align = ALIGN_LEFT;
- } else if (len == strlen("right") && !strncmp((const char*)val, "right", strlen("right"))) {
+ if (len == strlen("center") && !strncmp((const char *)val, "center", strlen("center"))) {
+ ctx->block.align = ALIGN_CENTER;
+ } else if (len == strlen("right") && !strncmp((const char *)val, "right", strlen("right"))) {
ctx->block.align = ALIGN_RIGHT;
} else {
- ctx->block.align = ALIGN_CENTER;
+ ctx->block.align = ALIGN_LEFT;
}
} else if (strcasecmp(ctx->last_map_key, "min_width") == 0) {
i3String *text = i3string_from_utf8_with_length((const char *)val, len);
i3string_free(text);
}
if (strcasecmp(ctx->last_map_key, "name") == 0) {
- char *copy = (char*)malloc(len+1);
+ char *copy = (char *)malloc(len + 1);
strncpy(copy, (const char *)val, len);
copy[len] = 0;
ctx->block.name = copy;
}
if (strcasecmp(ctx->last_map_key, "instance") == 0) {
- char *copy = (char*)malloc(len+1);
+ char *copy = (char *)malloc(len + 1);
strncpy(copy, (const char *)val, len);
copy[len] = 0;
ctx->block.instance = copy;
/* Ensure we have a full_text set, so that when it is missing (or null),
* i3bar doesn’t crash and the user gets an annoying message. */
if (!new_block->full_text)
- new_block->full_text = i3string_from_utf8("SPEC VIOLATION (null)");
+ new_block->full_text = i3string_from_utf8("SPEC VIOLATION: full_text is NULL!");
if (new_block->urgent)
ctx->has_urgent = true;
TAILQ_INSERT_TAIL(&statusline_head, new_block, blocks);
int n = 0;
int rec = 0;
int buffer_len = STDIN_CHUNK_SIZE;
- unsigned char *buffer = smalloc(buffer_len+1);
+ unsigned char *buffer = smalloc(buffer_len + 1);
buffer[0] = '\0';
- while(1) {
+ while (1) {
n = read(fd, buffer + rec, buffer_len - rec);
if (n == -1) {
if (errno == EAGAIN) {
I3STRING_FREE(first->full_text);
/* Remove the trailing newline and terminate the string at the same
* time. */
- if (buffer[length-1] == '\n' || buffer[length-1] == '\r')
- buffer[length-1] = '\0';
- else buffer[length] = '\0';
+ if (buffer[length - 1] == '\n' || buffer[length - 1] == '\r')
+ buffer[length - 1] = '\0';
+ else
+ buffer[length] = '\0';
first->full_text = i3string_from_utf8(buffer);
}
status, message, length, input);
set_statusline_error("Could not parse JSON (%s)", message);
- yajl_free_error(parser, (unsigned char*)message);
+ yajl_free_error(parser, (unsigned char *)message);
draw_bars(false);
} else if (parser_context.has_urgent) {
has_urgent = true;
if (child.version > 0) {
has_urgent = read_json_input(buffer, rec);
} else {
- read_flat_input((char*)buffer, rec);
+ read_flat_input((char *)buffer, rec);
}
free(buffer);
draw_bars(has_urgent);
if (config.hide_on_modifier) {
stop_child();
}
- read_json_input(buffer + consumed, rec - consumed);
+ draw_bars(read_json_input(buffer + consumed, rec - consumed));
} else {
/* In case of plaintext, we just add a single block and change its
* full_text pointer later. */
struct status_block *new_block = scalloc(sizeof(struct status_block));
TAILQ_INSERT_TAIL(&statusline_head, new_block, blocks);
- read_flat_input((char*)buffer, rec);
+ read_flat_input((char *)buffer, rec);
}
free(buffer);
ev_io_stop(main_loop, stdin_io);
int exit_status = WEXITSTATUS(watcher->rstatus);
ELOG("Child (pid: %d) unexpectedly exited with status %d\n",
- child.pid,
- exit_status);
+ child.pid,
+ exit_status);
/* this error is most likely caused by a user giving a nonexecutable or
* nonexistent file, so we will handle those cases separately. */
gen = yajl_gen_alloc(NULL);
- int pipe_in[2]; /* pipe we read from */
+ int pipe_in[2]; /* pipe we read from */
int pipe_out[2]; /* pipe we write to */
if (pipe(pipe_in) == -1)
dup2(pipe_out[0], STDIN_FILENO);
setpgid(child.pid, 0);
- execl(_PATH_BSHELL, _PATH_BSHELL, "-c", command, (char*) NULL);
+ execl(_PATH_BSHELL, _PATH_BSHELL, "-c", command, (char *)NULL);
return;
default:
/* Parent-process. Reroute streams */
*
*/
void send_block_clicked(int button, const char *name, const char *instance, int x, int y) {
- if (child.click_events) {
- child_click_events_initialize();
+ if (!child.click_events) {
+ return;
+ }
- yajl_gen_map_open(gen);
+ child_click_events_initialize();
- if (name) {
- child_click_events_key("name");
- yajl_gen_string(gen, (const unsigned char *)name, strlen(name));
- }
+ yajl_gen_map_open(gen);
- if (instance) {
- child_click_events_key("instance");
- yajl_gen_string(gen, (const unsigned char *)instance, strlen(instance));
- }
+ if (name) {
+ child_click_events_key("name");
+ yajl_gen_string(gen, (const unsigned char *)name, strlen(name));
+ }
- child_click_events_key("button");
- yajl_gen_integer(gen, button);
+ if (instance) {
+ child_click_events_key("instance");
+ yajl_gen_string(gen, (const unsigned char *)instance, strlen(instance));
+ }
- child_click_events_key("x");
- yajl_gen_integer(gen, x);
+ child_click_events_key("button");
+ yajl_gen_integer(gen, button);
- child_click_events_key("y");
- yajl_gen_integer(gen, y);
+ child_click_events_key("x");
+ yajl_gen_integer(gen, x);
- yajl_gen_map_close(gen);
- child_write_output();
- }
+ child_click_events_key("y");
+ yajl_gen_integer(gen, y);
+
+ yajl_gen_map_close(gen);
+ child_write_output();
}
/*