aboutsummaryrefslogtreecommitdiff
path: root/sway/config
diff options
context:
space:
mode:
authorDavid Rosca <nowrep@gmail.com>2021-07-18 12:05:47 +0200
committerSimon Ser <contact@emersion.fr>2021-08-31 17:29:40 +0200
commit57d6f6f19e3088dcb8e202acade8c39a80075b4a (patch)
treea1efb14a17b60ac278c1221ed907671a822dabfd /sway/config
parentdaaec72ac01f66fda8b3eabe6e11e461f2e0f31d (diff)
Add `output modeline` command
Only works with DRM backend.
Diffstat (limited to 'sway/config')
-rw-r--r--sway/config/output.c23
1 files changed, 22 insertions, 1 deletions
diff --git a/sway/config/output.c b/sway/config/output.c
index 6224fc10..9fff79fd 100644
--- a/sway/config/output.c
+++ b/sway/config/output.c
@@ -8,6 +8,7 @@
#include <wlr/types/wlr_cursor.h>
#include <wlr/types/wlr_output_layout.h>
#include <wlr/types/wlr_output.h>
+#include <wlr/backend/drm.h>
#include "sway/config.h"
#include "sway/input/cursor.h"
#include "sway/output.h"
@@ -58,6 +59,7 @@ struct output_config *new_output_config(const char *name) {
oc->width = oc->height = -1;
oc->refresh_rate = -1;
oc->custom_mode = -1;
+ oc->drm_mode.type = -1;
oc->x = oc->y = -1;
oc->scale = -1;
oc->scale_filter = SCALE_FILTER_DEFAULT;
@@ -99,6 +101,9 @@ void merge_output_config(struct output_config *dst, struct output_config *src) {
if (src->custom_mode != -1) {
dst->custom_mode = src->custom_mode;
}
+ if (src->drm_mode.type != (uint32_t) -1) {
+ memcpy(&dst->drm_mode, &src->drm_mode, sizeof(src->drm_mode));
+ }
if (src->transform != -1) {
dst->transform = src->transform;
}
@@ -271,6 +276,18 @@ static void set_mode(struct wlr_output *output, int width, int height,
wlr_output_set_mode(output, best);
}
+static void set_modeline(struct wlr_output *output, drmModeModeInfo *drm_mode) {
+ if (!wlr_output_is_drm(output)) {
+ sway_log(SWAY_ERROR, "Modeline can only be set to DRM output");
+ return;
+ }
+ sway_log(SWAY_DEBUG, "Assigning custom modeline to %s", output->name);
+ struct wlr_output_mode *mode = wlr_drm_connector_add_mode(output, drm_mode);
+ if (mode) {
+ wlr_output_set_mode(output, mode);
+ }
+}
+
/* Some manufacturers hardcode the aspect-ratio of the output in the physical
* size field. */
static bool phys_size_is_aspect_ratio(struct wlr_output *output) {
@@ -351,7 +368,11 @@ static void queue_output_config(struct output_config *oc,
sway_log(SWAY_DEBUG, "Turning on output %s", wlr_output->name);
wlr_output_enable(wlr_output, true);
- if (oc && oc->width > 0 && oc->height > 0) {
+ if (oc && oc->drm_mode.type != 0 && oc->drm_mode.type != (uint32_t) -1) {
+ sway_log(SWAY_DEBUG, "Set %s modeline",
+ wlr_output->name);
+ set_modeline(wlr_output, &oc->drm_mode);
+ } else if (oc && oc->width > 0 && oc->height > 0) {
sway_log(SWAY_DEBUG, "Set %s mode to %dx%d (%f Hz)",
wlr_output->name, oc->width, oc->height, oc->refresh_rate);
set_mode(wlr_output, oc->width, oc->height,