From bca08c2c4ed0b9fbe8a518e692cbd8bdb777f39b Mon Sep 17 00:00:00 2001 From: Olivier Fourdan Date: Wed, 26 Jun 2019 11:40:00 +0200 Subject: [PATCH] monitor-manager: Use `meta_monitor_get_display_name()` API Use the new monitor's `meta_monitor_get_display_name()` instead of rebuilding the display name for each DBUS request. https://gitlab.gnome.org/GNOME/mutter/issues/645 --- src/backends/meta-monitor-manager.c | 102 +--------------------------- 1 file changed, 3 insertions(+), 99 deletions(-) diff --git a/src/backends/meta-monitor-manager.c b/src/backends/meta-monitor-manager.c index a85a140a7..d2cbe2ec8 100644 --- a/src/backends/meta-monitor-manager.c +++ b/src/backends/meta-monitor-manager.c @@ -921,29 +921,6 @@ meta_monitor_manager_class_init (MetaMonitorManagerClass *klass) g_object_class_install_properties (object_class, PROP_LAST, obj_props); } -static const double known_diagonals[] = { - 12.1, - 13.3, - 15.6 -}; - -static char * -diagonal_to_str (double d) -{ - unsigned int i; - - for (i = 0; i < G_N_ELEMENTS (known_diagonals); i++) - { - double delta; - - delta = fabs(known_diagonals[i] - d); - if (delta < 0.1) - return g_strdup_printf ("%0.1lf\"", known_diagonals[i]); - } - - return g_strdup_printf ("%d\"", (int) (d + 0.5)); -} - gboolean meta_monitor_has_aspect_as_size (MetaMonitor *monitor) { @@ -960,79 +937,6 @@ meta_monitor_has_aspect_as_size (MetaMonitor *monitor) (width_mm == 16 && height_mm == 10); } -static char * -make_display_name (MetaMonitorManager *manager, - MetaMonitor *monitor) -{ - g_autofree char *inches = NULL; - g_autofree char *vendor_name = NULL; - const char *vendor = NULL; - const char *product_name = NULL; - int width_mm; - int height_mm; - - meta_monitor_get_physical_dimensions (monitor, &width_mm, &height_mm); - - if (meta_monitor_is_laptop_panel (monitor)) - return g_strdup (_("Built-in display")); - - if (width_mm > 0 && height_mm > 0) - { - if (!meta_monitor_has_aspect_as_size (monitor)) - { - double d = sqrt (width_mm * width_mm + - height_mm * height_mm); - inches = diagonal_to_str (d / 25.4); - } - else - { - product_name = meta_monitor_get_product (monitor); - } - } - - vendor = meta_monitor_get_vendor (monitor); - - 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, - vendor); - - if (!vendor_name) - vendor_name = g_strdup (vendor); - } - else - { - if (inches != NULL) - vendor_name = g_strdup (_("Unknown")); - else - vendor_name = g_strdup (_("Unknown Display")); - } - - if (inches != NULL) - { - /**/ - return g_strdup_printf (C_("This is a monitor vendor name, followed by a " - "size in inches, like 'Dell 15\"'", - "%s %s"), - vendor_name, inches); - } - else if (product_name != NULL) - { - return g_strdup_printf (C_("This is a monitor vendor name followed by " - "product/model name where size in inches " - "could not be calculated, e.g. Dell U2414H", - "%s %s"), - vendor_name, product_name); - } - else - { - return g_strdup (vendor_name); - } -} - static const char * get_connector_type_name (MetaConnectorType connector_type) { @@ -1383,7 +1287,7 @@ meta_monitor_manager_handle_get_current_state (MetaDBusDisplayConfig *skeleton, GVariantBuilder monitor_properties_builder; GList *k; gboolean is_builtin; - char *display_name; + const char *display_name; current_mode = meta_monitor_get_current_mode (monitor); preferred_mode = meta_monitor_get_preferred_mode (monitor); @@ -1472,10 +1376,10 @@ meta_monitor_manager_handle_get_current_state (MetaDBusDisplayConfig *skeleton, "is-builtin", g_variant_new_boolean (is_builtin)); - display_name = make_display_name (manager, monitor); + display_name = meta_monitor_get_display_name (monitor); g_variant_builder_add (&monitor_properties_builder, "{sv}", "display-name", - g_variant_new_take_string (display_name)); + g_variant_new_string (display_name)); g_variant_builder_add (&monitors_builder, MONITOR_FORMAT, monitor_spec->connector,