]> git.sur5r.net Git - i3/i3/commitdiff
Merge pull request #1575 from hwangcc23/next
authorMichael Stapelberg <stapelberg@users.noreply.github.com>
Sun, 29 Mar 2015 14:53:14 +0000 (16:53 +0200)
committerMichael Stapelberg <stapelberg@users.noreply.github.com>
Sun, 29 Mar 2015 14:53:14 +0000 (16:53 +0200)
Fix warnings

1  2 
i3-nagbar/main.c
i3bar/src/child.c
i3bar/src/ipc.c

diff --combined i3-nagbar/main.c
index 805066f82d56b5a9002a0a836383356602b231cc,91de317fb67084e8b9dfa3dae2de2f2b4238ccd3..bf6d1cca41f29a6ba39bec468c677ef3571b2734
@@@ -131,7 -131,7 +131,7 @@@ static void handle_button_release(xcb_c
      printf("button released on x = %d, y = %d\n",
             event->event_x, event->event_y);
      /* If the user hits the close button, we exit(0) */
 -    if (event->event_x >= (rect.width - 32))
 +    if (event->event_x >= (rect.width - logical_px(32)))
          exit(0);
      button_t *button = get_button_at(event->event_x, event->event_y);
      if (!button)
      char *link_path;
      char *exe_path = get_exe_path(argv0);
      sasprintf(&link_path, "%s.nagbar_cmd", script_path);
-     symlink(exe_path, link_path);
+     if (symlink(exe_path, link_path) == -1) {
+         err(EXIT_FAILURE, "Failed to symlink %s to %s", link_path, exe_path);
+     }
  
      char *terminal_cmd;
      sasprintf(&terminal_cmd, "i3-sensible-terminal -e %s", link_path);
@@@ -194,17 -196,15 +196,17 @@@ static int handle_expose(xcb_connection
      /* restore font color */
      set_font_colors(pixmap_gc, color_text, color_background);
      draw_text(prompt, pixmap, pixmap_gc,
 -              4 + 4, 4 + 4, rect.width - 4 - 4);
 +              logical_px(4) + logical_px(4),
 +              logical_px(4) + logical_px(4),
 +              rect.width - logical_px(4) - logical_px(4));
  
      /* render close button */
      const char *close_button_label = "X";
 -    int line_width = 4;
 +    int line_width = logical_px(4);
      /* set width to the width of the label */
      int w = predict_text_width(i3string_from_utf8(close_button_label));
      /* account for left/right padding, which seems to be set to 8px (total) below */
 -    w += 8;
 +    w += logical_px(8);
      int y = rect.width;
      uint32_t values[3];
      values[0] = color_button_background;
      xcb_point_t points[] = {
          {y - w - (2 * line_width), line_width / 2},
          {y - (line_width / 2), line_width / 2},
 -        {y - (line_width / 2), (rect.height - (line_width / 2)) - 2},
 -        {y - w - (2 * line_width), (rect.height - (line_width / 2)) - 2},
 +        {y - (line_width / 2), (rect.height - (line_width / 2)) - logical_px(2)},
 +        {y - w - (2 * line_width), (rect.height - (line_width / 2)) - logical_px(2)},
          {y - w - (2 * line_width), line_width / 2}};
      xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, pixmap, pixmap_gc, 5, points);
  
      values[0] = 1;
      set_font_colors(pixmap_gc, color_text, color_button_background);
      /* the x term here seems to set left/right padding */
 -    draw_text_ascii(close_button_label, pixmap, pixmap_gc, y - w - line_width + w / 2 - 4,
 -                    4 + 4 - 1, rect.width - y + w + line_width - w / 2 + 4);
 +    draw_text_ascii(close_button_label, pixmap, pixmap_gc,
 +                    y - w - line_width + w / 2 - logical_px(4),
 +                    logical_px(4) + logical_px(3),
 +                    rect.width - y + w + line_width - w / 2 + logical_px(4));
      y -= w;
  
 -    y -= 20;
 +    y -= logical_px(20);
  
      /* render custom buttons */
      line_width = 1;
          /* set w to the width of the label */
          w = predict_text_width(buttons[c].label);
          /* account for left/right padding, which seems to be set to 12px (total) below */
 -        w += 12;
 -        y -= 30;
 +        w += logical_px(12);
 +        y -= logical_px(30);
          xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){color_button_background});
 -        close = (xcb_rectangle_t){y - w - (2 * line_width), 2, w + (2 * line_width), rect.height - 6};
 +        close = (xcb_rectangle_t){y - w - (2 * line_width), logical_px(2), w + (2 * line_width), rect.height - logical_px(6)};
          xcb_poly_fill_rectangle(conn, pixmap, pixmap_gc, 1, &close);
  
          xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND, (uint32_t[]){color_border});
          buttons[c].x = y - w - (2 * line_width);
          buttons[c].width = w;
          xcb_point_t points2[] = {
 -            {y - w - (2 * line_width), (line_width / 2) + 2},
 -            {y - (line_width / 2), (line_width / 2) + 2},
 -            {y - (line_width / 2), (rect.height - 4 - (line_width / 2))},
 -            {y - w - (2 * line_width), (rect.height - 4 - (line_width / 2))},
 -            {y - w - (2 * line_width), (line_width / 2) + 2}};
 +            {y - w - (2 * line_width), (line_width / 2) + logical_px(2)},
 +            {y - (line_width / 2), (line_width / 2) + logical_px(2)},
 +            {y - (line_width / 2), (rect.height - logical_px(4) - (line_width / 2))},
 +            {y - w - (2 * line_width), (rect.height - logical_px(4) - (line_width / 2))},
 +            {y - w - (2 * line_width), (line_width / 2) + logical_px(2)}};
          xcb_poly_line(conn, XCB_COORD_MODE_ORIGIN, pixmap, pixmap_gc, 5, points2);
  
          values[0] = color_text;
          set_font_colors(pixmap_gc, color_text, color_button_background);
          /* the x term seems to set left/right padding */
          draw_text(buttons[c].label, pixmap, pixmap_gc,
 -                  y - w - line_width + 6, 4 + 3, rect.width - y + w + line_width - 6);
 +                  y - w - line_width + logical_px(6),
 +                  logical_px(4) + logical_px(3),
 +                  rect.width - y + w + line_width - logical_px(6));
  
          y -= w;
      }
  
      /* border line at the bottom */
 -    line_width = 2;
 +    line_width = logical_px(2);
      values[0] = color_border_bottom;
      values[1] = line_width;
      xcb_change_gc(conn, pixmap_gc, XCB_GC_FOREGROUND | XCB_GC_LINE_WIDTH, values);
@@@ -322,7 -318,7 +324,7 @@@ int main(int argc, char *argv[]) 
  
      argv0 = argv[0];
  
 -    char *pattern = sstrdup("-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1");
 +    char *pattern = sstrdup("pango:monospace 8");
      int o, option_index = 0;
      enum { TYPE_ERROR = 0,
             TYPE_WARNING = 1 } bar_type = TYPE_ERROR;
      xcb_create_window(
          conn,
          XCB_COPY_FROM_PARENT,
 -        win,                                                 /* the window id */
 -        root,                                                /* parent == root */
 -        50, 50, 500, font.height + 8 + 8 /* 8 px padding */, /* dimensions */
 -        0,                                                   /* x11 border = 0, we draw our own */
 +        win,                                                                         /* the window id */
 +        root,                                                                        /* parent == root */
 +        50, 50, 500, font.height + logical_px(8) + logical_px(8) /* 8 px padding */, /* dimensions */
 +        0,                                                                           /* x11 border = 0, we draw our own */
          XCB_WINDOW_CLASS_INPUT_OUTPUT,
          XCB_WINDOW_CLASS_COPY_FROM_PARENT, /* copy visual from parent */
          XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK,
      } __attribute__((__packed__)) strut_partial;
      memset(&strut_partial, 0, sizeof(strut_partial));
  
 -    strut_partial.top = font.height + 6;
 +    strut_partial.top = font.height + logical_px(6);
      strut_partial.top_start_x = 0;
      strut_partial.top_end_x = 800;
  
      /* Create pixmap */
      pixmap = xcb_generate_id(conn);
      pixmap_gc = xcb_generate_id(conn);
 -    xcb_create_pixmap(conn, root_screen->root_depth, pixmap, win, 500, font.height + 8);
 +    xcb_create_pixmap(conn, root_screen->root_depth, pixmap, win, 500, font.height + logical_px(8));
      xcb_create_gc(conn, pixmap_gc, pixmap, 0, 0);
  
      /* Grab the keyboard to get all input */
diff --combined i3bar/src/child.c
index 779f8381734854edf8cab4ec9944247a52fbfd65,818ce7841e88969d3a58b34ef97c1fb55e2d95fb..9cc50f2a25f7b5e3a3d9bb0981ecc4ea93ee8be3
@@@ -4,7 -4,7 +4,7 @@@
   * i3bar - an xcb-based status- and ws-bar for i3
   * © 2010-2012 Axel Wagner and contributors (see also: LICENSE)
   *
 - * child.c: Getting Input for the statusline
 + * child.c: Getting input for the statusline
   *
   */
  #include <stdlib.h>
@@@ -103,7 -103,7 +103,7 @@@ __attribute__((format(printf, 1, 2))) s
      char *message;
      va_list args;
      va_start(args, format);
-     vasprintf(&message, format, args);
+     (void)vasprintf(&message, format, args);
  
      struct status_block *err_block = scalloc(sizeof(struct status_block));
      err_block->full_text = i3string_from_utf8("Error: ");
@@@ -164,6 -164,9 +164,6 @@@ static int stdin_start_map(void *contex
      /* Default width of the separator block. */
      ctx->block.sep_block_width = logical_px(9);
  
 -    /* Use markup by default */
 -    ctx->block.is_markup = true;
 -
      return 1;
  }
  
@@@ -178,13 -181,10 +178,13 @@@ static int stdin_boolean(void *context
      parser_ctx *ctx = context;
      if (strcasecmp(ctx->last_map_key, "urgent") == 0) {
          ctx->block.urgent = val;
 +        return 1;
      }
      if (strcasecmp(ctx->last_map_key, "separator") == 0) {
          ctx->block.no_separator = !val;
 +        return 1;
      }
 +
      return 1;
  }
  
@@@ -192,19 -192,15 +192,19 @@@ static int stdin_string(void *context, 
      parser_ctx *ctx = context;
      if (strcasecmp(ctx->last_map_key, "full_text") == 0) {
          ctx->block.full_text = i3string_from_markup_with_length((const char *)val, len);
 +        return 1;
      }
      if (strcasecmp(ctx->last_map_key, "short_text") == 0) {
          ctx->block.short_text = i3string_from_markup_with_length((const char *)val, len);
 +        return 1;
      }
      if (strcasecmp(ctx->last_map_key, "color") == 0) {
          sasprintf(&(ctx->block.color), "%.*s", len, val);
 +        return 1;
      }
      if (strcasecmp(ctx->last_map_key, "markup") == 0) {
          ctx->block.is_markup = (len == strlen("pango") && !strncasecmp((const char *)val, "pango", strlen("pango")));
 +        return 1;
      }
      if (strcasecmp(ctx->last_map_key, "align") == 0) {
          if (len == strlen("center") && !strncmp((const char *)val, "center", strlen("center"))) {
          } else {
              ctx->block.align = ALIGN_LEFT;
          }
 -    } else if (strcasecmp(ctx->last_map_key, "min_width") == 0) {
 +        return 1;
 +    }
 +    if (strcasecmp(ctx->last_map_key, "min_width") == 0) {
          char *copy = (char *)malloc(len + 1);
          strncpy(copy, (const char *)val, len);
          copy[len] = 0;
          ctx->block.min_width_str = copy;
 +        return 1;
      }
      if (strcasecmp(ctx->last_map_key, "name") == 0) {
          char *copy = (char *)malloc(len + 1);
          strncpy(copy, (const char *)val, len);
          copy[len] = 0;
          ctx->block.name = copy;
 +        return 1;
      }
      if (strcasecmp(ctx->last_map_key, "instance") == 0) {
          char *copy = (char *)malloc(len + 1);
          strncpy(copy, (const char *)val, len);
          copy[len] = 0;
          ctx->block.instance = copy;
 +        return 1;
      }
 +
      return 1;
  }
  
@@@ -245,13 -235,10 +245,13 @@@ static int stdin_integer(void *context
      parser_ctx *ctx = context;
      if (strcasecmp(ctx->last_map_key, "min_width") == 0) {
          ctx->block.min_width = (uint32_t)val;
 +        return 1;
      }
      if (strcasecmp(ctx->last_map_key, "separator_block_width") == 0) {
          ctx->block.sep_block_width = (uint32_t)val;
 +        return 1;
      }
 +
      return 1;
  }
  
@@@ -278,9 -265,7 +278,9 @@@ static int stdin_end_map(void *context
      }
  
      i3string_set_markup(new_block->full_text, new_block->is_markup);
 -    i3string_set_markup(new_block->short_text, new_block->is_markup);
 +
 +    if (new_block->short_text != NULL)
 +        i3string_set_markup(new_block->short_text, new_block->is_markup);
  
      TAILQ_INSERT_TAIL(&statusline_buffer, new_block, blocks);
      return 1;
@@@ -299,7 -284,7 +299,7 @@@ static int stdin_end_array(void *contex
      struct status_block *current;
      TAILQ_FOREACH(current, &statusline_head, blocks) {
          DLOG("full_text = %s\n", i3string_as_utf8(current->full_text));
 -        DLOG("short_text = %s\n", i3string_as_utf8(current->short_text));
 +        DLOG("short_text = %s\n", (current->short_text == NULL ? NULL : i3string_as_utf8(current->short_text)));
          DLOG("color = %s\n", current->color);
      }
      DLOG("end of dump\n");
@@@ -470,11 -455,22 +470,22 @@@ void child_write_output(void) 
      if (child.click_events) {
          const unsigned char *output;
          size_t size;
+         ssize_t n;
  
          yajl_gen_get_buf(gen, &output, &size);
-         write(child_stdin, output, size);
-         write(child_stdin, "\n", 1);
+         n = writeall(child_stdin, output, size);
+         if (n != -1)
+             n = writeall(child_stdin, "\n", 1);
          yajl_gen_clear(gen);
+         if (n == -1) {
+             child.click_events = false;
+             kill_child();
+             set_statusline_error("child_write_output failed");
+             draw_bars(false);
+         }
      }
  }
  
diff --combined i3bar/src/ipc.c
index ff6f57795cea3aa7e0f722c345521ebf8a6b94e7,edc9d73f0bf7e9719d1836e82cb31daa51607c3c..15a26d7b4eb42b502fa3ca1a45d01cee90bc42d3
@@@ -40,7 -40,7 +40,7 @@@ void got_command_reply(char *reply) 
   *
   */
  void got_workspace_reply(char *reply) {
 -    DLOG("Got Workspace-Data!\n");
 +    DLOG("Got workspace data!\n");
      parse_workspaces_json(reply);
      draw_bars(false);
  }
@@@ -51,7 -51,7 +51,7 @@@
   *
   */
  void got_subscribe_reply(char *reply) {
 -    DLOG("Got Subscribe Reply: %s\n", reply);
 +    DLOG("Got subscribe reply: %s\n", reply);
      /* TODO: Error handling for subscribe commands */
  }
  
@@@ -60,9 -60,9 +60,9 @@@
   *
   */
  void got_output_reply(char *reply) {
 -    DLOG("Parsing Outputs-JSON...\n");
 +    DLOG("Parsing outputs JSON...\n");
      parse_outputs_json(reply);
 -    DLOG("Reconfiguring Windows...\n");
 +    DLOG("Reconfiguring windows...\n");
      realloc_sl_buffer();
      reconfig_windows(false);
  
@@@ -104,7 -104,7 +104,7 @@@ void got_bar_config(char *reply) 
      FREE(config.command);
  }
  
 -/* Data-structure to easily call the reply handlers later */
 +/* Data structure to easily call the reply handlers later */
  handler_t reply_handlers[] = {
      &got_command_reply,
      &got_workspace_reply,
   *
   */
  void got_workspace_event(char *event) {
 -    DLOG("Got Workspace Event!\n");
 +    DLOG("Got workspace event!\n");
      i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
  }
  
  /*
 - * Called, when an output event arrives (i.e. the screen-configuration changed)
 + * Called, when an output event arrives (i.e. the screen configuration changed)
   *
   */
  void got_output_event(char *event) {
 -    DLOG("Got Output Event!\n");
 +    DLOG("Got output event!\n");
      i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_OUTPUTS, NULL);
      if (!config.disable_ws) {
          i3_send_msg(I3_IPC_MESSAGE_TYPE_GET_WORKSPACES, NULL);
   *
   */
  void got_mode_event(char *event) {
 -    DLOG("Got Mode Event!\n");
 +    DLOG("Got mode event!\n");
      parse_mode_json(event);
      draw_bars(false);
  }
@@@ -180,7 -180,7 +180,7 @@@ void got_bar_config_update(char *event
      draw_bars(false);
  }
  
 -/* Data-structure to easily call the event handlers later */
 +/* Data structure to easily call the event handlers later */
  handler_t event_handlers[] = {
      &got_workspace_event,
      &got_output_event,
@@@ -201,7 -201,7 +201,7 @@@ void got_data(struct ev_loop *loop, ev_
      uint32_t header_len = strlen(I3_IPC_MAGIC) + sizeof(uint32_t) * 2;
      char *header = smalloc(header_len);
  
 -    /* We first parse the fixed-length IPC-header, to know, how much data
 +    /* We first parse the fixed-length IPC header, to know, how much data
       * we have to expect */
      uint32_t rec = 0;
      while (rec < header_len) {
  }
  
  /*
 - * Sends a Message to i3.
 + * Sends a message to i3.
   * type must be a valid I3_IPC_MESSAGE_TYPE (see i3/ipc.h for further information)
   *
   */
@@@ -296,18 -296,7 +296,7 @@@ int i3_send_msg(uint32_t type, const ch
      if (payload != NULL)
          strncpy(walk, payload, len);
  
-     uint32_t written = 0;
-     while (to_write > 0) {
-         int n = write(i3_connection->fd, buffer + written, to_write);
-         if (n == -1) {
-             ELOG("write() failed: %s\n", strerror(errno));
-             exit(EXIT_FAILURE);
-         }
-         to_write -= n;
-         written += n;
-     }
+     swrite(i3_connection->fd, buffer, to_write);
  
      FREE(buffer);