From f22ef5014d956629c7d90749c6b9b07d491264d1 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Wed, 25 Jan 2017 21:34:48 +0100 Subject: [PATCH] Make beautiful fallback properly if Xft.dpi is missing As documented in , the fallback value for Xft.dpi should be the vertical DPI reported by X. On Xorg, this will generally be 96, unless the user has overridden the value by either forcing Xorg to report the EDID-derived DPI, or by setting the DPI themselves (via configuration, command line, or xrandr). The 96 value is kept as ultimate fallback if anything goes wrong. --- lib/beautiful/xresources.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/lib/beautiful/xresources.lua b/lib/beautiful/xresources.lua index f0f5d78b..3c0b80f1 100644 --- a/lib/beautiful/xresources.lua +++ b/lib/beautiful/xresources.lua @@ -83,6 +83,22 @@ function xresources.get_dpi(s) if awesome and awesome.xrdb_get_value then xresources.dpi = tonumber(awesome.xrdb_get_value("", "Xft.dpi")) end + -- Following Keith Packard's whitepaper on Xft, + -- https://keithp.com/~keithp/talks/xtc2001/paper/xft.html#sec-editing + -- the proper fallback for Xft.dpi is the vertical DPI reported by + -- the X server. This will generally be 96 on Xorg, unless the user + -- has configured it differently + if not xresources.dpi then + if root then + local mm_to_inch = 25.4 + _, h = root.size() + _, hmm = root.size_mm() + if hmm ~= 0 then + xresources.dpi = round(h*mm_to_inch/hmm) + end + end + end + -- ultimate fallback if not xresources.dpi then xresources.dpi = 96 end