Predictable Xrandr
2021-12-18
I have three monitors which are all capable of DisplayPort daisy-chaining (each has a DP-out port). This is nice, as I only need 1-2 cables (DP or USB-C-DP) connected connect to the setup.
Less nice is that the names of DisplayPort outs on the computers are not predictable.
These change, based on the order in which they are connected.
And since each connected USB-C or DisplayPort device can connect multiple monitors, this gets even further expanded.
At times I had 10+ DisplayPorts showing with xrandr
.
When I run Sway, it is trivially possible to work around, as Sway exposes monitor names and serial numbers. This is my setup with Sway:
output "Dell Inc. DELL U2715H GH85D73K..." {
position 0,0
res 2560x1440
}
output "Dell Inc. DELL U2715H GH85D72R..." {
position 2560,0
res 2560x1440
}
output $laptop_screen {
position 1600,1440
#scale 0.75
res 1920x1080
}
Today I learned…
Under X11, more detailed monitor information can be read with the read-edid
and parse-edid
tools.
Since read-edid
doesn't work for me, I worked around it and did not further bother fixing it.
In /sys/class/drm/card0/card0-DP-3/edid
, I can find the information about connected displays.
By piping this through parse-edid
, I get human-readable output. And if I further look for ModelName
and the manufacturing week, I can obtain unique-enough identifiers to get a predictable configuration for my desk.
toe-private@gaspode3 ~ % cat /sys/class/drm/card0/card0-DP-3/edid | parse-edid | grep -E "ModelName|Manufactured"
Checksum Correct
ModelName "T27hv-20"
# Monitor Manufactured week 30 of 2021
What is a bit annoying is that parse-edid
only works for individual /sys/class
files.
It also does not like looping too much.
I have connected right now:
toe-private@gaspode3 ~ % xrandr | grep -vE "^ " | grep "DisplayPort-" | grep -v disconnected
DisplayPort-2 connected 2560x1440+2560+0 (normal left inverted right x axis y axis) 597mm x 336mm
DisplayPort-3 connected 2560x1440+5120+0 (normal left inverted right x axis y axis) 597mm x 336mm
DisplayPort-5 connected 2560x1440+0+0 (normal left inverted right x axis y axis) 597mm x 336mm
So, I filter this down a little:
toe-private@gaspode3 ~ % for dpout in $(xrandr | grep -vE "^ " | grep "DisplayPort-" | grep -v disconnected | sed -r "s/DisplayPort-([0-9]+).*/\1/"); do echo $dpout; done
2
3
5
Next annoyance: The DisplayPort numbers reported by xrandr
are different ones than the /sys/class
files. So I need to increment each of these by one:
toe-private@gaspode3 ~ % for dpout in $(xrandr | grep -vE "^ " | grep "DisplayPort-" | grep -v disconnected | sed -r "s/DisplayPort-([0-9]+).*/\1/") ; do echo "$(($dpout + 1))"; done
3
4
6
Now I can finally glue all of this together:
toe-private@gaspode3 ~ % for dpout in $(xrandr | grep -vE "^ " | grep "DisplayPort-" | grep -v disconnected | sed -r "s/DisplayPort-([0-9]+).*/\1/") ; do cat /sys/class/drm/card0/card0-DP-$(($dpout + 1))/edid | parse-edid | grep -E "ModelName|Manufactured"; done
Checksum Correct
ModelName "T27hv-20"
# Monitor Manufactured week 30 of 2021
Checksum Correct
ModelName "DELL U2715H"
# Monitor Manufactured week 9 of 2017
Checksum Correct
ModelName "DELL U2715H"
# Monitor Manufactured week 12 of 2017