Skip to content

Commit

Permalink
Re-add support for wlr_output's atomic API
Browse files Browse the repository at this point in the history
This reverts commit 724926e and
re-applies commit 6e0565e.

See also: swaywm/wlroots#1797 (wlroots PR)
See also: swaywm#4355 (Original sway PR)
See also: swaywm#4434 (Revert sway PR)
  • Loading branch information
emersion committed Dec 27, 2019
1 parent 088b374 commit 8f3f017
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions sway/config/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,15 @@ struct output_config *store_output_config(struct output_config *oc) {
return oc;
}

static bool set_mode(struct wlr_output *output, int width, int height,
static void set_mode(struct wlr_output *output, int width, int height,
float refresh_rate, bool custom) {
int mhz = (int)(refresh_rate * 1000);

if (wl_list_empty(&output->modes) || custom) {
sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name);
return wlr_output_set_custom_mode(output, width, height,
wlr_output_set_custom_mode(output, width, height,
refresh_rate > 0 ? mhz : 0);
return;
}

struct wlr_output_mode *mode, *best = NULL;
Expand All @@ -260,7 +261,7 @@ static bool set_mode(struct wlr_output *output, int width, int height,
} else {
sway_log(SWAY_DEBUG, "Assigning configured mode to %s", output->name);
}
return wlr_output_set_mode(output, best);
wlr_output_set_mode(output, best);
}

/* Some manufacturers hardcode the aspect-ratio of the output in the physical
Expand Down Expand Up @@ -320,11 +321,12 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
wlr_output_layout_remove(root->output_layout, wlr_output);
}
wlr_output_enable(wlr_output, false);
return true;
return wlr_output_commit(wlr_output);
} else if (!output->enabled) {
// Output is not enabled. Enable it, output_enable will call us again.
if (!oc || oc->dpms_state != DPMS_OFF) {
wlr_output_enable(wlr_output, true);
wlr_output_commit(wlr_output);
}
return output_enable(output, oc);
}
Expand All @@ -334,27 +336,15 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
wlr_output_enable(wlr_output, true);
}

bool modeset_success;
if (oc && oc->width > 0 && oc->height > 0) {
sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f Hz)", oc->name, oc->width,
oc->height, oc->refresh_rate);
modeset_success = set_mode(wlr_output, oc->width, oc->height,
set_mode(wlr_output, oc->width, oc->height,
oc->refresh_rate, oc->custom_mode == 1);
} else if (!wl_list_empty(&wlr_output->modes)) {
struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output);
modeset_success = wlr_output_set_mode(wlr_output, mode);
} else {
// Output doesn't support modes
modeset_success = true;
}
if (!modeset_success) {
// Failed to modeset, maybe the output is missing a CRTC. Leave the
// output disabled for now and try again when the output gets the mode
// we asked for.
sway_log(SWAY_ERROR, "Failed to modeset output %s", wlr_output->name);
return false;
wlr_output_set_mode(wlr_output, mode);
}
output->current_mode = wlr_output->current_mode;

float scale;
if (oc && oc->scale > 0) {
Expand Down Expand Up @@ -400,6 +390,14 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
wlr_output_set_transform(wlr_output, oc->transform);
}

if (!wlr_output_commit(wlr_output)) {
// Failed to modeset, maybe the output is missing a CRTC. Leave the
// output disabled for now and try again when the output gets the mode
// we asked for.
sway_log(SWAY_ERROR, "Failed to modeset output %s", wlr_output->name);
return false;
}

// Find position for it
if (oc && (oc->x != -1 || oc->y != -1)) {
sway_log(SWAY_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
Expand All @@ -408,6 +406,8 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
wlr_output_layout_add_auto(root->output_layout, wlr_output);
}

output->current_mode = wlr_output->current_mode;

// Update output->{lx, ly, width, height}
struct wlr_box *output_box =
wlr_output_layout_get_box(root->output_layout, wlr_output);
Expand All @@ -419,6 +419,7 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
if (oc && oc->dpms_state == DPMS_OFF) {
sway_log(SWAY_DEBUG, "Turning off screen");
wlr_output_enable(wlr_output, false);
wlr_output_commit(wlr_output);
}

if (oc && oc->max_render_time >= 0) {
Expand Down

0 comments on commit 8f3f017

Please sign in to comment.