diff options
-rw-r--r-- | include/sway/config.h | 2 | ||||
-rw-r--r-- | sway/config.c | 2 | ||||
-rw-r--r-- | sway/config/output.c | 76 |
3 files changed, 42 insertions, 38 deletions
diff --git a/include/sway/config.h b/include/sway/config.h index 58b7010e..6afb471a 100644 --- a/include/sway/config.h +++ b/include/sway/config.h | |||
@@ -553,8 +553,6 @@ void apply_output_config_to_outputs(struct output_config *oc); | |||
553 | 553 | ||
554 | void free_output_config(struct output_config *oc); | 554 | void free_output_config(struct output_config *oc); |
555 | 555 | ||
556 | void create_default_output_configs(void); | ||
557 | |||
558 | int workspace_output_cmp_workspace(const void *a, const void *b); | 556 | int workspace_output_cmp_workspace(const void *a, const void *b); |
559 | 557 | ||
560 | int sway_binding_cmp(const void *a, const void *b); | 558 | int sway_binding_cmp(const void *a, const void *b); |
diff --git a/sway/config.c b/sway/config.c index 5b03bc56..d4b7d466 100644 --- a/sway/config.c +++ b/sway/config.c | |||
@@ -391,8 +391,6 @@ bool load_main_config(const char *file, bool is_active, bool validating) { | |||
391 | memcpy(&config->swaynag_config_errors, | 391 | memcpy(&config->swaynag_config_errors, |
392 | &old_config->swaynag_config_errors, | 392 | &old_config->swaynag_config_errors, |
393 | sizeof(struct swaynag_instance)); | 393 | sizeof(struct swaynag_instance)); |
394 | |||
395 | create_default_output_configs(); | ||
396 | } | 394 | } |
397 | 395 | ||
398 | config->current_config_path = path; | 396 | config->current_config_path = path; |
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 | ||
279 | static struct output_config *get_output_config(char *name, char *identifier) { | 279 | static 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 | |||
294 | static 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 | |||
370 | static 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 | |||
385 | void 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 | } | ||