From b8c5891e7643c6d786cd5c8cdd2fef8dfb9ced7b Mon Sep 17 00:00:00 2001 From: "Maarten A." Date: Wed, 12 Nov 2025 22:01:19 +0100 Subject: [PATCH] Add mode_index to display configuration --- config.def.h | 8 +++++--- dwl.c | 14 +++++++++++++- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/config.def.h b/config.def.h index 22d2171..c942289 100644 --- a/config.def.h +++ b/config.def.h @@ -40,15 +40,17 @@ static const Layout layouts[] = { /* (x=-1, y=-1) is reserved as an "autoconfigure" monitor position indicator * WARNING: negative values other than (-1, -1) cause problems with Xwayland clients * https://gitlab.freedesktop.org/xorg/xserver/-/issues/899 + * + * mode: 0 based index of the display mode use -1 to use the preferred display mode */ /* NOTE: ALWAYS add a fallback rule, even if you are completely sure it won't be used */ static const MonitorRule monrules[] = { - /* name mfact nmaster scale layout rotate/reflect x y */ + /* name mfact nmaster scale layout rotate/reflect x y mode */ /* example of a HiDPI laptop monitor: - { "eDP-1", 0.5f, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, + { "eDP-1", 0.5f, 1, 2, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1, -1}, */ /* defaults */ - { NULL, 0.55f, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1 }, + { NULL, 0.55f, 1, 1, &layouts[0], WL_OUTPUT_TRANSFORM_NORMAL, -1, -1, -1}, }; /* keyboard */ diff --git a/dwl.c b/dwl.c index a2711f6..1f34b94 100644 --- a/dwl.c +++ b/dwl.c @@ -218,6 +218,7 @@ typedef struct { const Layout *lt; enum wl_output_transform rr; int x, y; + int mode_index; } MonitorRule; typedef struct { @@ -978,6 +979,7 @@ createmon(struct wl_listener *listener, void *data) const MonitorRule *r; size_t i; struct wlr_output_state state; + struct wlr_output_mode *mode = wlr_output_preferred_mode(wlr_output); Monitor *m; if (!wlr_output_init_render(wlr_output, alloc, drw)) @@ -1003,6 +1005,16 @@ createmon(struct wl_listener *listener, void *data) strncpy(m->ltsymbol, m->lt[m->sellt]->symbol, LENGTH(m->ltsymbol)); wlr_output_state_set_scale(&state, r->scale); wlr_output_state_set_transform(&state, r->rr); + if (r->mode_index >= 0 && !wl_list_empty(&wlr_output->modes)) { + int count = 0; + struct wlr_output_mode *mode_iter; + wl_list_for_each(mode_iter, &wlr_output->modes, link) { + if (count == r->mode_index) { + mode = mode_iter; + break; + } count++; + } + } break; } } @@ -1011,7 +1023,7 @@ createmon(struct wl_listener *listener, void *data) * monitor supports only a specific set of modes. We just pick the * monitor's preferred mode; a more sophisticated compositor would let * the user configure it. */ - wlr_output_state_set_mode(&state, wlr_output_preferred_mode(wlr_output)); + wlr_output_state_set_mode(&state, mode); /* Set up event listeners */ LISTEN(&wlr_output->events.frame, &m->frame, rendermon); -- 2.47.3