X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=i3bar%2Fsrc%2Foutputs.c;h=480c00be7dd90a1b9e500b3074e87888da64bcbc;hb=f354f534357798eb3ba497b7143132f41ff090f6;hp=02b718d3ae42418ddbcd8899f8aa312cfec5e278;hpb=3c5df50c54ab6451098c2175a21470312952000e;p=i3%2Fi3 diff --git a/i3bar/src/outputs.c b/i3bar/src/outputs.c index 02b718d3..480c00be 100644 --- a/i3bar/src/outputs.c +++ b/i3bar/src/outputs.c @@ -2,11 +2,13 @@ * vim:ts=4:sw=4:expandtab * * i3bar - an xcb-based status- and ws-bar for i3 - * © 2010-2012 Axel Wagner and contributors (see also: LICENSE) + * © 2010 Axel Wagner and contributors (see also: LICENSE) * - * outputs.c: Maintaining the output-list + * outputs.c: Maintaining the outputs list * */ +#include "common.h" + #include #include #include @@ -15,8 +17,6 @@ #include #include -#include "common.h" - /* A datatype to pass through the callbacks to save the state */ struct outputs_json_params { struct outputs_head *outputs; @@ -27,7 +27,7 @@ struct outputs_json_params { }; /* - * Parse a null-value (current_workspace) + * Parse a null value (current_workspace) * */ static int outputs_null_cb(void *params_) { @@ -108,9 +108,8 @@ static int outputs_string_cb(void *params_, const unsigned char *val, size_t len struct outputs_json_params *params = (struct outputs_json_params *)params_; if (!strcmp(params->cur_key, "current_workspace")) { - char *copy = smalloc(sizeof(const unsigned char) * (len + 1)); - strncpy(copy, (const char *)val, len); - copy[len] = '\0'; + char *copy = NULL; + sasprintf(©, "%.*s", len, val); char *end; errno = 0; @@ -118,7 +117,8 @@ static int outputs_string_cb(void *params_, const unsigned char *val, size_t len if (errno == 0 && (end && *end == '\0')) params->outputs_walk->ws = parsed_num; - free(copy); + + FREE(copy); FREE(params->cur_key); return 1; } @@ -127,19 +127,14 @@ static int outputs_string_cb(void *params_, const unsigned char *val, size_t len return 0; } - char *name = smalloc(sizeof(const unsigned char) * (len + 1)); - strncpy(name, (const char *)val, len); - name[len] = '\0'; - - params->outputs_walk->name = name; + sasprintf(&(params->outputs_walk->name), "%.*s", len, val); FREE(params->cur_key); - return 1; } /* - * We hit the start of a json-map (rect or a new output) + * We hit the start of a JSON map (rect or a new output) * */ static int outputs_start_map_cb(void *params_) { @@ -149,9 +144,16 @@ static int outputs_start_map_cb(void *params_) { if (params->cur_key == NULL) { new_output = smalloc(sizeof(i3_output)); new_output->name = NULL; + new_output->active = false; + new_output->primary = false; + new_output->visible = false; new_output->ws = 0, + new_output->statusline_width = 0; + new_output->statusline_short_text = false; memset(&new_output->rect, 0, sizeof(rect)); - new_output->bar = XCB_NONE; + memset(&new_output->bar, 0, sizeof(surface_t)); + memset(&new_output->buffer, 0, sizeof(surface_t)); + memset(&new_output->statusline_buffer, 0, sizeof(surface_t)); new_output->workspaces = smalloc(sizeof(struct ws_head)); TAILQ_INIT(new_output->workspaces); @@ -221,17 +223,13 @@ static int outputs_end_map_cb(void *params_) { /* * Parse a key. * - * Essentially we just save it in the parsing-state + * Essentially we just save it in the parsing state * */ static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) { struct outputs_json_params *params = (struct outputs_json_params *)params_; FREE(params->cur_key); - - params->cur_key = smalloc(sizeof(unsigned char) * (keyLen + 1)); - strncpy(params->cur_key, (const char *)keyVal, keyLen); - params->cur_key[keyLen] = '\0'; - + sasprintf(&(params->cur_key), "%.*s", keyLen, keyVal); return 1; } @@ -247,7 +245,7 @@ static yajl_callbacks outputs_callbacks = { }; /* - * Initiate the output-list + * Initiate the outputs list * */ void init_outputs(void) { @@ -256,7 +254,7 @@ void init_outputs(void) { } /* - * Start parsing the received json-string + * Start parsing the received JSON string * */ void parse_outputs_json(char *json) { @@ -273,13 +271,13 @@ void parse_outputs_json(char *json) { state = yajl_parse(handle, (const unsigned char *)json, strlen(json)); - /* FIXME: Propper errorhandling for JSON-parsing */ + /* FIXME: Proper errorhandling for JSON-parsing */ switch (state) { case yajl_status_ok: break; case yajl_status_client_canceled: case yajl_status_error: - ELOG("Could not parse outputs-reply!\n"); + ELOG("Could not parse outputs reply!\n"); exit(EXIT_FAILURE); break; } @@ -304,3 +302,17 @@ i3_output *get_output_by_name(char *name) { return walk; } + +/* + * Returns true if the output has the currently focused workspace + * + */ +bool output_has_focus(i3_output *output) { + i3_ws *ws_walk; + TAILQ_FOREACH(ws_walk, output->workspaces, tailq) { + if (ws_walk->focused) { + return true; + } + } + return false; +}