mirror of
https://github.com/brl/mutter.git
synced 2024-11-26 01:50:42 -05:00
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
This commit is contained in:
parent
6541d49fe7
commit
bca08c2c4e
@ -921,29 +921,6 @@ meta_monitor_manager_class_init (MetaMonitorManagerClass *klass)
|
|||||||
g_object_class_install_properties (object_class, PROP_LAST, obj_props);
|
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
|
gboolean
|
||||||
meta_monitor_has_aspect_as_size (MetaMonitor *monitor)
|
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);
|
(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 *
|
static const char *
|
||||||
get_connector_type_name (MetaConnectorType connector_type)
|
get_connector_type_name (MetaConnectorType connector_type)
|
||||||
{
|
{
|
||||||
@ -1383,7 +1287,7 @@ meta_monitor_manager_handle_get_current_state (MetaDBusDisplayConfig *skeleton,
|
|||||||
GVariantBuilder monitor_properties_builder;
|
GVariantBuilder monitor_properties_builder;
|
||||||
GList *k;
|
GList *k;
|
||||||
gboolean is_builtin;
|
gboolean is_builtin;
|
||||||
char *display_name;
|
const char *display_name;
|
||||||
|
|
||||||
current_mode = meta_monitor_get_current_mode (monitor);
|
current_mode = meta_monitor_get_current_mode (monitor);
|
||||||
preferred_mode = meta_monitor_get_preferred_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",
|
"is-builtin",
|
||||||
g_variant_new_boolean (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}",
|
g_variant_builder_add (&monitor_properties_builder, "{sv}",
|
||||||
"display-name",
|
"display-name",
|
||||||
g_variant_new_take_string (display_name));
|
g_variant_new_string (display_name));
|
||||||
|
|
||||||
g_variant_builder_add (&monitors_builder, MONITOR_FORMAT,
|
g_variant_builder_add (&monitors_builder, MONITOR_FORMAT,
|
||||||
monitor_spec->connector,
|
monitor_spec->connector,
|
||||||
|
Loading…
Reference in New Issue
Block a user