swaybar: fix whitespace

master
progandy 9 years ago
parent 70b24fbb1f
commit d37169a927

@ -46,13 +46,13 @@ struct workspace {
}; };
struct status_block { struct status_block {
char *full_text, *short_text, *align; char *full_text, *short_text, *align;
bool urgent; bool urgent;
uint32_t color; uint32_t color;
int min_width; int min_width;
char *name, *instance; char *name, *instance;
bool separator; bool separator;
int separator_block_width; int separator_block_width;
}; };
list_t *status_line = NULL; list_t *status_line = NULL;
@ -375,21 +375,21 @@ void render() {
cairo_set_source_u32(window->cairo, colors.statusline); cairo_set_source_u32(window->cairo, colors.statusline);
int width, height; int width, height;
if (status_line) { if (status_line) {
int i; int i;
int moved = 0; int moved = 0;
for ( i = status_line->length - 1; i >= 0; --i ) { for ( i = status_line->length - 1; i >= 0; --i ) {
struct status_block *block = status_line->items[i]; struct status_block *block = status_line->items[i];
if (block->full_text) { if (block->full_text) {
get_text_size(window, &width, &height, "%s", block->full_text); get_text_size(window, &width, &height, "%s", block->full_text);
moved += width + block->separator_block_width; moved += width + block->separator_block_width;
cairo_move_to(window->cairo, window->width - margin - moved, margin); cairo_move_to(window->cairo, window->width - margin - moved, margin);
cairo_set_source_u32(window->cairo, block->color); cairo_set_source_u32(window->cairo, block->color);
pango_printf(window, "%s", block->full_text); pango_printf(window, "%s", block->full_text);
} }
} }
} }
// Workspaces // Workspaces
cairo_set_line_width(window->cairo, 1.0); cairo_set_line_width(window->cairo, 1.0);
double x = 0.5; double x = 0.5;
@ -425,124 +425,118 @@ void render() {
} }
void parse_json(const char *text) { void parse_json(const char *text) {
/* the array of objects looks like this:
/* * [ {
* { * "full_text": "E: 10.0.0.1 (1000 Mbit/s)",
"full_text": "E: 10.0.0.1 (1000 Mbit/s)", * "short_text": "10.0.0.1",
"short_text": "10.0.0.1", * "color": "#00ff00",
"color": "#00ff00", * "min_width": 300,
"min_width": 300, * "align": "right",
"align": "right", * "urgent": false,
"urgent": false, * "name": "ethernet",
"name": "ethernet", * "instance": "eth0",
"instance": "eth0", * "separator": true,
"separator": true, * "separator_block_width": 9
"separator_block_width": 9 * },
} * { ... }, ...
* * ]
* */
*
* */
json_object *results = json_tokener_parse(text); json_object *results = json_tokener_parse(text);
if (!results) { if (!results) {
sway_log(L_DEBUG, "xxx Failed to parse json"); sway_log(L_DEBUG, "xxx Failed to parse json");
return; return;
} }
if (json_object_array_length(results) < 1) { if (json_object_array_length(results) < 1) {
return; return;
} }
if (status_line) { if (status_line) {
free_flat_list(status_line); free_flat_list(status_line);
} }
status_line = create_list(); status_line = create_list();
int i; int i;
for (i = 0; i < json_object_array_length(results); ++i) { for (i = 0; i < json_object_array_length(results); ++i) {
json_object *full_text, *short_text, *color, *min_width, *align, *urgent; json_object *full_text, *short_text, *color, *min_width, *align, *urgent;
json_object *name, *instance, *separator, *separator_block_width; json_object *name, *instance, *separator, *separator_block_width;
json_object *json = json_object_array_get_idx(results, i); json_object *json = json_object_array_get_idx(results, i);
if (!json) {
if (!json) { continue;
continue; }
}
json_object_object_get_ex(json, "full_text", &full_text);
json_object_object_get_ex(json, "full_text", &full_text); json_object_object_get_ex(json, "short_text", &short_text);
json_object_object_get_ex(json, "short_text", &short_text); json_object_object_get_ex(json, "color", &color);
json_object_object_get_ex(json, "color", &color); json_object_object_get_ex(json, "min_width", &min_width);
json_object_object_get_ex(json, "min_width", &min_width); json_object_object_get_ex(json, "align", &align);
json_object_object_get_ex(json, "align", &align); json_object_object_get_ex(json, "urgent", &urgent);
json_object_object_get_ex(json, "urgent", &urgent); json_object_object_get_ex(json, "name", &name);
json_object_object_get_ex(json, "name", &name); json_object_object_get_ex(json, "instance", &instance);
json_object_object_get_ex(json, "instance", &instance); json_object_object_get_ex(json, "separator", &separator);
json_object_object_get_ex(json, "separator", &separator); json_object_object_get_ex(json, "separator_block_width", &separator_block_width);
json_object_object_get_ex(json, "separator_block_width", &separator_block_width);
struct status_block *new = malloc(sizeof(struct status_block));
struct status_block *new = malloc(sizeof(struct status_block)); memset(new, 0, sizeof(struct status_block));
memset(new, 0, sizeof(struct status_block));
if (full_text) {
if (full_text) { new->full_text = strdup(json_object_get_string(full_text));
new->full_text = strdup(json_object_get_string(full_text)); }
}
if (short_text) {
if (short_text) { new->short_text = strdup(json_object_get_string(short_text));
new->short_text = strdup(json_object_get_string(short_text)); }
}
if (color) {
if (color) { new->color = parse_color(json_object_get_string(color));
new->color = parse_color(json_object_get_string(color)); }
} else {
else { new->color = 0xFFFFFFFF;
new->color = 0xFFFFFFFF; }
}
if (min_width) {
if (min_width) { new->min_width = json_object_get_int(min_width);
new->min_width = json_object_get_int(min_width); }
}
if (align) {
if (align) { new->align = strdup(json_object_get_string(align));
new->align = strdup(json_object_get_string(align)); }
} else {
else { new->align = strdup("left");
new->align = strdup("left"); }
}
if (urgent) {
if (urgent) { new->urgent = json_object_get_int(urgent);
new->urgent = json_object_get_int(urgent); }
}
if (name) {
if (name) { new->name = strdup(json_object_get_string(name));
new->name = strdup(json_object_get_string(name)); }
}
if (instance) {
if (instance) { new->instance = strdup(json_object_get_string(instance));
new->instance = strdup(json_object_get_string(instance)); }
}
if (separator) {
if (separator) { new->separator = json_object_get_int(separator);
new->separator = json_object_get_int(separator); }
} else {
else { new->separator = true; // i3bar spec
new->separator = true; // i3bar spec }
}
if (separator_block_width) {
if (separator_block_width) { new->separator_block_width = json_object_get_int(separator_block_width);
new->separator_block_width = json_object_get_int(separator_block_width); }
} else {
else { new->separator_block_width = 9; // i3bar spec
new->separator_block_width = 9; // i3bar spec }
}
list_add(status_line, new); list_add(status_line, new);
}
}
json_object_put(results); json_object_put(results);
} }
void poll_for_update() { void poll_for_update() {
@ -581,16 +575,16 @@ void poll_for_update() {
if (status_command && FD_ISSET(pipefd[0], &readfds)) { if (status_command && FD_ISSET(pipefd[0], &readfds)) {
sway_log(L_DEBUG, "Got update from status command."); sway_log(L_DEBUG, "Got update from status command.");
fgets(line, sizeof(line), command); fgets(line, sizeof(line), command);
sway_log(L_DEBUG, "zzz %s", line); sway_log(L_DEBUG, "zzz %s", line);
int l = strlen(line) - 1; int l = strlen(line) - 1;
if (line[l] == '\n') { if (line[l] == '\n') {
line[l] = '\0'; line[l] = '\0';
} }
if (line[0] == ',') { if (line[0] == ',') {
line[0] = ' '; line[0] = ' ';
} }
dirty = true; dirty = true;
parse_json(line); parse_json(line);
} }
} }
} }

Loading…
Cancel
Save