ipc: Canonicalize output names in bar configuration

Convert the output names specified in the "output" and "tray_output"
fields in bar blocks in i3's configuration to the referred output's
primary name. This allows specifying names other than the primary
output's name in the given fields without changing the IPC protocol.
This commit is contained in:
Vladimir Panteleev 2017-09-11 11:15:56 +00:00
parent ae8f3c2679
commit 6de9cdd96f
No known key found for this signature in database
GPG Key ID: 5004F0FAD051576D
1 changed files with 13 additions and 3 deletions

View File

@ -579,6 +579,11 @@ static void dump_bar_bindings(yajl_gen gen, Barconfig *config) {
y(array_close); y(array_close);
} }
static char *canonicalize_output_name(char *name) {
Output *output = get_output_by_name(name, false);
return output ? output_primary_name(output) : name;
}
static void dump_bar_config(yajl_gen gen, Barconfig *config) { static void dump_bar_config(yajl_gen gen, Barconfig *config) {
y(map_open); y(map_open);
@ -588,8 +593,13 @@ static void dump_bar_config(yajl_gen gen, Barconfig *config) {
if (config->num_outputs > 0) { if (config->num_outputs > 0) {
ystr("outputs"); ystr("outputs");
y(array_open); y(array_open);
for (int c = 0; c < config->num_outputs; c++) for (int c = 0; c < config->num_outputs; c++) {
ystr(config->outputs[c]); /* Convert monitor names (RandR ≥ 1.5) or output names
* (RandR < 1.5) into monitor names. This way, existing
* configs which use output names transparently keep
* working. */
ystr(canonicalize_output_name(config->outputs[c]));
}
y(array_close); y(array_close);
} }
@ -599,7 +609,7 @@ static void dump_bar_config(yajl_gen gen, Barconfig *config) {
struct tray_output_t *tray_output; struct tray_output_t *tray_output;
TAILQ_FOREACH(tray_output, &(config->tray_outputs), tray_outputs) { TAILQ_FOREACH(tray_output, &(config->tray_outputs), tray_outputs) {
ystr(tray_output->output); ystr(canonicalize_output_name(tray_output->output));
} }
y(array_close); y(array_close);