[gnome-flashback] monitor: add mode spec helper checking resolution similarness



commit 43649800236a869a26a5ca157c6891c88b13bb8a
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Fri Aug 19 20:34:53 2022 +0300

    monitor: add mode spec helper checking resolution similarness
    
    Based on mutter commit:
    https://gitlab.gnome.org/GNOME/mutter/-/commit/4580bca664bb1f421c28614b66154ba4a0027831

 backends/gf-monitor-private.h |  3 +++
 backends/gf-monitor.c         | 19 +++++++++++++++++++
 2 files changed, 22 insertions(+)
---
diff --git a/backends/gf-monitor-private.h b/backends/gf-monitor-private.h
index 6a10ec9..ce6ea98 100644
--- a/backends/gf-monitor-private.h
+++ b/backends/gf-monitor-private.h
@@ -182,6 +182,9 @@ GfLogicalMonitor   *gf_monitor_get_logical_monitor        (GfMonitor
 GfMonitorMode      *gf_monitor_get_mode_from_id           (GfMonitor                  *monitor,
                                                            const gchar                *monitor_mode_id);
 
+gboolean            gf_monitor_mode_spec_has_similar_size (GfMonitorModeSpec          *monitor_mode_spec,
+                                                           GfMonitorModeSpec          
*other_monitor_mode_spec);
+
 GfMonitorMode      *gf_monitor_get_mode_from_spec         (GfMonitor                  *monitor,
                                                            GfMonitorModeSpec          *monitor_mode_spec);
 
diff --git a/backends/gf-monitor.c b/backends/gf-monitor.c
index deae884..0afb79c 100644
--- a/backends/gf-monitor.c
+++ b/backends/gf-monitor.c
@@ -966,6 +966,25 @@ gf_monitor_get_mode_from_id (GfMonitor   *monitor,
   return g_hash_table_lookup (priv->mode_ids, monitor_mode_id);
 }
 
+gboolean
+gf_monitor_mode_spec_has_similar_size (GfMonitorModeSpec *monitor_mode_spec,
+                                       GfMonitorModeSpec *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);
+}
+
 GfMonitorMode *
 gf_monitor_get_mode_from_spec (GfMonitor         *monitor,
                                GfMonitorModeSpec *monitor_mode_spec)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]