aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2019-12-27 11:47:51 +0100
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-12-30 11:24:11 -0700
commitef2332f7a648c208bb0c601f670823162f584664 (patch)
treeb8b5d0b5dd51b63c42663ed2a7f55b38e25edeaa
parentAdd Chinese (zh-TW) translation of README (diff)
downloadsway-ef2332f7a648c208bb0c601f670823162f584664.tar.gz
sway-ef2332f7a648c208bb0c601f670823162f584664.tar.zst
sway-ef2332f7a648c208bb0c601f670823162f584664.zip
Re-add support for wlr_output's atomic API
This reverts commit 724926ea6ae119956dc7b1e39c2e30c1e3657676 and re-applies commit 6e0565e9de4247bbf0ca662565c58e0a54258d6e. Outputs now need to be explicitly enabled when performing a modeset. We need to roll back wlr_output_attach_render when we decide not to render. See also: https://github.com/swaywm/wlroots/pull/1797 (wlroots PR) See also: https://github.com/swaywm/sway/pull/4355 (Original sway PR) See also: https://github.com/swaywm/sway/pull/4434 (Revert sway PR)
-rw-r--r--sway/config/output.c59
-rw-r--r--sway/desktop/output.c8
2 files changed, 37 insertions, 30 deletions
diff --git a/sway/config/output.c b/sway/config/output.c
index 2a65718a..b8b028e6 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -231,14 +231,15 @@ struct output_config *store_output_config(struct output_config *oc) {
231 return oc; 231 return oc;
232} 232}
233 233
234static bool set_mode(struct wlr_output *output, int width, int height, 234static void set_mode(struct wlr_output *output, int width, int height,
235 float refresh_rate, bool custom) { 235 float refresh_rate, bool custom) {
236 int mhz = (int)(refresh_rate * 1000); 236 int mhz = (int)(refresh_rate * 1000);
237 237
238 if (wl_list_empty(&output->modes) || custom) { 238 if (wl_list_empty(&output->modes) || custom) {
239 sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name); 239 sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name);
240 return wlr_output_set_custom_mode(output, width, height, 240 wlr_output_set_custom_mode(output, width, height,
241 refresh_rate > 0 ? mhz : 0); 241 refresh_rate > 0 ? mhz : 0);
242 return;
242 } 243 }
243 244
244 struct wlr_output_mode *mode, *best = NULL; 245 struct wlr_output_mode *mode, *best = NULL;
@@ -260,7 +261,7 @@ static bool set_mode(struct wlr_output *output, int width, int height,
260 } else { 261 } else {
261 sway_log(SWAY_DEBUG, "Assigning configured mode to %s", output->name); 262 sway_log(SWAY_DEBUG, "Assigning configured mode to %s", output->name);
262 } 263 }
263 return wlr_output_set_mode(output, best); 264 wlr_output_set_mode(output, best);
264} 265}
265 266
266/* Some manufacturers hardcode the aspect-ratio of the output in the physical 267/* Some manufacturers hardcode the aspect-ratio of the output in the physical
@@ -315,46 +316,38 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
315 316
316 if (oc && !oc->enabled) { 317 if (oc && !oc->enabled) {
317 // Output is configured to be disabled 318 // Output is configured to be disabled
319 sway_log(SWAY_DEBUG, "Disabling output %s", oc->name);
318 if (output->enabled) { 320 if (output->enabled) {
319 output_disable(output); 321 output_disable(output);
320 wlr_output_layout_remove(root->output_layout, wlr_output); 322 wlr_output_layout_remove(root->output_layout, wlr_output);
321 } 323 }
322 wlr_output_enable(wlr_output, false); 324 wlr_output_enable(wlr_output, false);
323 return true; 325 return wlr_output_commit(wlr_output);
324 } else if (!output->enabled) { 326 } else if (!output->enabled) {
325 // Output is not enabled. Enable it, output_enable will call us again. 327 // Output is not enabled. Enable it, output_enable will call us again.
326 if (!oc || oc->dpms_state != DPMS_OFF) { 328 if (!oc || oc->dpms_state != DPMS_OFF) {
329 sway_log(SWAY_DEBUG, "Enabling output %s", oc->name);
327 wlr_output_enable(wlr_output, true); 330 wlr_output_enable(wlr_output, true);
331 wlr_output_commit(wlr_output);
328 } 332 }
329 return output_enable(output, oc); 333 return output_enable(output, oc);
330 } 334 }
331 335
332 if (oc && oc->dpms_state == DPMS_ON) { 336 if (!oc || oc->dpms_state != DPMS_OFF) {
333 sway_log(SWAY_DEBUG, "Turning on screen"); 337 sway_log(SWAY_DEBUG, "Turning on output %s", oc->name);
334 wlr_output_enable(wlr_output, true); 338 wlr_output_enable(wlr_output, true);
335 }
336 339
337 bool modeset_success; 340 if (oc && oc->width > 0 && oc->height > 0) {
338 if (oc && oc->width > 0 && oc->height > 0) { 341 sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f Hz)", oc->name, oc->width,
339 sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f Hz)", oc->name, oc->width, 342 oc->height, oc->refresh_rate);
340 oc->height, oc->refresh_rate); 343 set_mode(wlr_output, oc->width, oc->height,
341 modeset_success = set_mode(wlr_output, oc->width, oc->height, 344 oc->refresh_rate, oc->custom_mode == 1);
342 oc->refresh_rate, oc->custom_mode == 1); 345 } else if (!wl_list_empty(&wlr_output->modes)) {
343 } else if (!wl_list_empty(&wlr_output->modes)) { 346 struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
344 struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output); 347 wlr_output_set_mode(wlr_output, mode);
345 modeset_success = wlr_output_set_mode(wlr_output, mode); 348 }
346 } else { 349 output->current_mode = wlr_output->pending.mode;
347 // Output doesn't support modes
348 modeset_success = true;
349 }
350 if (!modeset_success) {
351 // Failed to modeset, maybe the output is missing a CRTC. Leave the
352 // output disabled for now and try again when the output gets the mode
353 // we asked for.
354 sway_log(SWAY_ERROR, "Failed to modeset output %s", wlr_output->name);
355 return false;
356 } 350 }
357 output->current_mode = wlr_output->current_mode;
358 351
359 float scale; 352 float scale;
360 if (oc && oc->scale > 0) { 353 if (oc && oc->scale > 0) {
@@ -400,6 +393,15 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
400 wlr_output_set_transform(wlr_output, oc->transform); 393 wlr_output_set_transform(wlr_output, oc->transform);
401 } 394 }
402 395
396 sway_log(SWAY_DEBUG, "Committing output %s", wlr_output->name);
397 if (!wlr_output_commit(wlr_output)) {
398 // Failed to modeset, maybe the output is missing a CRTC. Leave the
399 // output disabled for now and try again when the output gets the mode
400 // we asked for.
401 sway_log(SWAY_ERROR, "Failed to modeset output %s", wlr_output->name);
402 return false;
403 }
404
403 // Find position for it 405 // Find position for it
404 if (oc && (oc->x != -1 || oc->y != -1)) { 406 if (oc && (oc->x != -1 || oc->y != -1)) {
405 sway_log(SWAY_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); 407 sway_log(SWAY_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
@@ -417,8 +419,9 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
417 output->height = output_box->height; 419 output->height = output_box->height;
418 420
419 if (oc && oc->dpms_state == DPMS_OFF) { 421 if (oc && oc->dpms_state == DPMS_OFF) {
420 sway_log(SWAY_DEBUG, "Turning off screen"); 422 sway_log(SWAY_DEBUG, "Turning off output %s", oc->name);
421 wlr_output_enable(wlr_output, false); 423 wlr_output_enable(wlr_output, false);
424 wlr_output_commit(wlr_output);
422 } 425 }
423 426
424 if (oc && oc->max_render_time >= 0) { 427 if (oc && oc->max_render_time >= 0) {
diff --git a/sway/desktop/output.c b/sway/desktop/output.c
index 6b0ceee1..b1767efc 100644
--- a/sway/desktop/output.c
+++ b/sway/desktop/output.c
@@ -560,8 +560,12 @@ int output_repaint_timer_handler(void *data) {
560 clock_gettime(CLOCK_MONOTONIC, &now); 560 clock_gettime(CLOCK_MONOTONIC, &now);
561 561
562 output_render(output, &now, &damage); 562 output_render(output, &now, &damage);
563 } else if (surface_needs_frame) { 563 } else {
564 wlr_output_schedule_frame(output->wlr_output); 564 wlr_output_rollback(output->wlr_output);
565
566 if (surface_needs_frame) {
567 wlr_output_schedule_frame(output->wlr_output);
568 }
565 } 569 }
566 570
567 pixman_region32_fini(&damage); 571 pixman_region32_fini(&damage);