Index: xfsettingsd/registry.c =================================================================== --- xfsettingsd/registry.c (revision 29498) +++ xfsettingsd/registry.c (working copy) @@ -74,6 +74,10 @@ | G_PARAM_STATIC_NICK \ | G_PARAM_STATIC_BLURB) +#define INCH_MM 25.4 +#define FALLBACK_DPI 96 +#define MAX_DPI 1000 + G_DEFINE_TYPE(XSettingsRegistry, xsettings_registry, G_TYPE_OBJECT); enum @@ -399,6 +403,39 @@ g_error_free (error); } +static int +compute_xsettings_dpi (XSettingsRegistry *registry, int value) +{ + Screen *xscreen; + int width_mm, height_mm; + int width, height; + int dpi; + + xscreen = ScreenOfDisplay (registry->priv->display, + registry->priv->screen); + width_mm = WidthMMOfScreen (xscreen); + height_mm = HeightMMOfScreen (xscreen); + dpi = 1024 * FALLBACK_DPI; + + if (value > 0) + { + dpi = 1024 * value; + } + else if (width_mm > 0 && height_mm > 0) + { + width = WidthOfScreen (xscreen); + height = HeightOfScreen (xscreen); + dpi = MIN (1024 * INCH_MM * width / width_mm, + 1024 * INCH_MM * height / height_mm); + } + if (dpi > MAX_DPI * 1024) + { + dpi = 1024 * FALLBACK_DPI; + } + + return dpi; +} + void xsettings_registry_notify(XSettingsRegistry *registry) { @@ -541,8 +578,8 @@ * font sizes with -1 DPI and a forced setting equal to the X * server's calculated DPI don't match. Need to look into * this a bit more. */ - if (strcmp (entry->name, "Xft/DPI") == 0 && g_value_get_int(&entry->value) != -1) - *(CARD32 *)pos = g_value_get_int(&entry->value) * 1024; + if (strcmp (entry->name, "Xft/DPI") == 0) + *(CARD32 *)pos = compute_xsettings_dpi (registry, g_value_get_int(&entry->value)); else *(CARD32 *)pos = g_value_get_int(&entry->value); pos += 4;