aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config/output.c
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2018-12-12 12:13:03 -0500
committerLibravatar emersion <contact@emersion.fr>2018-12-13 18:37:25 +0100
commit1897edabbaf8755d1b124ab2e00c8f7d43dca57a (patch)
treece82b8c5607b884d7ad55bbf0bacffa52d27d6e5 /sway/config/output.c
parentFix criteria execution in view_map (diff)
downloadsway-1897edabbaf8755d1b124ab2e00c8f7d43dca57a.tar.gz
sway-1897edabbaf8755d1b124ab2e00c8f7d43dca57a.tar.zst
sway-1897edabbaf8755d1b124ab2e00c8f7d43dca57a.zip
Rework default output configs
Default output configs were generated on reload to reset an output to its default settings. The idea was that anything that was removed from the config or changed at runtime and not in the config should be reset on reload. Originally, they were created using the output name. Recently, they were changed to use the output identifier. It turns out that there are issues of shadowing with that solution as well. This should fix those issues. Instead of generating the default output configs on reload and storing them in the output config list to merge on top of, they are now only generated when retrieving the output config for an output during a reload. This means that the default output configs are never stored anywhere and just used as a base to merge unaltered user configs on top of during a reload. Starting with a blank output config, merges get applied in the following order: 1. Default output config (only during a reload) 2. Wildcard config (only if neither output name or output identifier exist) 3. Output name config 4. Output identifier config
Diffstat (limited to 'sway/config/output.c')
-rw-r--r--sway/config/output.c76
1 files changed, 42 insertions, 34 deletions
diff --git a/sway/config/output.c b/sway/config/output.c
index 18707535..7c2df6ec 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -276,7 +276,24 @@ void apply_output_config(struct output_config *oc, struct sway_output *output) {
276 } 276 }
277} 277}
278 278
279static struct output_config *get_output_config(char *name, char *identifier) { 279static void default_output_config(struct output_config *oc,
280 struct wlr_output *wlr_output) {
281 oc->enabled = 1;
282 if (!wl_list_empty(&wlr_output->modes)) {
283 struct wlr_output_mode *mode =
284 wl_container_of(wlr_output->modes.prev, mode, link);
285 oc->width = mode->width;
286 oc->height = mode->height;
287 oc->refresh_rate = mode->refresh;
288 }
289 oc->x = oc->y = -1;
290 oc->scale = 1;
291 oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
292}
293
294static struct output_config *get_output_config(char *identifier,
295 struct sway_output *sway_output) {
296 const char *name = sway_output->wlr_output->name;
280 struct output_config *oc_name = NULL; 297 struct output_config *oc_name = NULL;
281 int i = list_seq_find(config->output_configs, output_name_cmp, name); 298 int i = list_seq_find(config->output_configs, output_name_cmp, name);
282 if (i >= 0) { 299 if (i >= 0) {
@@ -289,7 +306,10 @@ static struct output_config *get_output_config(char *name, char *identifier) {
289 oc_id = config->output_configs->items[i]; 306 oc_id = config->output_configs->items[i];
290 } 307 }
291 308
292 struct output_config *result = NULL; 309 struct output_config *result = result = new_output_config("temp");
310 if (config->reloading) {
311 default_output_config(result, sway_output->wlr_output);
312 }
293 if (oc_name && oc_id) { 313 if (oc_name && oc_id) {
294 // Generate a config named `<identifier> on <name>` which contains a 314 // Generate a config named `<identifier> on <name>` which contains a
295 // merged copy of the identifier on name. This will make sure that both 315 // merged copy of the identifier on name. This will make sure that both
@@ -299,7 +319,8 @@ static struct output_config *get_output_config(char *name, char *identifier) {
299 char *temp = malloc(length); 319 char *temp = malloc(length);
300 snprintf(temp, length, "%s on %s", identifier, name); 320 snprintf(temp, length, "%s on %s", identifier, name);
301 321
302 result = new_output_config(temp); 322 free(result->name);
323 result->name = temp;
303 merge_output_config(result, oc_name); 324 merge_output_config(result, oc_name);
304 merge_output_config(result, oc_id); 325 merge_output_config(result, oc_id);
305 326
@@ -309,16 +330,29 @@ static struct output_config *get_output_config(char *name, char *identifier) {
309 result->height, result->refresh_rate, result->x, result->y, 330 result->height, result->refresh_rate, result->x, result->y,
310 result->scale, result->transform, result->background, 331 result->scale, result->transform, result->background,
311 result->background_option, result->dpms_state); 332 result->background_option, result->dpms_state);
312
313 free(temp);
314 } else if (oc_name) { 333 } else if (oc_name) {
315 // No identifier config, just return a copy of the name config 334 // No identifier config, just return a copy of the name config
316 result = new_output_config(name); 335 free(result->name);
336 result->name = strdup(name);
317 merge_output_config(result, oc_name); 337 merge_output_config(result, oc_name);
318 } else if (oc_id) { 338 } else if (oc_id) {
319 // No name config, just return a copy of the identifier config 339 // No name config, just return a copy of the identifier config
320 result = new_output_config(identifier); 340 free(result->name);
341 result->name = strdup(identifier);
321 merge_output_config(result, oc_id); 342 merge_output_config(result, oc_id);
343 } else if (config->reloading) {
344 // Neither config exists, but we need to reset the output so create a
345 // default config for the output and if a wildcard config exists, merge
346 // that on top
347 free(result->name);
348 result->name = strdup("*");
349 i = list_seq_find(config->output_configs, output_name_cmp, "*");
350 if (i >= 0) {
351 merge_output_config(result, config->output_configs->items[i]);
352 }
353 } else {
354 free_output_config(result);
355 result = NULL;
322 } 356 }
323 357
324 return result; 358 return result;
@@ -338,7 +372,7 @@ void apply_output_config_to_outputs(struct output_config *oc) {
338 struct output_config *current = new_output_config(oc->name); 372 struct output_config *current = new_output_config(oc->name);
339 merge_output_config(current, oc); 373 merge_output_config(current, oc);
340 if (wildcard) { 374 if (wildcard) {
341 struct output_config *tmp = get_output_config(name, id); 375 struct output_config *tmp = get_output_config(id, sway_output);
342 if (tmp) { 376 if (tmp) {
343 free_output_config(current); 377 free_output_config(current);
344 current = tmp; 378 current = tmp;
@@ -366,29 +400,3 @@ void free_output_config(struct output_config *oc) {
366 free(oc->background_fallback); 400 free(oc->background_fallback);
367 free(oc); 401 free(oc);
368} 402}
369
370static void default_output_config(struct output_config *oc,
371 struct wlr_output *wlr_output) {
372 oc->enabled = 1;
373 if (!wl_list_empty(&wlr_output->modes)) {
374 struct wlr_output_mode *mode =
375 wl_container_of(wlr_output->modes.prev, mode, link);
376 oc->width = mode->width;
377 oc->height = mode->height;
378 oc->refresh_rate = mode->refresh;
379 }
380 oc->x = oc->y = -1;
381 oc->scale = 1;
382 oc->transform = WL_OUTPUT_TRANSFORM_NORMAL;
383}
384
385void create_default_output_configs(void) {
386 struct sway_output *sway_output;
387 wl_list_for_each(sway_output, &root->all_outputs, link) {
388 char id[128];
389 output_get_identifier(id, sizeof(id), sway_output);
390 struct output_config *oc = new_output_config(id);
391 default_output_config(oc, sway_output->wlr_output);
392 list_add(config->output_configs, oc);
393 }
394}