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??


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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.