[gnome-flashback] monitor-manager: don't use wacky physical dimensions in display name



commit 5f29021fc279220f542ab2c8854d5b70d205597e
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Tue Jul 16 23:12:43 2019 +0300

    monitor-manager: don't use wacky physical dimensions in display name
    
    Based on mutter commit:
    https://gitlab.gnome.org/GNOME/mutter/commit/cbb2a286f2a7b55a486c

 backends/gf-monitor-manager.c | 55 ++++++++++++++++++++++++++++++-------------
 backends/gf-monitor-private.h |  2 ++
 backends/gf-monitor.c         | 19 +++++++++++----
 3 files changed, 55 insertions(+), 21 deletions(-)
---
diff --git a/backends/gf-monitor-manager.c b/backends/gf-monitor-manager.c
index 8cf0277..deee31f 100644
--- a/backends/gf-monitor-manager.c
+++ b/backends/gf-monitor-manager.c
@@ -971,39 +971,49 @@ diagonal_to_str (gdouble d)
 
 static gchar *
 make_display_name (GfMonitorManager *manager,
-                   GfOutput         *output)
+                   GfMonitor        *monitor)
 {
   gchar *inches;
   gchar *vendor_name;
+  const char *vendor;
+  const char *product_name;
+  int width_mm;
+  int height_mm;
 
-  if (gf_output_is_laptop (output))
+  if (gf_monitor_is_laptop_panel (monitor))
     return g_strdup (_("Built-in display"));
 
   inches = NULL;
   vendor_name = NULL;
+  vendor = gf_monitor_get_vendor (monitor);
+  product_name = NULL;
 
-  if (output->width_mm > 0 && output->height_mm > 0)
-    {
-      gint width_mm;
-      gint height_mm;
-      gdouble d;
+  gf_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm);
 
-      width_mm = output->width_mm;
-      height_mm = output->height_mm;
-      d = sqrt (width_mm * width_mm + height_mm * height_mm);
+  if (width_mm > 0 && height_mm > 0)
+    {
+      if (!gf_monitor_has_aspect_as_size (monitor))
+        {
+          double d;
 
-      inches = diagonal_to_str (d / 25.4);
+          d = sqrt (width_mm * width_mm + height_mm * height_mm);
+          inches = diagonal_to_str (d / 25.4);
+        }
+      else
+        {
+          product_name = gf_monitor_get_product (monitor);
+        }
     }
 
-  if (g_strcmp0 (output->vendor, "unknown") != 0)
+  if (g_strcmp0 (vendor, "unknown") != 0)
     {
       if (!manager->pnp_ids)
         manager->pnp_ids = gnome_pnp_ids_new ();
 
-      vendor_name = gnome_pnp_ids_get_pnp_id (manager->pnp_ids, output->vendor);
+      vendor_name = gnome_pnp_ids_get_pnp_id (manager->pnp_ids, vendor);
 
       if (!vendor_name)
-        vendor_name = g_strdup (output->vendor);
+        vendor_name = g_strdup (vendor);
     }
   else
     {
@@ -1025,6 +1035,19 @@ make_display_name (GfMonitorManager *manager,
       g_free (vendor_name);
       g_free (inches);
 
+      return display_name;
+    }
+  else if (product_name != NULL)
+    {
+      gchar *display_name;
+
+      /* Translators: this is a monitor vendor name followed by
+       * product/model name where size in inches could not be calculated,
+       * e.g. Dell U2414H
+       */
+      display_name =  g_strdup_printf (_("%s %s"), vendor_name, product_name);
+      g_free (vendor_name);
+
       return display_name;
     }
 
@@ -1566,7 +1589,6 @@ gf_monitor_manager_handle_get_current_state (GfDBusDisplayConfig   *skeleton,
       GVariantBuilder monitor_properties_builder;
       GList *k;
       gboolean is_builtin;
-      GfOutput *main_output;
       gchar *display_name;
       gint i;
 
@@ -1653,8 +1675,7 @@ gf_monitor_manager_handle_get_current_state (GfDBusDisplayConfig   *skeleton,
                              "is-builtin",
                              g_variant_new_boolean (is_builtin));
 
-      main_output = gf_monitor_get_main_output (monitor);
-      display_name = make_display_name (manager, main_output);
+      display_name = make_display_name (manager, monitor);
       g_variant_builder_add (&monitor_properties_builder, "{sv}",
                              "display-name",
                              g_variant_new_take_string (display_name));
diff --git a/backends/gf-monitor-private.h b/backends/gf-monitor-private.h
index e130aa7..c7f8d23 100644
--- a/backends/gf-monitor-private.h
+++ b/backends/gf-monitor-private.h
@@ -228,6 +228,8 @@ gboolean            gf_monitor_mode_foreach_output        (GfMonitor
 gboolean            gf_verify_monitor_mode_spec           (GfMonitorModeSpec          *mode_spec,
                                                            GError                    **error);
 
+gboolean            gf_monitor_has_aspect_as_size         (GfMonitor                  *monitor);
+
 G_END_DECLS
 
 #endif
diff --git a/backends/gf-monitor.c b/backends/gf-monitor.c
index b6c52cd..a025952 100644
--- a/backends/gf-monitor.c
+++ b/backends/gf-monitor.c
@@ -165,10 +165,7 @@ calculate_scale (GfMonitor     *monitor,
   /* Somebody encoded the aspect ratio (16/9 or 16/10) instead of the
    * physical size.
    */
-  if ((width_mm == 160 && height_mm == 90) ||
-      (width_mm == 160 && height_mm == 100) ||
-      (width_mm == 16 && height_mm == 9) ||
-      (width_mm == 16 && height_mm == 10))
+  if (gf_monitor_has_aspect_as_size (monitor))
     goto out;
 
   if (width_mm > 0 && height_mm > 0)
@@ -1085,3 +1082,17 @@ gf_verify_monitor_mode_spec (GfMonitorModeSpec  *mode_spec,
       return FALSE;
     }
 }
+
+gboolean
+gf_monitor_has_aspect_as_size (GfMonitor *monitor)
+{
+  int width_mm;
+  int height_mm;
+
+  gf_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm);
+
+  return (width_mm == 160 && height_mm == 90) ||
+         (width_mm == 160 && height_mm == 100) ||
+         (width_mm == 16 && height_mm == 9) ||
+         (width_mm == 16 && height_mm == 10);
+}


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