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);
/* 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);
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 */
* 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>
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: ");
/* 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;
}
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;
}
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;
}
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;
}
}
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;
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");
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);
+ }
}
}
*
*/
void got_workspace_reply(char *reply) {
- DLOG("Got Workspace-Data!\n");
+ DLOG("Got workspace data!\n");
parse_workspaces_json(reply);
draw_bars(false);
}
*
*/
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 */
}
*
*/
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);
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);
}
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,
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)
*
*/
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);