Hacker News new | ask | show | jobs
by ranma42 1647 days ago
My shell-script solution I've been using for the last year or two:

  #!/bin/bash
  src="pc"
  while true; do
    lsusb -d 04d9:a0d1 >/dev/null  # Keyboard connected?
    ret=$?
    if [ $ret -eq 0 -a "$src" != "pc" ]; then
      src="pc"
      ddcutil --noverify setvcp 60 0x0f  # Switch monitor input to DP
    elif [ $ret -eq 1 -a "$src" = "pc" ]; then
      src="laptop"
      ddcutil --noverify setvcp 60 0x11  # Switch monitor input to HDMI
    fi
    sleep 1
  done
1 comments

> sleep 1

One second latency ... not ideal.

Is there any way to sleepwait on a USB config change instead?

[EDIT]: this might help:

https://stackoverflow.com/questions/469243/how-can-i-listen-...

Add udev rule, to launch script when an input is connected:

   ACTION=="add", DEVPATH=="*/input/*", RUN+="/usr/local/bin/script.sh $devnode"
You can use `udevadm monitor` or venture into `dbus-monitor` to capture events from udev.