From 60d7cd82ba7dcaff2f7b45226fe0782a8dbf24e6 Mon Sep 17 00:00:00 2001 From: Robert Mader Date: Thu, 30 Dec 2021 21:29:25 +0100 Subject: [PATCH] crtc-mode-xrandr: Take RR_DoubleScan and RR_Interlace flags into account MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Otherwise we often advertise wrongly calculated modes. Original patch from Jonas Ã…dahl and the xrandr project. Closes https://gitlab.gnome.org/GNOME/mutter/-/issues/275 Part-of: --- src/backends/x11/meta-gpu-xrandr.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/backends/x11/meta-gpu-xrandr.c b/src/backends/x11/meta-gpu-xrandr.c index bc3292d36..6c84be6ce 100644 --- a/src/backends/x11/meta-gpu-xrandr.c +++ b/src/backends/x11/meta-gpu-xrandr.c @@ -86,6 +86,24 @@ get_xmode_name (XRRModeInfo *xmode) return g_strdup_printf ("%dx%d", width, height); } +static float +calculate_xrandr_refresh_rate (XRRModeInfo *xmode) +{ + float h_total; + float v_total; + + h_total = (float) xmode->hTotal; + v_total = (float) xmode->vTotal; + + if (xmode->modeFlags & RR_DoubleScan) + v_total *= 2.0; + + if (xmode->modeFlags & RR_Interlace) + v_total /= 2.0; + + return xmode->dotClock / (h_total * v_total); +} + static gboolean meta_gpu_xrandr_read_current (MetaGpu *gpu, GError **error) @@ -148,8 +166,7 @@ meta_gpu_xrandr_read_current (MetaGpu *gpu, crtc_mode_info = meta_crtc_mode_info_new (); crtc_mode_info->width = xmode->width; crtc_mode_info->height = xmode->height; - crtc_mode_info->refresh_rate = (xmode->dotClock / - ((float)xmode->hTotal * xmode->vTotal)); + crtc_mode_info->refresh_rate = calculate_xrandr_refresh_rate (xmode); crtc_mode_info->flags = xmode->modeFlags; crtc_mode_name = get_xmode_name (xmode);