[gnome-desktop] gnome-rr: Better display dimensions in names
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-desktop] gnome-rr: Better display dimensions in names
- Date: Thu, 17 May 2012 17:02:17 +0000 (UTC)
commit 2ed4f948b8b1c7cdbcbe0ed82dc11179df5fa176
Author: Bastien Nocera <hadess hadess net>
Date: Thu May 17 17:57:41 2012 +0100
gnome-rr: Better display dimensions in names
For a small number of displays, we know the size it's sold as,
so make 15.6" displays show up as 15.6", not 16.
https://bugzilla.gnome.org/show_bug.cgi?id=669537
libgnome-desktop/display-name.c | 39 +++++++++++++++++++++++++++++++++------
1 files changed, 33 insertions(+), 6 deletions(-)
---
diff --git a/libgnome-desktop/display-name.c b/libgnome-desktop/display-name.c
index 933b020..3e51bce 100644
--- a/libgnome-desktop/display-name.c
+++ b/libgnome-desktop/display-name.c
@@ -49,11 +49,35 @@ find_vendor (const char *code)
return code;
}
+static const double known_diagonals[] = {
+ 12.1,
+ 13.3,
+ 15.6
+};
+
+static char *
+diagonal_to_str (double d)
+{
+ 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));
+}
+
char *
make_display_name (const MonitorInfo *info)
{
const char *vendor;
- int width_mm, height_mm, inches;
+ int width_mm, height_mm;
+ char *inches, *ret;
if (info)
{
@@ -87,15 +111,18 @@ make_display_name (const MonitorInfo *info)
{
double d = sqrt (width_mm * width_mm + height_mm * height_mm);
- inches = (int)(d / 25.4 + 0.5);
+ inches = diagonal_to_str (d / 25.4);
}
else
{
- inches = -1;
+ inches = NULL;
}
- if (inches > 0)
- return g_strdup_printf ("%s %d\"", vendor, inches);
- else
+ if (!inches)
return g_strdup (vendor);
+
+ ret = g_strdup_printf ("%s %s", vendor, inches);
+ g_free (inches);
+
+ return ret;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]