我无法让“optirun intel-virtual-output”在我的 udev 脚本中工作

我无法让“optirun intel-virtual-output”在我的 udev 脚本中工作

我有一个 Thunderbolt 3 坞站,我想在插入和拔出后自动运行脚本。我能够完美运行我的“插件”脚本,但我的“插件”脚本不起作用。我已经手动测试过,一切似乎都工作正常。但让 udev 运行似乎效果不太好。我无法找到 udev 引发的任何错误。任何帮助都有效。

/etc/udev/rules.d/81-thinkpad-dock.rules

SUBSYSTEM=="input", ACTION=="add|remove", ENV{ID_VENDOR_ID}=="17ef", ENV{ID_MODEL_ID}=="3083", TAGS=="power-switch", RUN+="/etc/sbin/thinkpad-dock.sh"

/etc/sbin/thinkpad-dock.sh

#!/bin/sh -e

sleep 1

username=adam

if [[ "$ACTION" == "add" ]]; then
  DOCKED=1
  logger -t DOCKING "Detected condition: docked"
elif [[ "$ACTION" == "remove" ]]; then
  DOCKED=0
  logger -t DOCKING "Detected condition: un-docked"
else
  logger -t DOCKING "Detected condition: unknown"
  echo Please set env var \$ACTION to 'add' or 'remove'
  exit 1
fi


function switch_to_local {
  export DISPLAY=$1
  VIRTUAL_OUTPUT_PID=$(ps aux | grep -i "intel-virtual-output" | awk 'NR==1{print $2}')
  kill -9 "$VIRTUAL_OUTPUT_PID"
  su $username -c '
        xrandr --output eDP1 --auto --primary \
                --output VIRTUAL1 --off \
                --output VIRTUAL2 --off'
}

function switch_to_external {
  sleep 10
  su $username -c 'optirun intel-virtual-output'
  logger -t DOCKING "finished running"

}

case "$DOCKED" in
  "0")
    #undocked event
    switch_to_local :0 ;;
  "1")
    #docked event
    switch_to_external :0 ;;
esac

相关内容