Merge pull request #2109 from Elv13/revert_dpi_per_screen

screen: Revert the DPI per screen changes.
This commit is contained in:
Emmanuel Lepage Vallée 2017-11-23 23:42:26 -05:00 committed by GitHub
commit 056af3d48d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 67 additions and 10 deletions

View File

@ -504,25 +504,78 @@ function screen.object.get_selected_tag(s)
return screen.object.get_selected_tags(s)[1] return screen.object.get_selected_tags(s)[1]
end end
--- Enable the automatic calculation of the screen DPI (experimental).
--
-- This will cause many elements such as the font and some widgets to be scaled
-- so they look the same (physical) size on different devices with different
-- pixel density.
--
-- It is calculated using the information provided from `xrandr`.
--
-- When enabled, the theme and configuration must avoid using pixel sizes for
-- different elements as this will cause misalignment or hidden content on some
-- devices.
--
-- Note that it has to be called early in `rc.lua` and requires restarting
-- awesome to take effect. It is disabled by default and changes introduced in
-- minor releases of Awesome may slightly break the behavior as more components
-- gain support for HiDPI.
--
-- When disabled the DPI is acquired from the `Xft.dpi` X resource (xrdb),
-- defaulting to 96.
--
-- @tparam boolean enabled Enable or disable automatic DPI support.
function screen.set_auto_dpi_enabled(enabled)
for s in capi.screen do
s.data.dpi_cache = nil
end
data.autodpi = enabled
end
--- The number of pixels per inch of the screen. --- The number of pixels per inch of the screen.
-- @property dpi -- @property dpi
-- @treturn number the DPI value. -- @treturn number the DPI value.
local xft_dpi, fallback_dpi local xft_dpi, fallback_dpi
local function get_fallback()
local mm_per_inch = 25.4
-- 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 root and not fallback_dpi then
local _, h = root.size()
local _, hmm = root.size_mm()
fallback_dpi = hmm ~= 0 and h * mm_per_inch / hmm
end
return fallback_dpi or 96
end
function screen.object.get_dpi(s) function screen.object.get_dpi(s)
local mm_per_inch = 25.4 local mm_per_inch = 25.4
if s.data.dpi then if s.data.dpi or s.data.dpi_cache then
return s.data.dpi return s.data.dpi or s.data.dpi_cache
end end
-- Xft.dpi is explicit user configuration, so honor it -- Xft.dpi is explicit user configuration, so honor it
if not xft_dpi and awesome and awesome.xrdb_get_value then if not xft_dpi and awesome and awesome.xrdb_get_value then
xft_dpi = tonumber(awesome.xrdb_get_value("", "Xft.dpi")) or false xft_dpi = tonumber(awesome.xrdb_get_value("", "Xft.dpi")) or false
end end
if xft_dpi then if xft_dpi then
return xft_dpi s.data.dpi_cache = xft_dpi
return s.data.dpi_cache
end
if not data.autodpi then
s.data.dpi_cache = get_fallback()
return s.data.dpi_cache
end end
-- Try to compute DPI based on outputs (use the minimum) -- Try to compute DPI based on outputs (use the minimum)
@ -537,16 +590,12 @@ function screen.object.get_dpi(s)
end end
end end
if dpi then if dpi then
s.data.dpi_cache = dpi
return dpi return dpi
end end
-- We have no outputs, so guess based on the size of the root window. s.data.dpi_cache = get_fallback()
if root and not fallback_dpi then return s.data.dpi_cache
local _, h = root.size()
local _, hmm = root.size_mm()
fallback_dpi = hmm ~= 0 and h * mm_per_inch / hmm
end
return fallback_dpi or 96
end end
function screen.object.set_dpi(s, dpi) function screen.object.set_dpi(s, dpi)

View File

@ -69,8 +69,14 @@ local function get_screen(s)
end end
--- Get global or per-screen DPI value falling back to xrdb. --- Get global or per-screen DPI value falling back to xrdb.
--
-- This function is deprecated. Use `s.dpi` and avoid getting the DPI without
-- a screen.
--
-- @deprecated xresources.get_dpi
-- @tparam[opt] integer|screen s The screen. -- @tparam[opt] integer|screen s The screen.
-- @treturn number DPI value. -- @treturn number DPI value.
function xresources.get_dpi(s) function xresources.get_dpi(s)
s = get_screen(s) s = get_screen(s)
if s then if s then

View File

@ -23,6 +23,7 @@ local textbox = { mt = {} }
--- Set the DPI of a Pango layout --- Set the DPI of a Pango layout
local function setup_dpi(box, dpi) local function setup_dpi(box, dpi)
assert(dpi, "No DPI provided")
if box._private.dpi ~= dpi then if box._private.dpi ~= dpi then
box._private.dpi = dpi box._private.dpi = dpi
box._private.ctx:set_resolution(dpi) box._private.ctx:set_resolution(dpi)
@ -80,6 +81,7 @@ function textbox:get_preferred_size(s)
gdebug.deprecate("textbox:get_preferred_size() requires a screen argument", {deprecated_in=5, raw=true}) gdebug.deprecate("textbox:get_preferred_size() requires a screen argument", {deprecated_in=5, raw=true})
dpi = beautiful.xresources.get_dpi() dpi = beautiful.xresources.get_dpi()
end end
return self:get_preferred_size_at_dpi(dpi) return self:get_preferred_size_at_dpi(dpi)
end end