Skip to content

Commit 19eae2b

Browse files
committed
Adapt the swaybg call to the new output code
Create a single background config per output that already incorporates all the globbing and merging.
1 parent 6169122 commit 19eae2b

File tree

3 files changed

+22
-26
lines changed

3 files changed

+22
-26
lines changed

sway/commands/output.c

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,18 +97,13 @@ struct cmd_results *cmd_output(int argc, char **argv) {
9797
config->handler_context.leftovers.argc = 0;
9898
config->handler_context.leftovers.argv = NULL;
9999

100-
bool background = output->background;
101-
102100
store_output_config(output);
103101

104102
// If reloading, the output configs will be applied after reading the
105103
// entire config and before the deferred commands so that an auto generated
106104
// workspace name is not given to re-enabled outputs.
107105
if (!config->reloading && !config->validating) {
108106
apply_output_config_to_outputs();
109-
if (background) {
110-
spawn_swaybg();
111-
}
112107
}
113108

114109
return cmd_results_new(CMD_SUCCESS, NULL);

sway/config.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -528,7 +528,6 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
528528
sway_switch_retrigger_bindings_for_all();
529529

530530
reset_outputs();
531-
spawn_swaybg();
532531

533532
config->reloading = false;
534533
if (config->swaynag_config_errors.client != NULL) {

sway/config/output.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,10 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
472472
// this output came online, and some config items (like map_to_output) are
473473
// dependent on an output being present.
474474
input_manager_configure_all_inputs();
475+
476+
// If we've changed the config of an output restart the backgrounds as well
477+
spawn_swaybg();
478+
475479
return true;
476480
}
477481

@@ -507,13 +511,13 @@ static void default_output_config(struct output_config *oc,
507511

508512
struct output_config *find_output_config(struct sway_output *sway_output) {
509513
// Start with a default config for this output
510-
struct output_config *result = new_output_config("merge");
514+
char *name = sway_output->wlr_output->name;
515+
struct output_config *result = new_output_config(name);
511516
default_output_config(result, sway_output->wlr_output);
512517

513518
// Apply all matches in order
514519
char id[128];
515520
output_get_identifier(id, sizeof(id), sway_output);
516-
char *name = sway_output->wlr_output->name;
517521
for (int i = 0; i < config->output_configs->length; ++i) {
518522
struct output_config *oc = config->output_configs->items[i];
519523
if (!fnmatch(oc->name, name, 0) || !fnmatch(oc->name, id, 0)) {
@@ -640,21 +644,8 @@ bool spawn_swaybg(void) {
640644
return true;
641645
}
642646

643-
size_t length = 2;
644-
for (int i = 0; i < config->output_configs->length; i++) {
645-
struct output_config *oc = config->output_configs->items[i];
646-
if (!oc->background) {
647-
continue;
648-
}
649-
if (strcmp(oc->background_option, "solid_color") == 0) {
650-
length += 4;
651-
} else if (oc->background_fallback) {
652-
length += 8;
653-
} else {
654-
length += 6;
655-
}
656-
}
657-
647+
// At most the program, 8 arguments per output and the terminating NULL
648+
size_t length = 2 + wl_list_length(&root->all_outputs) * 8;
658649
char **cmd = calloc(length, sizeof(char *));
659650
if (!cmd) {
660651
sway_log(SWAY_ERROR, "Failed to allocate spawn_swaybg command");
@@ -663,8 +654,13 @@ bool spawn_swaybg(void) {
663654

664655
size_t i = 0;
665656
cmd[i++] = config->swaybg_command;
666-
for (int j = 0; j < config->output_configs->length; j++) {
667-
struct output_config *oc = config->output_configs->items[j];
657+
658+
// Iterate all the outputs and write the command
659+
list_t *output_configs = create_list();
660+
struct sway_output *sway_output, *tmp;
661+
wl_list_for_each_safe(sway_output, tmp, &root->all_outputs, link) {
662+
struct output_config *oc = find_output_config(sway_output);
663+
list_add(output_configs, oc);
668664
if (!oc->background) {
669665
continue;
670666
}
@@ -685,14 +681,20 @@ bool spawn_swaybg(void) {
685681
cmd[i++] = oc->background_fallback;
686682
}
687683
}
688-
assert(i <= length);
684+
assert(i < length);
689685
}
690686

691687
for (size_t k = 0; k < i; k++) {
692688
sway_log(SWAY_DEBUG, "spawn_swaybg cmd[%zd] = %s", k, cmd[k]);
693689
}
694690

695691
bool result = _spawn_swaybg(cmd);
692+
696693
free(cmd);
694+
for (int k = 0; k < output_configs->length; k++) {
695+
free_output_config(output_configs->items[k]);
696+
}
697+
list_free(output_configs);
698+
697699
return result;
698700
}

0 commit comments

Comments
 (0)