Skip to content
Advertisement

How to get supported display refresh rates on Linux?

drmModeModeInfo structure from DRM contains uint32_t vrefresh; field, and the values are actually good there i.e. I’m getting 24-75Hz for different video modes. But refresh rates aren’t integers, they’re rational numbers, right now for my display the value is 59997/1000.

Is it possible to get the precise numbers on Linux? Or at least a floating point value?

Advertisement

Answer

The numerator is drmModeModeInfo::clock * 1000, the clock field is in kilohertz and we need Hz for the formula.

The denominator is the product of drmModeModeInfo::htotal and drmModeModeInfo::vtotal fields.

For better result, I simplify the rational by dividing both numerator and denominator by their greatest common divisor. For this part, I have used an algorithm from Wikipedia.

I’m not sure if current displays support signal frequencies above 2^32 Hz = 4.29 GHz, but even if they do not, future ones may do so, i.e. you better use 64-bit integer math there.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement