On Tue, Nov 22, 2022 at 13:50 (+1100), Steven D'Aprano wrote:
On Tue, Nov 22, 2022 at 07:41:17PM -0400, Jim wrote:
> A while ago I got tired of all the lies,
counter-lies,
> counter-counter-lies, and so on, and now when I log in before much of
> anything gets started I figure out the correct DPI
And how do you do that, if X lies about the screen
resolution?
Here's a long answer to a very short question, just in case other
people find this information useful.
Since some people use "resolution" to mean "pixels per unit
dimension"
and others use it to mean "total number of pixels", I will try to stay
away from using the word "resolution" to avoid confusion.
The X server lies about the DPI.
(As someone else pointed out, it lies about the physical size, but the
bottom line for the "my fonts are too small" complaint is *not* that
there are too many pixels but rather that the DPI value reported by X
is smaller than the actual DPI value.)
Anyway, xrandr can be asked to report the EDID information for an
attached screen. And that can be parsed to get information such as
the (alleged) physical screen size (in mm). Knowing the number of
pixels on the screen, the DPI value can be calculated.
Here is a (zsh, but may work with other shells) to get the information
of the (first only?) attached screen:
my_get_edid_as_ascii_hex ()
{
while read -r output hex conn
do
echo "$hex"
done < <(xrandr --prop | awk '
!/^[ \t]/ {
if (output && hex) print output, hex, conn
output=$1
hex=""
}
/ConnectorType:/ {conn=$2}
/[:.]/ && h {
h=0
}
h {sub(/[ \t]+/, ""); hex = hex $0}
/EDID.*:/ {h=1}
END {if (output && hex) print output, hex, conn}
'
)
}
When I run it on my laptop, I get
00ffffffffffff0006af8ac400000000001d0104a5221378036e8593585892281e505400000001010101010101010101010101010101963780c8703826406c30aa0058c2100000180f2580c8703826406c30aa0058c21000001800000000000000000000000000000000000000000002001040ff0f3c7d0f13287d20202000cd
Pipe that through xxd -p -r and parse-edid as follows:
my_get_edid_as_ascii_hex | xxd -p -r | parse-edid
and on mu laptop I get
Checksum Correct
Section "Monitor"
Identifier ""
ModelName ""
VendorName "AUO"
# Monitor Manufactured week 0 of 2019
# EDID version 1.4
# Digital Display
DisplaySize 340 190
Gamma 2.20
Option "DPMS" "false"
Modeline "Mode 0" 142.30 1920 2028 2076 2120 1080 1090 1100 1118 -hsync -vsync
Modeline "Mode 1" 94.87 1920 2028 2076 2120 1080 1090 1100 1118 -hsync -vsync
EndSection
which tells me that the display size is 340 mm by 190 mm (and a bunch
of other stuff, as you see).
Having said all that, I have found that I get a more accurate DPI
value for some of my screens by just testing the screen/machine
combination to see if I have hard-coded a preferred width, and
otherwise using the EDID value.
I then take this width, do some arithmetic to get the DPI, and then
do
xrandr --output $1 --dpi $dpi_x
where $dpi_x is the calculated DPI value and $1 is the particular
output device I am setting.
Oddly, setting Xft.dpi seems to behave differently on Slackware64 15.0
than on Raspbian. On Slackware the following does the right thing:
echo Xft.dpi: $dpi_x | xrdb -screen -merge -
but on Raspbian, that makes the fonts way too small, so I do
echo Xft.dpi: 120 | xrdb -screen -merge
which makes the fonts a reasonable size on that system.
I have all this code in a shell script which is run from my .Xsession
before the window manager starts up, so that when the window manager
starts the correct DPI has been set.
Cheers.
Jim