From: Mikko Rasa Date: Thu, 6 Jun 2019 09:32:35 +0000 (+0300) Subject: Match against current rate if no request for a specific rate was made X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=5831f82382a1ba7ca37f0e47aea984460eea47dd;p=libs%2Fgui.git Match against current rate if no request for a specific rate was made --- diff --git a/source/graphics/display.cpp b/source/graphics/display.cpp index ebf14ea..7f0b25a 100644 --- a/source/graphics/display.cpp +++ b/source/graphics/display.cpp @@ -40,27 +40,34 @@ void Display::restore_mode() const VideoMode *Display::find_mode(const VideoMode &mode, float rate_tolerance) const { const VideoMode *closest = 0; - float rate_diff = mode.rate; + float rate_diff = 0.0f; + + float target_rate = mode.rate; + if(!target_rate && mode.monitor) + if(const VideoMode *current_mode = mode.monitor->current_settings.mode) + target_rate = current_mode->rate; + for(list::const_iterator i=modes.begin(); i!=modes.end(); ++i) { if(mode.monitor && i->monitor!=mode.monitor) continue; + // Only check rate tolerance against an explicitly requested rate if(mode.rate && (i->raterate>mode.rate+rate_tolerance)) continue; if(i->width!=mode.width || i->height!=mode.height) continue; - if(mode.rate) + float ref_rate = target_rate; + if(!ref_rate) + if(const VideoMode *current_mode = i->monitor->current_settings.mode) + ref_rate = current_mode->rate; + + float d = abs(i->rate-ref_rate); + if(!closest || drate-mode.rate); - if(d