Jim composed on 2022-11-23 11:41 (UTC-0400):
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:
Instead of all that work measuring and calculating, use a tool that does the work for you:
inxi -Gaz --vs
inxi 3.3.23-00 (2022-10-31) Graphics: Device-1: Intel HD Graphics 630 vendor: ASUSTeK driver: i915 v: kernel arch: Gen-9.5 process: Intel 14nm built: 2016-20 ports: active: DP-1,HDMI-A-2,HDMI-A-3 empty: DP-2,HDMI-A-1 bus-ID: 00:02.0 chip-ID: 8086:5912 class-ID: 0300 Display: x11 server: X.Org v: 1.20.14 driver: X: loaded: modesetting alternate: fbdev,vesa dri: iris gpu: i915 display-ID: :0 screens: 1 Screen-1: 0 s-res: 3600x2640 s-dpi: 120 s-size: 762x558mm (30.00x21.97") s-diag: 944mm (37.18") Monitor-1: DP-1 pos: primary,bottom-l model: Acer K272HUL serial: <filter> built: 2018 res: 2560x1440 hz: 60 dpi: 109 gamma: 1.2 size: 598x336mm (23.54x13.23") diag: 686mm (27") ratio: 16:9 modes: max: 2560x1440 min: 720x400 Monitor-2: HDMI-A-2 mapped: HDMI-2 pos: top-right model: Dell P2213 serial: <filter> built: 2012 res: 1680x1050 hz: 60 dpi: 90 gamma: 1.2 size: 473x296mm (18.62x11.65") diag: 558mm (22") ratio: 16:10 modes: max: 1680x1050 min: 720x400 Monitor-3: HDMI-A-3 mapped: HDMI-3 pos: top-left model: NEC EA243WM serial: <filter> built: 2011 res: 1920x1200 hz: 60 dpi: 94 gamma: 1.2 size: 519x324mm (20.43x12.76") diag: 612mm (24.1") ratio: 16:10 modes: max: 1920x1200 min: 640x480 API: OpenGL v: 4.6 Mesa 22.1.7 renderer: Mesa Intel HD Graphics 630 (KBL GT2) direct render: Yes
Each monitor's actual dimensions and DPI are accurately reported (from EDID, if it exists), and the entire screen's /logical/ dimensions and DPI (what the software uses: s-dpi: 120) are also reported.