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<VideoMode>::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->rate<mode.rate-rate_tolerance || i->rate>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 || d<rate_diff)
{
- float d = abs(i->rate-mode.rate);
- if(d<rate_diff)
- {
- closest = &*i;
- rate_diff = d;
- }
+ closest = &*i;
+ rate_diff = d;
}
- else
- return &*i;
}
return closest;