From 5ba839e83b61b240be3e9fdc5ab5f0b516d06bc2 Mon Sep 17 00:00:00 2001 From: Caiyi Hsu Date: Sat, 27 Jan 2024 11:25:43 +0800 Subject: [PATCH] fix XRandR refresh rate calculation --- src/video/x11/SDL_x11modes.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index 3ba4f60498..ed8dd534c3 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -402,8 +402,21 @@ static SDL_bool CheckXRandR(Display *display, int *major, int *minor) static float CalculateXRandRRefreshRate(const XRRModeInfo *info) { - if (info->hTotal && info->vTotal) { - return ((100 * (Sint64)info->dotClock) / (info->hTotal * info->vTotal)) / 100.0f; + double vTotal = info->vTotal; + + if (info->modeFlags & RR_DoubleScan) { + /* doublescan doubles the number of lines */ + vTotal *= 2; + } + + if (info->modeFlags & RR_Interlace) { + /* interlace splits the frame into two fields */ + /* the field rate is what is typically reported by monitors */ + vTotal /= 2; + } + + if (info->hTotal && vTotal) { + return ((100 * (Sint64)info->dotClock) / (info->hTotal * vTotal)) / 100.0f; } return 0.0f; }