From: Michael Stapelberg Date: Fri, 21 Oct 2011 21:17:41 +0000 (+0100) Subject: i3bar: Implement the output option X-Git-Tag: 4.1~92^2~12 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=15f021b4fc8097a2870e56008db423dac9f430a1;p=i3%2Fi3 i3bar: Implement the output option --- diff --git a/i3bar/include/config.h b/i3bar/include/config.h index b914954c..c5fc218c 100644 --- a/i3bar/include/config.h +++ b/i3bar/include/config.h @@ -19,6 +19,8 @@ typedef struct config_t { char *command; char *fontname; char *tray_output; + int num_outputs; + char **outputs; } config_t; config_t config; diff --git a/i3bar/src/config.c b/i3bar/src/config.c index 179bc464..9e4552ed 100644 --- a/i3bar/src/config.c +++ b/i3bar/src/config.c @@ -100,8 +100,11 @@ static int config_string_cb(void *params_, const unsigned char *val, unsigned in } if (!strcmp(cur_key, "outputs")) { - printf("+output %.*s\n", len, val); - /* XXX: these are not implemented yet */ + DLOG("+output %.*s\n", len, val); + int new_num_outputs = config.num_outputs + 1; + config.outputs = srealloc(config.outputs, sizeof(char*) * new_num_outputs); + asprintf(&config.outputs[config.num_outputs], "%.*s", len, val); + config.num_outputs = new_num_outputs; return 1; } diff --git a/i3bar/src/outputs.c b/i3bar/src/outputs.c index 98939fb4..6278974f 100644 --- a/i3bar/src/outputs.c +++ b/i3bar/src/outputs.c @@ -26,7 +26,7 @@ struct outputs_json_params { i3_output *outputs_walk; char *cur_key; char *json; - bool init; + bool in_rect; }; /* @@ -171,6 +171,10 @@ static int outputs_start_map_cb(void *params_) { return 1; } + if (!strcmp(params->cur_key, "rect")) { + params->in_rect = true; + } + return 1; } @@ -180,7 +184,33 @@ static int outputs_start_map_cb(void *params_) { */ static int outputs_end_map_cb(void *params_) { struct outputs_json_params *params = (struct outputs_json_params*) params_; - /* FIXME: What is at the end of a rect? */ + if (params->in_rect) { + params->in_rect = false; + /* Ignore the end of a rect */ + return 1; + } + + /* See if we actually handle that output */ + if (config.num_outputs > 0) { + bool handle_output = false; + for (int c = 0; c < config.num_outputs; c++) { + if (strcasecmp(params->outputs_walk->name, config.outputs[c]) != 0) + continue; + + handle_output = true; + break; + } + if (!handle_output) { + DLOG("Ignoring output \"%s\", not configured to handle it.\n", + params->outputs_walk->name); + FREE(params->outputs_walk->name); + FREE(params->outputs_walk->workspaces); + FREE(params->outputs_walk->trayclients); + FREE(params->outputs_walk); + FREE(params->cur_key); + return 1; + } + } i3_output *target = get_output_by_name(params->outputs_walk->name); @@ -249,6 +279,7 @@ void parse_outputs_json(char *json) { params.outputs_walk = NULL; params.cur_key = NULL; params.json = json; + params.in_rect = false; yajl_handle handle; yajl_status state; diff --git a/i3bar/src/workspaces.c b/i3bar/src/workspaces.c index c2bb886c..bb00f0ba 100644 --- a/i3bar/src/workspaces.c +++ b/i3bar/src/workspaces.c @@ -144,11 +144,14 @@ static int workspaces_string_cb(void *params_, const unsigned char *val, unsigne output_name = smalloc(sizeof(const unsigned char) * (len + 1)); strncpy(output_name, (const char*) val, len); output_name[len] = '\0'; - params->workspaces_walk->output = get_output_by_name(output_name); + i3_output *target = get_output_by_name(output_name); + if (target) { + params->workspaces_walk->output = target; - TAILQ_INSERT_TAIL(params->workspaces_walk->output->workspaces, - params->workspaces_walk, - tailq); + TAILQ_INSERT_TAIL(params->workspaces_walk->output->workspaces, + params->workspaces_walk, + tailq); + } FREE(output_name); return 1;