From c8bfbf5a3b2cf21308dff113d609f3a753bf771c Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Thu, 26 Jan 2017 18:46:14 +0100 Subject: [PATCH 1/3] Update physical size on RRChangeNotifyEvent Xrandr provides new physical sizes in millimeters when sending a RRChangeNotifyEvent, either to preserve DPI when monitors are added, or to change DPI when a DPI change was requested. Keep track of the changes so that our DPI information is always fresh. --- event.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/event.c b/event.c index 40e33d740..8e64c28db 100644 --- a/event.c +++ b/event.c @@ -816,10 +816,14 @@ event_handle_randr_screen_change_notify(xcb_randr_screen_change_notify_event_t * /* Do (part of) what XRRUpdateConfiguration() would do (update our state) */ if (ev->rotation & (XCB_RANDR_ROTATION_ROTATE_90 | XCB_RANDR_ROTATION_ROTATE_270)) { globalconf.screen->width_in_pixels = ev->height; + globalconf.screen->width_in_millimeters = ev->mheight; globalconf.screen->height_in_pixels = ev->width; + globalconf.screen->height_in_millimeters = ev->mwidth; } else { globalconf.screen->width_in_pixels = ev->width; + globalconf.screen->width_in_millimeters = ev->mwidth; globalconf.screen->height_in_pixels = ev->height; + globalconf.screen->height_in_millimeters = ev->mheight;; } globalconf.screen_need_refresh = true; From f7d82334662f2949aef46d6dec86ed172108b9fb Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Wed, 25 Jan 2017 21:33:59 +0100 Subject: [PATCH 2/3] Add root.size_mm This function returns the (alleged) physical size of the root window. --- root.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/root.c b/root.c index 968cbba1e..bbd0b9d95 100644 --- a/root.c +++ b/root.c @@ -448,6 +448,20 @@ luaA_root_size(lua_State *L) return 2; } +/** Get the physical size of the root window, in millimeter. + * + * @return Width of the root window, in millimeters. + * @return height of the root window, in millimeters. + * @function size_mm + */ +static int +luaA_root_size_mm(lua_State *L) +{ + lua_pushinteger(L, globalconf.screen->width_in_millimeters); + lua_pushinteger(L, globalconf.screen->height_in_millimeters); + return 2; +} + /** Get the attached tags. * @return A table with all tags. * @function tags @@ -474,6 +488,7 @@ const struct luaL_Reg awesome_root_lib[] = { "drawins", luaA_root_drawins }, { "wallpaper", luaA_root_wallpaper }, { "size", luaA_root_size }, + { "size_mm", luaA_root_size_mm }, { "tags", luaA_root_tags }, { "__index", luaA_default_index }, { "__newindex", luaA_default_newindex }, From f22ef5014d956629c7d90749c6b9b07d491264d1 Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Wed, 25 Jan 2017 21:34:48 +0100 Subject: [PATCH 3/3] 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 f0f5d78b3..3c0b80f10 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