From 9ffb9f22faf7c540083e6df828500d54aabcbb56 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Tue, 20 Oct 2015 19:31:41 +0300 Subject: [PATCH] Use float rather than unsigned for refresh rate Display::set_mode now accepts a rate which is within +-0.5 Hz of requested and chooses the closest match if there are more than one. --- source/graphics/display.cpp | 23 +++++++++++++++++++---- source/graphics/display.h | 2 +- source/graphics/videomode.h | 2 +- source/graphics/x11/display.cpp | 2 +- 4 files changed, 22 insertions(+), 7 deletions(-) diff --git a/source/graphics/display.cpp b/source/graphics/display.cpp index de5a069..40112a3 100644 --- a/source/graphics/display.cpp +++ b/source/graphics/display.cpp @@ -1,3 +1,4 @@ +#include #include "display.h" #include "display_private.h" #include "window.h" @@ -31,19 +32,33 @@ void Display::restore_mode() set_mode(*i->desktop_mode, false); } -const VideoMode *Display::find_mode(const VideoMode &mode) const +const VideoMode *Display::find_mode(const VideoMode &mode, float rate_tolerance) const { + const VideoMode *closest = 0; + float rate_diff = mode.rate; for(list::const_iterator i=modes.begin(); i!=modes.end(); ++i) { if(mode.monitor && i->monitor!=mode.monitor) continue; - if(mode.rate && i->rate!=mode.rate) + if(mode.rate && (i->raterate>mode.rate+rate_tolerance)) continue; - if(i->width==mode.width && i->height==mode.height) + if(i->width!=mode.width || i->height!=mode.height) + continue; + + if(mode.rate) + { + float d = abs(i->rate-mode.rate); + if(dwidth, info->height); mode.index = modes.size(); mode.monitor = &monitor; - mode.rate = info->dotClock/(info->hTotal*info->vTotal); + mode.rate = static_cast(info->dotClock)/(info->hTotal*info->vTotal); if(find_mode(mode)) continue; -- 2.45.2