Skip to content

x11: fix refresh rate reported as 0 for high pixel-clock modes#15888

Open
francisdb wants to merge 1 commit into
libsdl-org:mainfrom
francisdb:fix-x11-high-pixelclock-refresh-overflow
Open

x11: fix refresh rate reported as 0 for high pixel-clock modes#15888
francisdb wants to merge 1 commit into
libsdl-org:mainfrom
francisdb:fix-x11-high-pixelclock-refresh-overflow

Conversation

@francisdb

Copy link
Copy Markdown
  • I confirm that I am the author of this code and release it to the SDL project under the Zlib license. This contribution does not contain code from other sources , including code generated by a Large Language Model ("AI")

If the AI code completion part is a problem consider this an issue an let somebody else come up with a fix.

Description

On X11, SDL_GetDesktopDisplayMode() reports a refresh rate of 0 for high pixel-clock modes such as 4K@240Hz, while lower-clock modes on the same machine (4K@60, 1080p) are fine.

The X11 refresh-rate calculation overflows for those high pixel clocks and falls back to 0. It is a regression from when the calculation moved to the numerator/denominator representation, which dropped the wide-integer handling the earlier path had (#8933).

Testing

Reproduced with a small program calling SDL_GetDesktopDisplayMode() per display on a dual-monitor setup (a 4K@240Hz DP-1 and a 4K@60Hz portrait DP-4), and cross-checked against xrandr:

Display unpatched SDL (x11) patched SDL (x11) xrandr SDL (wayland)
DP-1 (240Hz) 0.000 (num=0) 239.980 (num=1626625000) 239.98 240.000
DP-4 (60Hz) 59.980 59.980 59.98 60.000

Note: this surfaced while running an SDL app under Xwayland, but it is not Xwayland-specific - the same overflow applies to any high pixel-clock mode on a native X server.

CalculateXRandRRefreshRate assigned the XRandR mode's dotClock (unsigned long)
directly into the int numerator. For high pixel-clock modes (e.g. 4K@240Hz the
pixel clock exceeds INT_MAX) the numerator overflowed to a negative value, so
SDL_GetDesktopDisplayMode reported a refresh rate of 0.

Compute the fraction in 64-bit and scale it down to fit the int numerator and
denominator while preserving the ratio.
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.

2 participants