The point of this article is to document I workaround that I came up with to handle a HDMI KVM switch.
What happens is that if my Linux PC is turned on while the KVM switch is selecting the other PC, it fails to initialize the display, so when you switch back to the Linux PC, no display is shown.
Figuring out udev
First in the agenda is to figure out what kind of event we should be looking at. For that, we use the command:
With that we can determine what kind of udev events to look for (if any).
Next we need to figure out what keys we need to match. Unfortunately
there is some guess work required as you need to figure out the
device path, whereas
udevadm monitor shows a
However, you manage, you need to use the following command:
udevadm info --query=all --name=/dev/dri/card0 --attribute-walk
This will show possible attributes in the udev rules key format.
Once we know the keys to use, we can know create the rules files.
Rules are located in two locations:
/usr/lib/udev/rules.d/: for system default rules
/etc/udev/rules.d/: for local specific rules
Essentially, we are waiting for the monitor configuration to change and when that happens we will run a script. This is accomplish with the following rules file (99-xwin-hotplug.rules):
The script that is kicked off by udev does the following:
- Check if
:0.0(only one local display!) and tries to determine a suitable
- Run xrandr to try to determine what is the
xrandr --output "$monitor" --autoto re-configure the display
xrefreshfor good measure.