monitor: Add mode spec helper checking resolution similarness

If two modes are roughly the same, they should probably use the same UI
scaling factor. I.e. for the same monitor, if a 4K mode was configured to
have a certain scaling factor, and we generate a new configuration with
a similar sized 4K mode, we should re-use the scale previously
configured; however if we e.g. go from a 4K mode to a FHD mode, we
shouldn't.

This allows implementing better hueristics when using the switch-config
feature, where we'd be less likely to loose the for a certain monitor
mode combination previously configured scaling factor.

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/2479>
This commit is contained in:
Jonas Ådahl
2022-07-27 00:25:22 +02:00
committed by Marge Bot
parent 71bf31da83
commit 4580bca664
5 changed files with 171 additions and 1 deletions

View File

@ -1542,6 +1542,24 @@ meta_monitor_get_mode_from_id (MetaMonitor *monitor,
return g_hash_table_lookup (priv->mode_ids, monitor_mode_id);
}
gboolean
meta_monitor_mode_spec_has_similar_size (MetaMonitorModeSpec *monitor_mode_spec,
MetaMonitorModeSpec *other_monitor_mode_spec)
{
const float target_ratio = 1.0;
/* The a size difference of 15% means e.g. 4K modes matches other 4K modes,
* FHD (2K) modes other FHD modes, and HD modes other HD modes, but not each
* other.
*/
const float epsilon = 0.15;
return G_APPROX_VALUE (((float) monitor_mode_spec->width /
other_monitor_mode_spec->width) *
((float) monitor_mode_spec->height /
other_monitor_mode_spec->height),
target_ratio, epsilon);
}
static gboolean
meta_monitor_mode_spec_equals (MetaMonitorModeSpec *monitor_mode_spec,
MetaMonitorModeSpec *other_monitor_mode_spec)