]> git.sur5r.net Git - i3/i3/blobdiff - i3bar/src/child.c
remove unused statusline_buffer
[i3/i3] / i3bar / src / child.c
index bc5a53e5cf0e2ca72a7538687729c2f90f9daabb..c0ea36138548066693c9f55851359adcba4cf0b1 100644 (file)
@@ -31,7 +31,7 @@
 i3bar_child child;
 
 /* stdin- and sigchild-watchers */
-ev_io    *stdin_io;
+ev_io *stdin_io;
 ev_child *child_sig;
 
 /* JSON parser for stdin */
@@ -56,7 +56,6 @@ parser_ctx parser_context;
 
 /* The buffer statusline points to */
 struct statusline_head statusline_head = TAILQ_HEAD_INITIALIZER(statusline_head);
-char *statusline_buffer = NULL;
 
 int child_stdin;
 
@@ -80,7 +79,7 @@ static void clear_status_blocks() {
  * `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;
@@ -115,9 +114,6 @@ void cleanup(void) {
     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) {
@@ -188,12 +184,12 @@ static int stdin_string(void *context, const unsigned char *val, size_t len) {
         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);
@@ -201,13 +197,13 @@ static int stdin_string(void *context, const unsigned char *val, size_t 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;
@@ -233,7 +229,7 @@ static int stdin_end_map(void *context) {
     /* 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);
@@ -262,9 +258,9 @@ static unsigned char *get_buffer(ev_io *watcher, int *ret_buffer_len) {
     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) {
@@ -300,9 +296,10 @@ static void read_flat_input(char *buffer, int length) {
     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);
 }
 
@@ -320,7 +317,7 @@ static bool read_json_input(unsigned char *input, int length) {
                 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;
@@ -342,7 +339,7 @@ void stdin_io_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
     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);
@@ -370,13 +367,13 @@ void stdin_io_first_line_cb(struct ev_loop *loop, ev_io *watcher, int revents) {
         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);
@@ -394,8 +391,8 @@ void child_sig_cb(struct ev_loop *loop, ev_child *watcher, int revents) {
     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. */
@@ -450,7 +447,7 @@ void start_child(char *command) {
 
     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)
@@ -473,7 +470,7 @@ void start_child(char *command) {
             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 */
@@ -519,33 +516,35 @@ void child_click_events_key(const char *key) {
  *
  */
 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();
 }
 
 /*