aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2020-04-08 11:22:51 +0200
committerLibravatar Drew DeVault <sir@cmpwn.com>2020-04-08 16:36:40 +0200
commit0cdcf66bbccfeb1e3a8191cedd5f824bb27776a6 (patch)
tree496d26adca7bde794d346cedcdce79e1cd73f6ae
parentStop checking wlr_output_attach_buffer return value (diff)
downloadsway-0cdcf66bbccfeb1e3a8191cedd5f824bb27776a6.tar.gz
sway-0cdcf66bbccfeb1e3a8191cedd5f824bb27776a6.tar.zst
sway-0cdcf66bbccfeb1e3a8191cedd5f824bb27776a6.zip
Introduce test_output_config
This function checks whether the backend would accept an output configuration, without applying the changes.
-rw-r--r--include/sway/config.h2
-rw-r--r--sway/config/output.c84
2 files changed, 58 insertions, 28 deletions
diff --git a/include/sway/config.h b/include/sway/config.h
index 94ce6214..b541ff0d 100644
--- a/include/sway/config.h
+++ b/include/sway/config.h
@@ -691,6 +691,8 @@ void merge_output_config(struct output_config *dst, struct output_config *src);
691 691
692bool apply_output_config(struct output_config *oc, struct sway_output *output); 692bool apply_output_config(struct output_config *oc, struct sway_output *output);
693 693
694bool test_output_config(struct output_config *oc, struct sway_output *output);
695
694struct output_config *store_output_config(struct output_config *oc); 696struct output_config *store_output_config(struct output_config *oc);
695 697
696struct output_config *find_output_config(struct sway_output *output); 698struct output_config *find_output_config(struct sway_output *output);
diff --git a/sway/config/output.c b/sway/config/output.c
index cbcf713b..1a37c47c 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -331,34 +331,27 @@ static int compute_default_scale(struct wlr_output *output) {
331 return 2; 331 return 2;
332} 332}
333 333
334bool apply_output_config(struct output_config *oc, struct sway_output *output) { 334static void queue_output_config(struct output_config *oc,
335 struct sway_output *output) {
335 if (output == root->noop_output) { 336 if (output == root->noop_output) {
336 return false; 337 return;
337 } 338 }
338 339
339 struct wlr_output *wlr_output = output->wlr_output; 340 struct wlr_output *wlr_output = output->wlr_output;
340 341
341 if (oc && !oc->enabled) { 342 if (oc && (!oc->enabled || oc->dpms_state == DPMS_OFF)) {
342 // Output is configured to be disabled 343 sway_log(SWAY_DEBUG, "Turning off output %s", wlr_output->name);
343 sway_log(SWAY_DEBUG, "Disabling output %s", oc->name);
344 if (output->enabled) {
345 output_disable(output);
346 wlr_output_layout_remove(root->output_layout, wlr_output);
347 }
348 wlr_output_enable(wlr_output, false); 344 wlr_output_enable(wlr_output, false);
349 return wlr_output_commit(wlr_output); 345 return;
350 } 346 }
351 347
352 bool was_enabled = output->enabled; 348 if (!oc) {
353 output->enabled = true;
354
355 if (!oc || oc->dpms_state != DPMS_OFF) {
356 sway_log(SWAY_DEBUG, "Turning on output %s", wlr_output->name); 349 sway_log(SWAY_DEBUG, "Turning on output %s", wlr_output->name);
357 wlr_output_enable(wlr_output, true); 350 wlr_output_enable(wlr_output, true);
358 351
359 if (oc && oc->width > 0 && oc->height > 0) { 352 if (oc && oc->width > 0 && oc->height > 0) {
360 sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f Hz)", oc->name, oc->width, 353 sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f Hz)",
361 oc->height, oc->refresh_rate); 354 wlr_output->name, oc->width, oc->height, oc->refresh_rate);
362 set_mode(wlr_output, oc->width, oc->height, 355 set_mode(wlr_output, oc->width, oc->height,
363 oc->refresh_rate, oc->custom_mode == 1); 356 oc->refresh_rate, oc->custom_mode == 1);
364 } else if (!wl_list_empty(&wlr_output->modes)) { 357 } else if (!wl_list_empty(&wlr_output->modes)) {
@@ -372,7 +365,6 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
372 sway_log(SWAY_DEBUG, "Set %s subpixel to %s", oc->name, 365 sway_log(SWAY_DEBUG, "Set %s subpixel to %s", oc->name,
373 sway_wl_output_subpixel_to_string(oc->subpixel)); 366 sway_wl_output_subpixel_to_string(oc->subpixel));
374 wlr_output_set_subpixel(wlr_output, oc->subpixel); 367 wlr_output_set_subpixel(wlr_output, oc->subpixel);
375 output_damage_whole(output);
376 } 368 }
377 369
378 if (oc && oc->transform >= 0) { 370 if (oc && oc->transform >= 0) {
@@ -395,19 +387,51 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
395 } 387 }
396 388
397 if (oc && oc->adaptive_sync != -1) { 389 if (oc && oc->adaptive_sync != -1) {
390 sway_log(SWAY_DEBUG, "Set %s adaptive sync to %d", wlr_output->name,
391 oc->adaptive_sync);
398 wlr_output_enable_adaptive_sync(wlr_output, oc->adaptive_sync == 1); 392 wlr_output_enable_adaptive_sync(wlr_output, oc->adaptive_sync == 1);
399 } 393 }
394}
395
396bool apply_output_config(struct output_config *oc, struct sway_output *output) {
397 if (output == root->noop_output) {
398 return false;
399 }
400
401 struct wlr_output *wlr_output = output->wlr_output;
402
403 bool was_enabled = output->enabled;
404 if (oc && !oc->enabled) {
405 // Output is configured to be disabled
406 sway_log(SWAY_DEBUG, "Disabling output %s", oc->name);
407 if (output->enabled) {
408 output_disable(output);
409 wlr_output_layout_remove(root->output_layout, wlr_output);
410 }
411 } else {
412 output->enabled = true;
413 }
414
415 queue_output_config(oc, output);
416
417 if (!oc || oc->dpms_state != DPMS_OFF) {
418 output->current_mode = wlr_output->pending.mode;
419 }
400 420
401 sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name); 421 sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name);
402 if (!wlr_output_commit(wlr_output)) { 422 if (!wlr_output_commit(wlr_output)) {
403 // Failed to modeset, maybe the output is missing a CRTC. Leave the 423 // Failed to commit output changes, maybe the output is missing a CRTC.
404 // output disabled for now and try again when the output gets the mode 424 // Leave the output disabled for now and try again when the output gets
405 // we asked for. 425 // the mode we asked for.
406 sway_log(SWAY_ERROR, "Failed to modeset output %s", wlr_output->name); 426 sway_log(SWAY_ERROR, "Failed to commit output %s", wlr_output->name);
407 output->enabled = was_enabled; 427 output->enabled = was_enabled;
408 return false; 428 return false;
409 } 429 }
410 430
431 if (config->reloading) {
432 output_damage_whole(output);
433 }
434
411 if (oc) { 435 if (oc) {
412 enum scale_filter_mode scale_filter_old = output->scale_filter; 436 enum scale_filter_mode scale_filter_old = output->scale_filter;
413 switch (oc->scale_filter) { 437 switch (oc->scale_filter) {
@@ -424,7 +448,6 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
424 if (scale_filter_old != output->scale_filter) { 448 if (scale_filter_old != output->scale_filter) {
425 sway_log(SWAY_DEBUG, "Set %s scale_filter to %s", oc->name, 449 sway_log(SWAY_DEBUG, "Set %s scale_filter to %s", oc->name,
426 sway_output_scale_filter_to_string(output->scale_filter)); 450 sway_output_scale_filter_to_string(output->scale_filter));
427 output_damage_whole(output);
428 } 451 }
429 } 452 }
430 453
@@ -448,12 +471,6 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
448 output_configure(output); 471 output_configure(output);
449 } 472 }
450 473
451 if (oc && oc->dpms_state == DPMS_OFF) {
452 sway_log(SWAY_DEBUG, "Turning off output %s", oc->name);
453 wlr_output_enable(wlr_output, false);
454 wlr_output_commit(wlr_output);
455 }
456
457 if (oc && oc->max_render_time >= 0) { 474 if (oc && oc->max_render_time >= 0) {
458 sway_log(SWAY_DEBUG, "Set %s max render time to %d", 475 sway_log(SWAY_DEBUG, "Set %s max render time to %d",
459 oc->name, oc->max_render_time); 476 oc->name, oc->max_render_time);
@@ -463,6 +480,17 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
463 return true; 480 return true;
464} 481}
465 482
483bool test_output_config(struct output_config *oc, struct sway_output *output) {
484 if (output == root->noop_output) {
485 return false;
486 }
487
488 queue_output_config(oc, output);
489 bool ok = wlr_output_test(output->wlr_output);
490 wlr_output_rollback(output->wlr_output);
491 return ok;
492}
493
466static void default_output_config(struct output_config *oc, 494static void default_output_config(struct output_config *oc,
467 struct wlr_output *wlr_output) { 495 struct wlr_output *wlr_output) {
468 oc->enabled = 1; 496 oc->enabled = 1;