]> git.tdb.fi Git - libs/gui.git/commitdiff
Match against current rate if no request for a specific rate was made
authorMikko Rasa <tdb@tdb.fi>
Thu, 6 Jun 2019 09:32:35 +0000 (12:32 +0300)
committerMikko Rasa <tdb@tdb.fi>
Thu, 6 Jun 2019 09:32:35 +0000 (12:32 +0300)
source/graphics/display.cpp

index ebf14ea489c9d1befa6c8efd192a12806d5833d6..7f0b25af22f77d177ef244daa3997bc809b7951f 100644 (file)
@@ -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<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;