From 8e3d7e30e34ffb181a600e12e74727737e0c1f76 Mon Sep 17 00:00:00 2001 From: Tomi Valkeinen Date: Thu, 29 Sep 2016 10:55:19 +0300 Subject: Improve mode finding Change calculated_vrefresh to round to 2 decimals, and do two rounds when looking for a mode: first look for exact vrefresh match, then look for rounded match. Signed-off-by: Tomi Valkeinen --- kms++/src/connector.cpp | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'kms++/src/connector.cpp') diff --git a/kms++/src/connector.cpp b/kms++/src/connector.cpp index 92700af..7c6c179 100644 --- a/kms++/src/connector.cpp +++ b/kms++/src/connector.cpp @@ -132,7 +132,24 @@ Videomode Connector::get_mode(unsigned xres, unsigned yres, float vrefresh, bool if (ilace != m.interlace()) continue; - if (vrefresh && std::abs(m.calculated_vrefresh() - vrefresh) >= 0.001) + if (vrefresh && vrefresh != m.calculated_vrefresh()) + continue; + + return m; + } + + // If not found, do another round using rounded vrefresh + + for (int i = 0; i < c->count_modes; i++) { + Videomode m = drm_mode_to_video_mode(c->modes[i]); + + if (m.hdisplay != xres || m.vdisplay != yres) + continue; + + if (ilace != m.interlace()) + continue; + + if (vrefresh && vrefresh != roundf(m.calculated_vrefresh())) continue; return m; -- cgit v1.2.3