Skip to content

RANDR user modes: xrandr --newmode/--addmode work - #372

Merged
joske merged 14 commits into
masterfrom
feat/randr-user-modes
Nov 17, 2026
Merged

joske merged 14 commits into
masterfrom
feat/randr-user-modes

Conversation

@joske

@joske joske commented Nov 17, 2026

Copy link
Copy Markdown
Owner

xrandr --newmode, --addmode, --output … --mode <user mode>, --delmode and --rmmode now work as on Xorg. Before, --newmode failed with BadImplementation and --addmode/--delmode did nothing, so a monitor whose EDID doesn't reach the GPU (e.g. over VGA) was stuck at the kernel's fallback modes, up to 1024x768.

  • The four RANDR requests follow Xorg 21.1.24: same checks, errors and events, measured against Xvfb. User modes belong to the server, so they survive the client that created them (.xinitrc lines work).
  • On KMS the mode is programmed from its timings, as Xorg's modesetting driver does. A mode the driver refuses answers Configure crtc failed and leaves the output as it was. The mode is kept across VT switches and screen blanking.
  • On the macOS and Windows hosts a user mode resizes the window. RANDR 1.0 clients (xrandr --q1) see user modes as sizes and rates.
  • Also fixed on the way: RRScreenChangeNotify always reported size index 0, and on machines that had handed out 255 RANDR ids the next one was the root window's id.

xorg.conf Monitor Modelines stay unsupported; the xrandr lines do the same job.

Closes #360.

Testing

Unit tests against Xorg's source and Xvfb measurements, lavapipe suite, and a new vng scenario xrandr-usermode with a golden from Xorg. On an RX 6800 with two DP/HDMI monitors under XFCE: a new 1600x900@50 mode set, kept across a VT switch and DPMS; a 2000 MHz mode refused with the screen staying lit. Not yet tested on an EDID-less VGA output (#360) or a two-GPU machine.

🤖 Generated with Claude Code

joske and others added 14 commits November 17, 2026 12:58
The KMS RandrIdAllocator counted up from 1 in client 0's space, so its
256th id was 0x100, the root window's XID; rescans and new modes make
that reachable over a server's lifetime.

Client 0's space now has bounded ranges, defined next to
FIRST_CLIENT_BASE and checked at compile time: fixed server XIDs
0x1..=0xFFF, backend RANDR ids 0x10000..=0x7FFFF, user modes
0x80000..=0xFFFFF (defined only, nothing allocates there yet). The KMS
allocator starts at the backend range and never leaves it.

Running out (458752 ids) logs once and answers 0, RANDR's None, which
is no resource's XID; the projection leaves out outputs, CRTCs, modes
and providers that got it. This keeps the allocator's callers and the
connector registry unchanged, where an Option would have run through
every ids_for/mode_id caller and the entry_mut contract.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…eteOutputMode

CreateMode answered BadImplementation and the other three were silent
no-ops, so `xrandr --newmode/--addmode/--delmode/--rmmode` could not work.

The modes live in ServerState::randr_user_modes beside state.randr, so
backend rebuilds (sets, probes, hotplug) keep them, client disconnect
keeps them (they are server-owned, rrmode.c:91-92) and a server reset
clears them with the fresh state. Ids come from the user-mode XID range;
running out answers BadAlloc.

The four requests follow Xorg's check order, errors and errorValues
(the last looked-up id, as measured on Xvfb). AddOutputMode bumps
lastConfigTime and sends ScreenChangeNotify plus the output's
OutputChangeNotify, no CrtcChangeNotify; the others send nothing.
CreateMode asks the policy CREATE on the new id, owned by the server,
and rejects names of user modes and of the advertised backend modes.
CreateMode gets its swap-table entry, leaving hSkew unswapped as
SProcRRCreateMode does.

RandrView projects the user modes into GetScreenResources(Current) (in
RRModesForScreen order), GetOutputInfo, GetCrtcInfo, the RANDR events,
SetCrtcConfig validation and access checks. SetCrtcConfig to a mode only
on the output's user list answers RRSetConfigFailed for now: the backends
still resolve a mode by size and refresh.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…t-mode match

The kernel mode's hskew was dropped and its flags masked to the low six
bits, so a CRTC's programmed timing could not be compared with a user
mode's. drm::Mode, ModeIdentity and ModeTiming now carry hskew, and
mode_timing keeps the fourteen RR_* flag bits (RR_HSyncPositive through
RR_ClockDivideBy2, bit-identical to DRM_MODE_FLAG_* 0-13), dropping only
DRM's 3D and aspect bits. ModeInfo replies for backend modes report both,
as Xorg does after drmmode_ConvertFromKMode.

VidMode's V_* flags agree with RR_* only on the low six bits, so
GetModeLine, GetAllModeLines and ValidateModeLine mask to those
themselves and answer as before.

RandrView reports a CRTC's mode as Xorg's xf86RandR12CrtcNotify does:
the first mode in the output's probed list, then its user list, whose
timing matches the programmed one (xf86RandRModeMatches: dotClock in
truncated kHz, every timing field with hSkew, flags under FLAG_BITS,
names ignored), else the backend id. A backend id replaced this way is
not advertised: not in GetScreenResources, not in events, BadRRMode for
requests, its synthesized name free for CreateMode.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SetCrtcConfig to a mode only on an output's user list answered
RRSetConfigFailed: the backends found a mode by width, height and refresh
in the connector's list, which a user mode is not in.

ModeSpec now carries the full timing for such a mode, converted as Xorg's
xf86RandRModeConvert does (clock dotClock / 1000 truncated, flags masked
to FLAG_BITS). KMS builds the kernel mode from it as drmmode_ConvertToKMode
(empty name, type 0, vscan and vrefresh 0) instead of looking it up, on the
synchronous path and through the PRIME qualifier helper, whose request
frame carries the timing. A kernel refusal is the existing Err, answered
with RRSetConfigFailed.

The no-op guard and the per-CRTC position shortcut compare the full
timing (ConnectorConfig::Enabled carries it), so a user mode with the
size and refresh of the current mode is programmed, not skipped. The
programmed mode is the live output's own, which rescans, DPMS on and VT
resume already reuse; the projection reports its timing and the core maps
it to the user mode id.

Backends declare whether they program timings. Nested, KMS-rootless and
the surface hosts (until their own commit) keep answering
RRSetConfigFailed for these modes without reaching the backend.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
SetCrtcConfig to a user mode on the macOS, Windows and headless window
output answered RRSetConfigFailed. The window output takes any size that
fits the root, so a user mode now sizes the window like the window's own
modes; rootless still refuses every CRTC set.

The window's synthetic mode list has no timing a user mode could match,
so the platform keeps the programmed user timing and reports it as the
CRTC's mode under its own id, off the window's list, as KMS reports a
kernel mode the connector does not list. The core's current-mode match
then answers the user mode id. A same-size user mode with other timing is
a change without a window request; any other output size (a window's own
mode, the user's resize, a clamped window) drops the timing. The window's
refresh stays the host's.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
GetScreenInfo listed only the output's probed modes, so a user mode
added with xrandr --addmode was no RANDR 1.0 size or rate, and while one
was current the reply named no current size. SetScreenConfig could not
reach a user mode.

RR10GetData now reads the RandrView projection: the first output's probed
modes then its user modes, one size per width x height in that order,
one rate per RRVerticalRefresh, the first mode of a rate taking it; the
current size and rate are those of the mode the CRTC reports, which need
not be the first of its rate. SetScreenConfig resolves the size and rate
to that mode as Xorg does and programs a mode off the output's own list
by its timing, like SetCrtcConfig. A backend that cannot program a timing
answers RRSetConfigFailed for it at the CRTC set, after any screen
resize, as a refusing crtcSet; the check moves into start_crtc_config,
which both requests share.

RRScreenChangeNotify carried sizeID 0; it is now RR10CurrentSizeID, the
index of the screen's size among those sizes, 0xffff without one.

Expected values from rrscreen.c (RR10GetData, ProcRRGetScreenInfo,
ProcRRSetScreenConfig, RR10CurrentSizeID) and an Xvfb run with four user
modes on its output.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
xrandr --newmode (and the duplicate's BadName), --addmode twice,
--output --mode to the user mode, --rmmode (BadAccess) and --delmode
(BadMatch) while it is current, back to the preferred mode, then --delmode
and --rmmode, with the verbose mode list, the RANDR 1.0 sizes and the root
size after each change. The mode, cvt 1000 700 50, is off the virtio-gpu
output's list.

The golden is the same script on Xorg in the guest (--regen-goldens); the
RANDR 1.0 index of the user size is masked, as it follows the driver's
probed list. A host half presses the scanout dump while the user mode is
current and requires 1000x700. Part of the quick set that pushes and PRs
run, like the other xrandr scenarios.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
@joske
joske force-pushed the feat/randr-user-modes branch from c68cef4 to 2b7b85a Compare November 17, 2026 11:58
@joske
joske merged commit 9fe01bd into master Nov 17, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

yserver support for monitor.conf or xrandr custom modes

1 participant