4 external monitors go into : a hub of 4 DisplayLink-branded external videocards. (HDMI to USB)
Let's call it a dock. The dock goes into my laptop through one USB(-C).
I already made a udev rule, that detects an identifying attribute of the dock, and runs my xrandr
command when I hotplug it.
Here is the bash command:
#!/bin/sh
xrandr \
--output DP-1 --off \
--output DP-2 --off \
--output HDMI-1 --off \
--output HDMI-2 --off \
--output DVI-I-4-3 --mode 1920x1080 --pos 0x0 --rotate normal \
--output DVI-I-5-4 --mode 1920x1080 --pos 0x1080 --rotate normal \
--output DVI-I-2-1 --mode 1920x1080 --pos 1920x240 --rotate left \
--output DVI-I-3-2 --mode 1920x1080 --pos 3000x240 --rotate left \
--output eDP-1 --primary --mode 1920x1080 --pos 4080x1900 --rotate normal
The problem is that at each hotplug, the monitors/cards of the dock are loaded randomly by the kernel. In other word I can't predict what monitor will be the DVI-I-M-N
used in the xrandr
command.
You can see that on the attached picture: I first used the GUI to detect and write accordingly the xrandr
script, then I unplugged the dock, replugged, and now the GUI is wrong because displays the previous layout, whereas things have now changed, because red labels appearing when I click detect again, don't match anymore with the script. (This means in the real world I now see a messed-up arrangement, not the one displayed on the GUI within the screenshot)
So I need to uniquely identify each monitor, and map it to its "dynamically" (adaptively) allocated DVI port by the kernel at the last hotplug. To do so, I saw some EDID stuff. Here is a doc just for completeness, but don't bother reading:
- https://en.wikipedia.org/wiki/Extended_Display_Identification_Data#EDID_1.3_data_format
- https://www.kernel.org/doc/html/latest/admin-guide/edid.html
The whole point here, is that all the plug types are the same : HDMI (loaded in the kernel as DVI though). Therefore, such approach is unusable : https://stackoverflow.com/questions/5469828/how-to-create-a-callback-for-monitor-plugged-on-an-intel-graphics .
Even worse, all the monitors are the same model from the same brand. This implies that all these approaches :
- $
ls /sys/class/drm/*/edid | xargs -i{} sh -c "echo {}; parse-edid < {}"
(needs $sudo apt install read-edid -y
), retrieves sameIdentifier
,ModelName
, andVendorName
for the four monitors. (Credits : Display monitor info via command line ) - $
edid-decode </sys/class/drm/card2-DVI-I-1/edid
applied to {card3-DVI-I-2
,card4-DVI-I-3
,card5-DVI-I-4
} retrieve 2 differentSerial Number
,Made in week
, and batches of twoCheckshum
. This is because I first bought 2 monitors, and then 2 more the next year. If you wonder why so many cards, card0 is the intel iGPU, card1 is the nvidia dGPU, others belong to the dock https://ibb.co/CJvZPzg . (Credits : https://askubuntu.com/a/1149585/1173345 ) - $
sha1sum /sys/class/drm/card2-DVI-I-1/edid | cut -f1 -d " "
gives only 2 different 40-digit keys for the 4 different monitors/cards. (Credits : https://tyler.vc/auto-monitor-detection-on-linux )
fail.
How to get a very unique identifier for each of these monitors to rename them in some udev rule, in order to know to which DVI each is associated ?
Can I actually rewrite the EDID myself ? How ?