site  contact  subhomenews

Utility to report resolutions supported by monitor

January 19, 2020 — BarryK

I am phasing out the use of 'ddcprobe'. This is a CLI utility that reports various information about the video card and the monitor. XorgWizard uses it to obtain resolutions and refresh-frequencies supported by the monitor.

ddcprobe has various problems. One, it may hang -- this was reported as early as 2012 in the Puppy Forum. Another issue is that it simply doesn't work -- on some hardware, it has to be run a second time to correctly read the EDID information of the monitor. With some hardware, it simply returns nothing.

Earlier news about phasing out ddcprobe:

https://bkhome.org/news/202001/further-improved-video-hardware-profiling.html

An alternative is the duo get-edid and parse-edid, however, get-edid may not find any monitor resolution information. My Acer Aspire1 laptop purchased in 2019 is in that category.

Another alternative is "xrandr -q", but this only works when X is running.

However, there is no need to try and read the monitor EDID, as ddcprobe and get-edid do, as the Linux kernel has already done it, and the information is to be found in /sys/class/drm. So, I decided to write a little utility that pokes around in /sys/class/drm and reports on resolutions and frequencies supported by the video card and the monitor.

This utility will be called by the XorgWizard. It is /usr/sbin/get-monitor-resolutions and here it is:

#!/bin/bash
#(c) Copyright Barry Kauler 2020, licence GPL v3 (usr/share/doc/legal).
#200119 to be called by xorgwizard and anything else that wants to know what
# resolutions and frequencies are offered by the monitor. this is intended to
# replace 'ddcprobe' and get-edid|parse-edid'
#i think this will have the native resolution of monitor: /tmp/xorgwizard-get-mon-resolution-native
#all supported resolutions here: /tmp/xorgwizard-get-mon-resolutions

echo -n '' > /tmp/xorgwizard-get-mon-res
[ ! -d /sys/class/drm ] && exit 1

MON_INFO=''
for aCARD in /sys/class/drm/card*
do
if grep '^connected' ${aCARD}/status >/dev/null 2>&1;then
CARDname="${aCARD##*/}" #ex: card0-HDMI-A-2
if [ -e ${aCARD}/edid ];then
MON_INFO="$(cat ${aCARD}/edid | parse-edid 2>/dev/null)"
break
fi
fi
done
[ ! "MON_INFO" ] && exit 2

MODELINES="$(echo "$MON_INFO" | tr '\t' ' ' | tr -s ' ' | grep '^ Modeline ' | cut -f 3- -d '"' | grep -v 'interlace' | cut -f 2-10 -d ' ' | grep '^[0-9]')"

echo -n '' > /tmp/xorgwizard-get-mon-res0
if [ "$MODELINES" ];then
while read aML
do
[ ! "$aML" ] && continue
#ex: 148.500 1920 2448 2492 2640 1080 1084 1089 1125
read -r DCLK XRES HSYNCSTART HSYNCEND HTOTAL YRES VSYNCSTART VSYNCEND VTOTAL <<< "${aML}" #<<< needs bash
xVFREQ="$(dc ${DCLK} 1000000 mul ${HTOTAL} div ${VTOTAL} div p)"
VFREQ="$(printf "%.0f\n" "$xVFREQ")" #round up or down to an integer.
echo "${XRES} ${YRES} ${VFREQ}" >> /tmp/xorgwizard-get-mon-res0
done <<_EOF1
$(echo "$MODELINES")
_EOF1
fi

NATIVE_RES="$(sort -u -n /tmp/xorgwizard-get-mon-res0 | tail -n 1)"
echo -n "$NATIVE_RES" > /tmp/xorgwizard-get-mon-resolution-native

#my acer aspire1, purchased 2019, does not return any modeline info. fallback...
if [ -e ${aCARD}/modes ];then
HASINFOflg="$(cat ${aCARD}/modes)"
if [ "$HASINFOflg" ];then
for aXY in `cat ${aCARD}/modes`
do
[ ! "$aXY" ] && continue
if ! grep "^${aXY/x/ }" /tmp/xorgwizard-get-mon-res0 >/dev/null;then
echo "${aXY/x/ } 60" >> /tmp/xorgwizard-get-mon-res0
fi
done
fi
fi

[ ! -s /tmp/xorgwizard-get-mon-res0 ] && exit 3

sort -u -n /tmp/xorgwizard-get-mon-res0 > /tmp/xorgwizard-get-mon-resolutions
rm -f /tmp/xorgwizard-get-mon-res0
exit 0
###end###

This utility could be used in Puppy Linux. It does use the 'parse-edid' utility (see bold text above), which is part of the 'read-edid' package. Also, recent puppies have a different 'dc' utility (see bold text above) -- Easy and Puppy use 'dc' from Busybox, however, recent versions of Busybox have changed the commandline requirements for dc, so my script will be broken. 

You can run "dc --help" to see if it accepts the commandline syntax as I have used it, or not. 

Tags: easy