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.c47
1 files changed, 44 insertions, 3 deletions
diff --git a/sway/config/output.c b/sway/config/output.c
index c9ec6745..9fff79fd 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)) {
@@ -483,6 +522,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 522 // this output came online, and some config items (like map_to_output) are
484 // dependent on an output being present. 523 // dependent on an output being present.
485 input_manager_configure_all_inputs(); 524 input_manager_configure_all_inputs();
525 // Reconfigure the cursor images, since the scale may have changed.
526 input_manager_configure_xcursor();
486 return true; 527 return true;
487} 528}
488 529