mirror of
https://github.com/swaywm/sway.git
synced 2024-12-30 17:06:40 +01:00
Add support for wlr_output's atomic API
See https://github.com/swaywm/wlroots/pull/1762
This commit is contained in:
parent
8ee054b1b9
commit
6e0565e9de
1 changed files with 26 additions and 27 deletions
|
@ -199,12 +199,13 @@ struct output_config *store_output_config(struct output_config *oc) {
|
||||||
return 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) {
|
float refresh_rate) {
|
||||||
int mhz = (int)(refresh_rate * 1000);
|
int mhz = (int)(refresh_rate * 1000);
|
||||||
if (wl_list_empty(&output->modes)) {
|
if (wl_list_empty(&output->modes)) {
|
||||||
sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name);
|
sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name);
|
||||||
return wlr_output_set_custom_mode(output, width, height, mhz);
|
wlr_output_set_custom_mode(output, width, height, mhz);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct wlr_output_mode *mode, *best = NULL;
|
struct wlr_output_mode *mode, *best = NULL;
|
||||||
|
@ -224,7 +225,7 @@ static bool set_mode(struct wlr_output *output, int width, int height,
|
||||||
} else {
|
} else {
|
||||||
sway_log(SWAY_DEBUG, "Assigning configured mode to %s", output->name);
|
sway_log(SWAY_DEBUG, "Assigning configured mode to %s", output->name);
|
||||||
}
|
}
|
||||||
return wlr_output_set_mode(output, best);
|
wlr_output_set_mode(output, best);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
||||||
|
@ -241,11 +242,12 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
||||||
wlr_output_layout_remove(root->output_layout, wlr_output);
|
wlr_output_layout_remove(root->output_layout, wlr_output);
|
||||||
}
|
}
|
||||||
wlr_output_enable(wlr_output, false);
|
wlr_output_enable(wlr_output, false);
|
||||||
return true;
|
return wlr_output_commit(wlr_output);
|
||||||
} else if (!output->enabled) {
|
} else if (!output->enabled) {
|
||||||
// Output is not enabled. Enable it, output_enable will call us again.
|
// Output is not enabled. Enable it, output_enable will call us again.
|
||||||
if (!oc || oc->dpms_state != DPMS_OFF) {
|
if (!oc || oc->dpms_state != DPMS_OFF) {
|
||||||
wlr_output_enable(wlr_output, true);
|
wlr_output_enable(wlr_output, true);
|
||||||
|
wlr_output_commit(wlr_output);
|
||||||
}
|
}
|
||||||
output_enable(output, oc);
|
output_enable(output, oc);
|
||||||
return true;
|
return true;
|
||||||
|
@ -256,26 +258,14 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
||||||
wlr_output_enable(wlr_output, true);
|
wlr_output_enable(wlr_output, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool modeset_success;
|
struct wlr_output_mode *preferred_mode =
|
||||||
|
wlr_output_preferred_mode(wlr_output);
|
||||||
if (oc && oc->width > 0 && oc->height > 0) {
|
if (oc && oc->width > 0 && oc->height > 0) {
|
||||||
sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width,
|
sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width,
|
||||||
oc->height, oc->refresh_rate);
|
oc->height, oc->refresh_rate);
|
||||||
modeset_success =
|
|
||||||
set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate);
|
set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate);
|
||||||
} else if (!wl_list_empty(&wlr_output->modes)) {
|
} else if (preferred_mode != NULL) {
|
||||||
struct wlr_output_mode *mode =
|
wlr_output_set_mode(wlr_output, preferred_mode);
|
||||||
wl_container_of(wlr_output->modes.prev, mode, link);
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oc && oc->scale > 0) {
|
if (oc && oc->scale > 0) {
|
||||||
|
@ -295,6 +285,14 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
||||||
wlr_output_set_transform(wlr_output, oc->transform);
|
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
|
// Find position for it
|
||||||
if (oc && (oc->x != -1 || oc->y != -1)) {
|
if (oc && (oc->x != -1 || oc->y != -1)) {
|
||||||
sway_log(SWAY_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
|
sway_log(SWAY_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y);
|
||||||
|
@ -314,6 +312,7 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
||||||
if (oc && oc->dpms_state == DPMS_OFF) {
|
if (oc && oc->dpms_state == DPMS_OFF) {
|
||||||
sway_log(SWAY_DEBUG, "Turning off screen");
|
sway_log(SWAY_DEBUG, "Turning off screen");
|
||||||
wlr_output_enable(wlr_output, false);
|
wlr_output_enable(wlr_output, false);
|
||||||
|
wlr_output_commit(wlr_output);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -322,12 +321,12 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
|
||||||
static void default_output_config(struct output_config *oc,
|
static void default_output_config(struct output_config *oc,
|
||||||
struct wlr_output *wlr_output) {
|
struct wlr_output *wlr_output) {
|
||||||
oc->enabled = 1;
|
oc->enabled = 1;
|
||||||
if (!wl_list_empty(&wlr_output->modes)) {
|
struct wlr_output_mode *preferred_mode =
|
||||||
struct wlr_output_mode *mode =
|
wlr_output_preferred_mode(wlr_output);
|
||||||
wl_container_of(wlr_output->modes.prev, mode, link);
|
if (preferred_mode != NULL) {
|
||||||
oc->width = mode->width;
|
oc->width = preferred_mode->width;
|
||||||
oc->height = mode->height;
|
oc->height = preferred_mode->height;
|
||||||
oc->refresh_rate = mode->refresh;
|
oc->refresh_rate = preferred_mode->refresh;
|
||||||
}
|
}
|
||||||
oc->x = oc->y = -1;
|
oc->x = oc->y = -1;
|
||||||
oc->scale = 1;
|
oc->scale = 1;
|
||||||
|
|
Loading…
Reference in a new issue