9

I'm building a utility that simplifies the complexities of defining and adding/removing custom resolutions with cvt and xrandr down to at least 2 command inputs.

The idea is to enter a custom resolution and frame rate (similar to how you'd do with cvt) on a specific port if using multiple, and see if your monitor on said port can display it.
The 2nd command is a simple y or n entry if your screen isn't black.

here's where the trick comes in, and the problem I'm running into...

If you enter n on the validation prompt, the screen should be reset to the previous resolution, which also includes the current resolution upon startup.

The problem I'm facing is it doesn't seem possible to obtain the current modeline upon startup of the utility.

Does anyone know of a way to obtain the EXACT modeline for xrandr --output ##### --mode <mode> or is that not a possibility??

1 Answer 1

8
+250

This is a quite old question, but in case anyone stumbles over the problem, here is the answer. From the command line the simplest way is using

> xrandr --verbose
[...]
DP-3 connected 1920x1080+0+0 (0x22d) normal (normal left inverted right x axis y axis) 641mm x 401mm
  1920x1080 (0x22d) 148.500MHz +HSync +VSync *current +preferred
    h: width  1920 start 2008 end 2052 total 2200 skew    0 clock  67.50KHz
    v: height 1080 start 1084 end 1089 total 1125           clock  60.00Hz
[...]

The corresponding modeline can be extracted from the numbers in the output, e.g.

Modeline "1920x1080_60"  148.5  1920 2008 2052 2200  1080 1084 1089 1125  +HSync +Vsync

In case you need to fix the modeline you can also manually add that modeline via xrandr.

> xrandr -d :1 --newmode "1920x1080_60" 148.5 1920 2008 2052 2200 1080 1084 1089 1125 +HSync -VSync
> xrandr --addmode DP-3 "1920x1080_60"      
> xrandr --output DP-3 --mode "1920x1080_60"

In case you are writing a program you might of course want to use libXrandr, especially its XRRGetOutputInfo function to read the desired information from the mode's XRRModeInfo struct.

2
  • thanks, sadly as of the age of this question, I'd actually forgotten I'd asked after losing both the motivation and the project, and having to deal with nvidia drivers instead which override xrandr.
    – Tcll
    Dec 16, 2020 at 21:56
  • And if you're trying to transfer this modeline to another display, you may have to add Xorg config Option "ModeValidation" "AllowNonEdidModes" if the receiving display has non-compatible EDID. Be prepared to restore the config if forcing the new mode causes the display to go blank. Typically something like xrandr --auto is good enough to fix the image. Use something like sleep 60 && xrandr --auto before trying forcing the mode and if you don't interrupt the sleep, you default display mode will be restored in 60 seconds. Dec 15, 2023 at 18:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .