aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Simon Ser <contact@emersion.fr>2019-07-19 22:35:58 +0300
committerLibravatar Drew DeVault <sir@cmpwn.com>2019-08-02 10:01:50 -0400
commit6e0565e9de4247bbf0ca662565c58e0a54258d6e (patch)
treea29bf0ee51ad6818176b62c6ba1cdf97063d68f6
parentbindsym/code: add group support (diff)
downloadsway-6e0565e9de4247bbf0ca662565c58e0a54258d6e.tar.gz
sway-6e0565e9de4247bbf0ca662565c58e0a54258d6e.tar.zst
sway-6e0565e9de4247bbf0ca662565c58e0a54258d6e.zip
Add support for wlr_output's atomic API
See https://github.com/swaywm/wlroots/pull/1762
-rw-r--r--sway/config/output.c53
1 files changed, 26 insertions, 27 deletions
diff --git a/sway/config/output.c b/sway/config/output.c
index 84b7c7e2..be3013a3 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -199,12 +199,13 @@ struct output_config *store_output_config(struct output_config *oc) {
199 return oc; 199 return oc;
200} 200}
201 201
202static bool set_mode(struct wlr_output *output, int width, int height, 202static void set_mode(struct wlr_output *output, int width, int height,
203 float refresh_rate) { 203 float refresh_rate) {
204 int mhz = (int)(refresh_rate * 1000); 204 int mhz = (int)(refresh_rate * 1000);
205 if (wl_list_empty(&output->modes)) { 205 if (wl_list_empty(&output->modes)) {
206 sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name); 206 sway_log(SWAY_DEBUG, "Assigning custom mode to %s", output->name);
207 return wlr_output_set_custom_mode(output, width, height, mhz); 207 wlr_output_set_custom_mode(output, width, height, mhz);
208 return;
208 } 209 }
209 210
210 struct wlr_output_mode *mode, *best = NULL; 211 struct wlr_output_mode *mode, *best = NULL;
@@ -224,7 +225,7 @@ static bool set_mode(struct wlr_output *output, int width, int height,
224 } else { 225 } else {
225 sway_log(SWAY_DEBUG, "Assigning configured mode to %s", output->name); 226 sway_log(SWAY_DEBUG, "Assigning configured mode to %s", output->name);
226 } 227 }
227 return wlr_output_set_mode(output, best); 228 wlr_output_set_mode(output, best);
228} 229}
229 230
230bool apply_output_config(struct output_config *oc, struct sway_output *output) { 231bool 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) {
241 wlr_output_layout_remove(root->output_layout, wlr_output); 242 wlr_output_layout_remove(root->output_layout, wlr_output);
242 } 243 }
243 wlr_output_enable(wlr_output, false); 244 wlr_output_enable(wlr_output, false);
244 return true; 245 return wlr_output_commit(wlr_output);
245 } else if (!output->enabled) { 246 } else if (!output->enabled) {
246 // Output is not enabled. Enable it, output_enable will call us again. 247 // Output is not enabled. Enable it, output_enable will call us again.
247 if (!oc || oc->dpms_state != DPMS_OFF) { 248 if (!oc || oc->dpms_state != DPMS_OFF) {
248 wlr_output_enable(wlr_output, true); 249 wlr_output_enable(wlr_output, true);
250 wlr_output_commit(wlr_output);
249 } 251 }
250 output_enable(output, oc); 252 output_enable(output, oc);
251 return true; 253 return true;
@@ -256,26 +258,14 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
256 wlr_output_enable(wlr_output, true); 258 wlr_output_enable(wlr_output, true);
257 } 259 }
258 260
259 bool modeset_success; 261 struct wlr_output_mode *preferred_mode =
262 wlr_output_preferred_mode(wlr_output);
260 if (oc && oc->width > 0 && oc->height > 0) { 263 if (oc && oc->width > 0 && oc->height > 0) {
261 sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width, 264 sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f GHz)", oc->name, oc->width,
262 oc->height, oc->refresh_rate); 265 oc->height, oc->refresh_rate);
263 modeset_success = 266 set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate);
264 set_mode(wlr_output, oc->width, oc->height, oc->refresh_rate); 267 } else if (preferred_mode != NULL) {
265 } else if (!wl_list_empty(&wlr_output->modes)) { 268 wlr_output_set_mode(wlr_output, preferred_mode);
266 struct wlr_output_mode *mode =
267 wl_container_of(wlr_output->modes.prev, mode, link);
268 modeset_success = wlr_output_set_mode(wlr_output, mode);
269 } else {
270 // Output doesn't support modes
271 modeset_success = true;
272 }
273 if (!modeset_success) {
274 // Failed to modeset, maybe the output is missing a CRTC. Leave the
275 // output disabled for now and try again when the output gets the mode
276 // we asked for.
277 sway_log(SWAY_ERROR, "Failed to modeset output %s", wlr_output->name);
278 return false;
279 } 269 }
280 270
281 if (oc && oc->scale > 0) { 271 if (oc && oc->scale > 0) {
@@ -295,6 +285,14 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
295 wlr_output_set_transform(wlr_output, oc->transform); 285 wlr_output_set_transform(wlr_output, oc->transform);
296 } 286 }
297 287
288 if (!wlr_output_commit(wlr_output)) {
289 // Failed to modeset, maybe the output is missing a CRTC. Leave the
290 // output disabled for now and try again when the output gets the mode
291 // we asked for.
292 sway_log(SWAY_ERROR, "Failed to modeset output %s", wlr_output->name);
293 return false;
294 }
295
298 // Find position for it 296 // Find position for it
299 if (oc && (oc->x != -1 || oc->y != -1)) { 297 if (oc && (oc->x != -1 || oc->y != -1)) {
300 sway_log(SWAY_DEBUG, "Set %s position to %d, %d", oc->name, oc->x, oc->y); 298 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) {
314 if (oc && oc->dpms_state == DPMS_OFF) { 312 if (oc && oc->dpms_state == DPMS_OFF) {
315 sway_log(SWAY_DEBUG, "Turning off screen"); 313 sway_log(SWAY_DEBUG, "Turning off screen");
316 wlr_output_enable(wlr_output, false); 314 wlr_output_enable(wlr_output, false);
315 wlr_output_commit(wlr_output);
317 } 316 }
318 317
319 return true; 318 return true;
@@ -322,12 +321,12 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
322static void default_output_config(struct output_config *oc, 321static void default_output_config(struct output_config *oc,
323 struct wlr_output *wlr_output) { 322 struct wlr_output *wlr_output) {
324 oc->enabled = 1; 323 oc->enabled = 1;
325 if (!wl_list_empty(&wlr_output->modes)) { 324 struct wlr_output_mode *preferred_mode =
326 struct wlr_output_mode *mode = 325 wlr_output_preferred_mode(wlr_output);
327 wl_container_of(wlr_output->modes.prev, mode, link); 326 if (preferred_mode != NULL) {
328 oc->width = mode->width; 327 oc->width = preferred_mode->width;
329 oc->height = mode->height; 328 oc->height = preferred_mode->height;
330 oc->refresh_rate = mode->refresh; 329 oc->refresh_rate = preferred_mode->refresh;
331 } 330 }
332 oc->x = oc->y = -1; 331 oc->x = oc->y = -1;
333 oc->scale = 1; 332 oc->scale = 1;