aboutsummaryrefslogtreecommitdiffstats
path: root/sway/config/output.c
diff options
context:
space:
mode:
Diffstat (limited to 'sway/config/output.c')
-rw-r--r--sway/config/output.c58
1 files changed, 53 insertions, 5 deletions
diff --git a/sway/config/output.c b/sway/config/output.c
index c9ec6745..8e937b28 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -8,6 +8,7 @@
8#include <wlr/types/wlr_cursor.h> 8#include <wlr/types/wlr_cursor.h>
9#include <wlr/types/wlr_output_layout.h> 9#include <wlr/types/wlr_output_layout.h>
10#include <wlr/types/wlr_output.h> 10#include <wlr/types/wlr_output.h>
11#include <wlr/backend/drm.h>
11#include "sway/config.h" 12#include "sway/config.h"
12#include "sway/input/cursor.h" 13#include "sway/input/cursor.h"
13#include "sway/output.h" 14#include "sway/output.h"
@@ -58,6 +59,7 @@ struct output_config *new_output_config(const char *name) {
58 oc->width = oc->height = -1; 59 oc->width = oc->height = -1;
59 oc->refresh_rate = -1; 60 oc->refresh_rate = -1;
60 oc->custom_mode = -1; 61 oc->custom_mode = -1;
62 oc->drm_mode.type = -1;
61 oc->x = oc->y = -1; 63 oc->x = oc->y = -1;
62 oc->scale = -1; 64 oc->scale = -1;
63 oc->scale_filter = SCALE_FILTER_DEFAULT; 65 oc->scale_filter = SCALE_FILTER_DEFAULT;
@@ -99,6 +101,9 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
99 if (src->custom_mode != -1) { 101 if (src->custom_mode != -1) {
100 dst->custom_mode = src->custom_mode; 102 dst->custom_mode = src->custom_mode;
101 } 103 }
104 if (src->drm_mode.type != (uint32_t) -1) {
105 memcpy(&dst->drm_mode, &src->drm_mode, sizeof(src->drm_mode));
106 }
102 if (src->transform != -1) { 107 if (src->transform != -1) {
103 dst->transform = src->transform; 108 dst->transform = src->transform;
104 } 109 }
@@ -271,6 +276,18 @@ static void set_mode(struct wlr_output *output, int width, int height,
271 wlr_output_set_mode(output, best); 276 wlr_output_set_mode(output, best);
272} 277}
273 278
279static void set_modeline(struct wlr_output *output, drmModeModeInfo *drm_mode) {
280 if (!wlr_output_is_drm(output)) {
281 sway_log(SWAY_ERROR, "Modeline can only be set to DRM output");
282 return;
283 }
284 sway_log(SWAY_DEBUG, "Assigning custom modeline to %s", output->name);
285 struct wlr_output_mode *mode = wlr_drm_connector_add_mode(output, drm_mode);
286 if (mode) {
287 wlr_output_set_mode(output, mode);
288 }
289}
290
274/* Some manufacturers hardcode the aspect-ratio of the output in the physical 291/* Some manufacturers hardcode the aspect-ratio of the output in the physical
275 * size field. */ 292 * size field. */
276static bool phys_size_is_aspect_ratio(struct wlr_output *output) { 293static bool phys_size_is_aspect_ratio(struct wlr_output *output) {
@@ -351,14 +368,36 @@ static void queue_output_config(struct output_config *oc,
351 sway_log(SWAY_DEBUG, "Turning on output %s", wlr_output->name); 368 sway_log(SWAY_DEBUG, "Turning on output %s", wlr_output->name);
352 wlr_output_enable(wlr_output, true); 369 wlr_output_enable(wlr_output, true);
353 370
354 if (oc && oc->width > 0 && oc->height > 0) { 371 if (oc && oc->drm_mode.type != 0 && oc->drm_mode.type != (uint32_t) -1) {
372 sway_log(SWAY_DEBUG, "Set %s modeline",
373 wlr_output->name);
374 set_modeline(wlr_output, &oc->drm_mode);
375 } else if (oc && oc->width > 0 && oc->height > 0) {
355 sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f Hz)", 376 sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f Hz)",
356 wlr_output->name, oc->width, oc->height, oc->refresh_rate); 377 wlr_output->name, oc->width, oc->height, oc->refresh_rate);
357 set_mode(wlr_output, oc->width, oc->height, 378 set_mode(wlr_output, oc->width, oc->height,
358 oc->refresh_rate, oc->custom_mode == 1); 379 oc->refresh_rate, oc->custom_mode == 1);
359 } else if (!wl_list_empty(&wlr_output->modes)) { 380 } else if (!wl_list_empty(&wlr_output->modes)) {
360 struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output); 381 sway_log(SWAY_DEBUG, "Set preferred mode");
361 wlr_output_set_mode(wlr_output, mode); 382 struct wlr_output_mode *preferred_mode =
383 wlr_output_preferred_mode(wlr_output);
384 wlr_output_set_mode(wlr_output, preferred_mode);
385
386 if (!wlr_output_test(wlr_output)) {
387 sway_log(SWAY_DEBUG, "Preferred mode rejected, "
388 "falling back to another mode");
389 struct wlr_output_mode *mode;
390 wl_list_for_each(mode, &wlr_output->modes, link) {
391 if (mode == preferred_mode) {
392 continue;
393 }
394
395 wlr_output_set_mode(wlr_output, mode);
396 if (wlr_output_test(wlr_output)) {
397 break;
398 }
399 }
400 }
362 } 401 }
363 402
364 if (oc && (oc->subpixel != WL_OUTPUT_SUBPIXEL_UNKNOWN || config->reloading)) { 403 if (oc && (oc->subpixel != WL_OUTPUT_SUBPIXEL_UNKNOWN || config->reloading)) {
@@ -367,9 +406,16 @@ static void queue_output_config(struct output_config *oc,
367 wlr_output_set_subpixel(wlr_output, oc->subpixel); 406 wlr_output_set_subpixel(wlr_output, oc->subpixel);
368 } 407 }
369 408
409 enum wl_output_transform tr = WL_OUTPUT_TRANSFORM_NORMAL;
370 if (oc && oc->transform >= 0) { 410 if (oc && oc->transform >= 0) {
371 sway_log(SWAY_DEBUG, "Set %s transform to %d", oc->name, oc->transform); 411 tr = oc->transform;
372 wlr_output_set_transform(wlr_output, oc->transform); 412 } else if (wlr_output_is_drm(wlr_output)) {
413 tr = wlr_drm_connector_get_panel_orientation(wlr_output);
414 sway_log(SWAY_DEBUG, "Auto-detected output transform: %d", tr);
415 }
416 if (wlr_output->transform != tr) {
417 sway_log(SWAY_DEBUG, "Set %s transform to %d", oc->name, tr);
418 wlr_output_set_transform(wlr_output, tr);
373 } 419 }
374 420
375 // Apply the scale last before the commit, because the scale auto-detection 421 // Apply the scale last before the commit, because the scale auto-detection
@@ -483,6 +529,8 @@ bool apply_output_config(struct output_config *oc, struct sway_output *output) {
483 // this output came online, and some config items (like map_to_output) are 529 // this output came online, and some config items (like map_to_output) are
484 // dependent on an output being present. 530 // dependent on an output being present.
485 input_manager_configure_all_inputs(); 531 input_manager_configure_all_inputs();
532 // Reconfigure the cursor images, since the scale may have changed.
533 input_manager_configure_xcursor();
486 return true; 534 return true;
487} 535}
488 536