diff options
author | Ryan Dwyer <RyanDwyer@users.noreply.github.com> | 2018-07-21 21:35:40 +1000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-07-21 21:35:40 +1000 |
commit | 27f65b94ae35a7b7342ed331884f765141fad373 (patch) | |
tree | d125902e937c72b566a09b2a91d78040f82906b8 | |
parent | Merge pull request #2317 from RyanDwyer/force-display-urgency-hint (diff) | |
parent | Reset outputs on reload (diff) | |
download | sway-27f65b94ae35a7b7342ed331884f765141fad373.tar.gz sway-27f65b94ae35a7b7342ed331884f765141fad373.tar.zst sway-27f65b94ae35a7b7342ed331884f765141fad373.zip |
Merge pull request #2320 from RedSoxFan/reset-outputs-on-reload
Reset outputs on reload
-rw-r--r-- | include/sway/config.h | 4 | ||||
-rw-r--r-- | sway/commands/output.c | 62 | ||||
-rw-r--r-- | sway/config.c | 4 | ||||
-rw-r--r-- | sway/config/output.c | 80 |
4 files changed, 95 insertions, 55 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 87768399..b8da29c5 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -464,8 +464,12 @@ void apply_output_config(struct output_config *oc, | |||
464 | 464 | ||
465 | struct output_config *store_output_config(struct output_config *oc); | 465 | struct output_config *store_output_config(struct output_config *oc); |
466 | 466 | ||
467 | void apply_output_config_to_outputs(struct output_config *oc); | ||
468 | |||
467 | void free_output_config(struct output_config *oc); | 469 | void free_output_config(struct output_config *oc); |
468 | 470 | ||
471 | void create_default_output_configs(void); | ||
472 | |||
469 | int workspace_output_cmp_workspace(const void *a, const void *b); | 473 | int workspace_output_cmp_workspace(const void *a, const void *b); |
470 | 474 | ||
471 | int sway_binding_cmp(const void *a, const void *b); | 475 | int sway_binding_cmp(const void *a, const void *b); |
diff --git a/sway/commands/output.c b/sway/commands/output.c index 4d98162b..ef1b7a69 100644 --- a/sway/commands/output.c +++ b/sway/commands/output.c | |||
@@ -21,60 +21,6 @@ static struct cmd_handler output_handlers[] = { | |||
21 | { "transform", output_cmd_transform }, | 21 | { "transform", output_cmd_transform }, |
22 | }; | 22 | }; |
23 | 23 | ||
24 | static struct output_config *get_output_config(char *name, char *identifier) { | ||
25 | int i = list_seq_find(config->output_configs, output_name_cmp, name); | ||
26 | if (i >= 0) { | ||
27 | return config->output_configs->items[i]; | ||
28 | } | ||
29 | |||
30 | i = list_seq_find(config->output_configs, output_name_cmp, identifier); | ||
31 | if (i >= 0) { | ||
32 | return config->output_configs->items[i]; | ||
33 | } | ||
34 | |||
35 | return NULL; | ||
36 | } | ||
37 | |||
38 | static void apply_output_config_to_outputs(struct output_config *oc) { | ||
39 | // Try to find the output container and apply configuration now. If | ||
40 | // this is during startup then there will be no container and config | ||
41 | // will be applied during normal "new output" event from wlroots. | ||
42 | bool wildcard = strcmp(oc->name, "*") == 0; | ||
43 | char id[128]; | ||
44 | struct sway_output *sway_output; | ||
45 | wl_list_for_each(sway_output, &root_container.sway_root->outputs, link) { | ||
46 | char *name = sway_output->wlr_output->name; | ||
47 | output_get_identifier(id, sizeof(id), sway_output); | ||
48 | if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) { | ||
49 | if (!sway_output->swayc) { | ||
50 | if (!oc->enabled) { | ||
51 | if (!wildcard) { | ||
52 | break; | ||
53 | } | ||
54 | continue; | ||
55 | } | ||
56 | |||
57 | output_enable(sway_output); | ||
58 | } | ||
59 | |||
60 | struct output_config *current = oc; | ||
61 | if (wildcard) { | ||
62 | struct output_config *tmp = get_output_config(name, id); | ||
63 | if (tmp) { | ||
64 | current = tmp; | ||
65 | } | ||
66 | } | ||
67 | apply_output_config(current, sway_output->swayc); | ||
68 | |||
69 | if (!wildcard) { | ||
70 | // Stop looking if the output config isn't applicable to all | ||
71 | // outputs | ||
72 | break; | ||
73 | } | ||
74 | } | ||
75 | } | ||
76 | } | ||
77 | |||
78 | struct cmd_results *cmd_output(int argc, char **argv) { | 24 | struct cmd_results *cmd_output(int argc, char **argv) { |
79 | struct cmd_results *error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1); | 25 | struct cmd_results *error = checkarg(argc, "output", EXPECTED_AT_LEAST, 1); |
80 | if (error != NULL) { | 26 | if (error != NULL) { |
@@ -115,7 +61,13 @@ struct cmd_results *cmd_output(int argc, char **argv) { | |||
115 | config->handler_context.leftovers.argv = NULL; | 61 | config->handler_context.leftovers.argv = NULL; |
116 | 62 | ||
117 | output = store_output_config(output); | 63 | output = store_output_config(output); |
118 | apply_output_config_to_outputs(output); | 64 | |
65 | // If reloading, the output configs will be applied after reading the | ||
66 | // entire config and before the deferred commands so that an auto generated | ||
67 | // workspace name is not given to re-enabled outputs. | ||
68 | if (!config->reloading) { | ||
69 | apply_output_config_to_outputs(output); | ||
70 | } | ||
119 | 71 | ||
120 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); | 72 | return cmd_results_new(CMD_SUCCESS, NULL, NULL); |
121 | 73 | ||
diff --git a/sway/config.c b/sway/config.c index 4b892852..ed624bfa 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -361,6 +361,7 @@ bool load_main_config(const char *file, bool is_active) { | |||
361 | wlr_log(WLR_DEBUG, "Performing configuration file reload"); | 361 | wlr_log(WLR_DEBUG, "Performing configuration file reload"); |
362 | config->reloading = true; | 362 | config->reloading = true; |
363 | config->active = true; | 363 | config->active = true; |
364 | create_default_output_configs(); | ||
364 | } | 365 | } |
365 | 366 | ||
366 | config->current_config_path = path; | 367 | config->current_config_path = path; |
@@ -419,6 +420,9 @@ bool load_main_config(const char *file, bool is_active) { | |||
419 | success = success && load_config(path, config); | 420 | success = success && load_config(path, config); |
420 | 421 | ||
421 | if (is_active) { | 422 | if (is_active) { |
423 | for (int i = 0; i < config->output_configs->length; i++) { | ||
424 | apply_output_config_to_outputs(config->output_configs->items[i]); | ||
425 | } | ||
422 | config->reloading = false; | 426 | config->reloading = false; |
423 | } | 427 | } |
424 | 428 | ||
diff --git a/sway/config/output.c b/sway/config/output.c index 505fa745..504c48c6 100644 --- a/sway/config/output.c +++ b/sway/config/output.c | |||
@@ -263,6 +263,60 @@ void apply_output_config(struct output_config *oc, struct sway_container *output | |||
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | static struct output_config *get_output_config(char *name, char *identifier) { | ||
267 | int i = list_seq_find(config->output_configs, output_name_cmp, name); | ||
268 | if (i >= 0) { | ||
269 | return config->output_configs->items[i]; | ||
270 | } | ||
271 | |||
272 | i = list_seq_find(config->output_configs, output_name_cmp, identifier); | ||
273 | if (i >= 0) { | ||
274 | return config->output_configs->items[i]; | ||
275 | } | ||
276 | |||
277 | return NULL; | ||
278 | } | ||
279 | |||
280 | void apply_output_config_to_outputs(struct output_config *oc) { | ||
281 | // Try to find the output container and apply configuration now. If | ||
282 | // this is during startup then there will be no container and config | ||
283 | // will be applied during normal "new output" event from wlroots. | ||
284 | bool wildcard = strcmp(oc->name, "*") == 0; | ||
285 | char id[128]; | ||
286 | struct sway_output *sway_output; | ||
287 | wl_list_for_each(sway_output, &root_container.sway_root->outputs, link) { | ||
288 | char *name = sway_output->wlr_output->name; | ||
289 | output_get_identifier(id, sizeof(id), sway_output); | ||
290 | if (wildcard || !strcmp(name, oc->name) || !strcmp(id, oc->name)) { | ||
291 | if (!sway_output->swayc) { | ||
292 | if (!oc->enabled) { | ||
293 | if (!wildcard) { | ||
294 | break; | ||
295 | } | ||
296 | continue; | ||
297 | } | ||
298 | |||
299 | output_enable(sway_output); | ||
300 | } | ||
301 | |||
302 | struct output_config *current = oc; | ||
303 | if (wildcard) { | ||
304 | struct output_config *tmp = get_output_config(name, id); | ||
305 | if (tmp) { | ||
306 | current = tmp; | ||
307 | } | ||
308 | } | ||
309 | apply_output_config(current, sway_output->swayc); | ||
310 | |||
311 | if (!wildcard) { | ||
312 | // Stop looking if the output config isn't applicable to all | ||
313 | // outputs | ||
314 | break; | ||
315 | } | ||
316 | } | ||
317 | } | ||
318 | } | ||
319 | |||
266 | void free_output_config(struct output_config *oc) { | 320 | void free_output_config(struct output_config *oc) { |
267 | if (!oc) { | 321 | if (!oc) { |
268 | return; | 322 | return; |
@@ -272,3 +326,29 @@ void free_output_config(struct output_config *oc) { | |||
272 | free(oc->background_option); | 326 | free(oc->background_option); |
273 | free(oc); | 327 | free(oc); |
274 | } | 328 | } |
329 | |||
330 | static void default_output_config(struct output_config *oc, | ||
331 | struct wlr_output *wlr_output) { | ||
332 | oc->enabled = 1; | ||
333 | if (!wl_list_empty(&wlr_output->modes)) { | ||
334 | struct wlr_output_mode *mode = | ||
335 | wl_container_of(wlr_output->modes.prev, mode, link); | ||
336 | oc->width = mode->width; | ||
337 | oc->height = mode->height; | ||
338 | oc->refresh_rate = mode->refresh; | ||
339 | } | ||
340 | oc->x = oc->y = -1; | ||
341 | oc->scale = 1; | ||
342 | oc->transform = WL_OUTPUT_TRANSFORM_NORMAL; | ||
343 | } | ||
344 | |||
345 | void create_default_output_configs(void) { | ||
346 | struct sway_output *sway_output; | ||
347 | wl_list_for_each(sway_output, &root_container.sway_root->outputs, link) { | ||
348 | char *name = sway_output->wlr_output->name; | ||
349 | struct output_config *oc = new_output_config(name); | ||
350 | default_output_config(oc, sway_output->wlr_output); | ||
351 | list_add(config->output_configs, oc); | ||
352 | } | ||
353 | } | ||
354 | |||