haimgel / display-switch

Turn a $30 USB switch into a full-featured multi-monitor KVM switch
https://haim.dev/posts/2020-07-28-dual-monitor-kvm/
MIT License
2.83k stars 110 forks source link

Retry if a display is not found #48

Closed andornaut closed 3 years ago

andornaut commented 3 years ago

I use display-switch to workaround an issue where MacOS sometimes does not wake-up its external display when switching between a Macbook and Linux desktop via a KVM.

Macbook (closed lid) -
                       \
                         -->  KVM  -->  External display on DisplayPort1
                       /
Linux desktop --------

I have configured display-switch on my Macbook to monitor a USB device that is connected to the KVM and to send a DDC input-switch command to my monitor whenever the USB device is connected. Although, the monitor is always connected to DisplayPort1 (no other video cables are connected), the input-switch command (or perhaps a wake-up command is also sent?) has the side-effect of waking the monitor up, which solves the wake-up flakiness issue I was experiencing.

This usually works:

19:27:26 [INFO] Monitored device ("14b0:011e") is connected
19:27:28 [DEBUG] (1) display_switch::display_control: Setting display 'DELL U3417W' to DisplayPort1(0xf)

But sometimes, due I think to timing of the USB detection and KVM port switching, the monitor is not detected:

15:00:26 [INFO] Monitored device ("14b0:011e") is connected
15:00:27 [ERROR] Did not detect any DDC-compatible displays!

I believe that this issue could be worked around by introducing a retry mechanism. Perhaps something with a slight delay - even a fixed 2 second sleep before retrying would probably be sufficient.