i3bar: Implement the output option
This commit is contained in:
parent
6de1590e59
commit
15f021b4fc
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue