mirror of
https://github.com/swaywm/sway.git
synced 2026-04-25 06:46:24 -04:00
Adapt the swaybg call to the new output code
Create a single background config per output that already incorporates all the globbing and merging.
This commit is contained in:
parent
f85ea8c39f
commit
139c4c5f74
3 changed files with 22 additions and 26 deletions
|
|
@ -97,8 +97,6 @@ struct cmd_results *cmd_output(int argc, char **argv) {
|
|||
config->handler_context.leftovers.argc = 0;
|
||||
config->handler_context.leftovers.argv = NULL;
|
||||
|
||||
bool background = output->background;
|
||||
|
||||
store_output_config(output);
|
||||
|
||||
// If reloading, the output configs will be applied after reading the
|
||||
|
|
@ -106,9 +104,6 @@ struct cmd_results *cmd_output(int argc, char **argv) {
|
|||
// workspace name is not given to re-enabled outputs.
|
||||
if (!config->reloading && !config->validating) {
|
||||
apply_output_config_to_outputs();
|
||||
if (background) {
|
||||
spawn_swaybg();
|
||||
}
|
||||
}
|
||||
|
||||
return cmd_results_new(CMD_SUCCESS, NULL);
|
||||
|
|
|
|||
|
|
@ -528,7 +528,6 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
|
|||
sway_switch_retrigger_bindings_for_all();
|
||||
|
||||
reset_outputs();
|
||||
spawn_swaybg();
|
||||
|
||||
config->reloading = false;
|
||||
if (config->swaynag_config_errors.client != NULL) {
|
||||
|
|
|
|||
|
|
@ -472,6 +472,10 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
|||
// this output came online, and some config items (like map_to_output) are
|
||||
// dependent on an output being present.
|
||||
input_manager_configure_all_inputs();
|
||||
|
||||
// If we've changed the config of an output restart the backgrounds as well
|
||||
spawn_swaybg();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -507,13 +511,13 @@ static void default_output_config(struct output_config *oc,
|
|||
|
||||
struct output_config *find_output_config(struct sway_output *sway_output) {
|
||||
// Start with a default config for this output
|
||||
struct output_config *result = new_output_config("merge");
|
||||
char *name = sway_output->wlr_output->name;
|
||||
struct output_config *result = new_output_config(name);
|
||||
default_output_config(result, sway_output->wlr_output);
|
||||
|
||||
// Apply all matches in order
|
||||
char id[128];
|
||||
output_get_identifier(id, sizeof(id), sway_output);
|
||||
char *name = sway_output->wlr_output->name;
|
||||
for (int i = 0; i < config->output_configs->length; ++i) {
|
||||
struct output_config *oc = config->output_configs->items[i];
|
||||
if (!fnmatch(oc->name, name, 0) || !fnmatch(oc->name, id, 0)) {
|
||||
|
|
@ -640,21 +644,8 @@ bool spawn_swaybg(void) {
|
|||
return true;
|
||||
}
|
||||
|
||||
size_t length = 2;
|
||||
for (int i = 0; i < config->output_configs->length; i++) {
|
||||
struct output_config *oc = config->output_configs->items[i];
|
||||
if (!oc->background) {
|
||||
continue;
|
||||
}
|
||||
if (strcmp(oc->background_option, "solid_color") == 0) {
|
||||
length += 4;
|
||||
} else if (oc->background_fallback) {
|
||||
length += 8;
|
||||
} else {
|
||||
length += 6;
|
||||
}
|
||||
}
|
||||
|
||||
// At most the program, 8 arguments per output and the terminating NULL
|
||||
size_t length = 2 + wl_list_length(&root->all_outputs) * 8;
|
||||
char **cmd = calloc(length, sizeof(char *));
|
||||
if (!cmd) {
|
||||
sway_log(SWAY_ERROR, "Failed to allocate spawn_swaybg command");
|
||||
|
|
@ -663,8 +654,13 @@ bool spawn_swaybg(void) {
|
|||
|
||||
size_t i = 0;
|
||||
cmd[i++] = config->swaybg_command;
|
||||
for (int j = 0; j < config->output_configs->length; j++) {
|
||||
struct output_config *oc = config->output_configs->items[j];
|
||||
|
||||
// Iterate all the outputs and write the command
|
||||
list_t *output_configs = create_list();
|
||||
struct sway_output *sway_output, *tmp;
|
||||
wl_list_for_each_safe(sway_output, tmp, &root->all_outputs, link) {
|
||||
struct output_config *oc = find_output_config(sway_output);
|
||||
list_add(output_configs, oc);
|
||||
if (!oc->background) {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -685,7 +681,7 @@ bool spawn_swaybg(void) {
|
|||
cmd[i++] = oc->background_fallback;
|
||||
}
|
||||
}
|
||||
assert(i <= length);
|
||||
assert(i < length);
|
||||
}
|
||||
|
||||
for (size_t k = 0; k < i; k++) {
|
||||
|
|
@ -693,6 +689,12 @@ bool spawn_swaybg(void) {
|
|||
}
|
||||
|
||||
bool result = _spawn_swaybg(cmd);
|
||||
|
||||
free(cmd);
|
||||
for (int k = 0; k < output_configs->length; k++) {
|
||||
free_output_config(output_configs->items[k]);
|
||||
}
|
||||
list_free(output_configs);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue