udev 规则脚本“xinput --list”在终端和日志中有所不同

udev 规则脚本“xinput --list”在终端和日志中有所不同

我正在尝试自动校准 Huion 平板电脑,但没有成功。

我有这个输出xinput --list在普通终端中:

⎡ Virtual core pointer                          id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ USB USB Keyboard                          id=13   [slave  pointer  (2)]
⎜   ↳ SynPS/2 Synaptics TouchPad                id=16   [slave  pointer  (2)]
⎜   ↳ Logitech USB Receiver                     id=14   [slave  pointer  (2)]
⎜   ↳ HUION PenTablet                           id=18   [slave  pointer  (2)]
⎜   ↳ HUION PenTablet                           id=19   [slave  pointer  (2)]
⎜   ↳ HUION PenTablet                           id=20   [slave  pointer  (2)]
⎣ Virtual core keyboard                         id=3    [master keyboard (2)]
↳ Virtual core XTEST keyboard               id=5    [slave  keyboard (3)]
↳ Power Button                              id=6    [slave  keyboard (3)]
↳ Video Bus                                 id=7    [slave  keyboard (3)]
↳ Video Bus                                 id=8    [slave  keyboard (3)]
↳ Power Button                              id=9    [slave  keyboard (3)]
↳ Sleep Button                              id=10   [slave  keyboard (3)]
↳ Laptop_Integrated_Webcam_2HDM             id=11   [slave  keyboard (3)]
↳ USB USB Keyboard                          id=12   [slave  keyboard (3)]
↳ AT Translated Set 2 keyboard              id=15   [slave  keyboard (3)]
↳ Dell WMI hotkeys                          id=17   [slave  keyboard (3)]

udev log 仅显示相同命令的内容:

⎡ Virtual core pointer id=2 [master pointer (3)] 
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)] 
⎜ ↳ USB USB Keyboard id=13 [slave pointer (2)] 
⎜ ↳ SynPS/2 Synaptics TouchPad id=16 [slave pointer (2)] 
⎜ ↳ Logitech USB Receiver id=14 [slave pointer (2)] 
⎜ ↳ HUION PenTablet id=18 [slave pointer (2)] 
⎣ Virtual core keyboard id=3 [master keyboard (2)] 
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)] 
↳ Power Button id=6 [slave keyboard (3)] 
↳ Video Bus id=7 [slave keyboard (3)] 
↳ Video Bus id=8 [slave keyboard (3)] 
↳ Power Button id=9 [slave keyboard (3)] 
↳ Sleep Button id=10 [slave keyboard (3)] 
↳Laptop_Integrated_Webcam_2HDM id=11 [slave keyboard (3)] 
↳ USB USB Keyboard id=12 [slave keyboard (3)] 
↳ AT Translated Set 2 keyboard id=15 [slave keyboard (3)] 
↳ Dell WMI hotkeys id=17 [slave keyboard (3)]

id=19请注意,和的行id=20缺失了。

我有:

/etc/udev/rules.d/huion.rules

ATTRS{idVendor}=="256c", ATTRS{idProduct}=="006e", SYMLINK+="davesusb", ENV{DISPLAY}=":0.0", ENV{XAUTHORITY}="/home/romulo/.Xauthority", RUN+="/usr/local/Huion"

/usr/local/Huion

#!/bin/bash
/home/romulo/.local/Huion &

~/.local/Huion

#!/bin/bash

sleep 3
DISPLAY=":0.0"
HOME=/home/romulo/
XAUTHORITY=$HOME/.Xauthority
export DISPLAY XAUTHORITY HOME

if (xrandr | grep "HDMI1 connected" > /dev/null)
then
    LENGTH=$(/usr/bin/xrandr | grep 'HDMI1 connected primary' | uniq |  awk '{x=$4; split(x,a,"+"); split(a[1],b,"x"); print b[1]}')
    WIDTH=$(/usr/bin/xrandr | grep 'HDMI1 connected primary' | uniq |  awk '{x=$4; split(x,a,"+"); split(a[1],b,"x"); print b[2]}')
    DEVICE=$(/usr/bin/xinput --list | grep HUION | uniq | awk 'NR==2 {x=$5; split(x,a,"="); print a[2]}')

    echo $(/usr/bin/xinput --list)

    CORRECTION=$((40000*$WIDTH/$LENGTH))
    echo "$CORRECTION"

    if (glxinfo | grep "Intel" > /dev/null)
    then
        xsetwacom set $DEVICE MapToOutput HDMI1
        echo "device $DEVICE restricted to HDMI-1"
        xinput set-prop $DEVICE "Evdev Axis Calibration" 0 40000 0 $CORRECTION
        echo "correction of proportion : 40000x$CORRECTION"        
    else
        echo "error :("
    fi
else
    echo "error :("
fi

该脚本xinput --list | grep HUION | uniq | awk 'NR==2 …' 尝试捕获id第二个 HUION 设备(即19)的,但由于该信息不存在而失败。我该如何解决这个问题?

更新 1

通过sudo su给了我同样xinput --list作为普通用户,但任何校准尝试都没有效果。我需要在 udev shell 脚本调用中切换到我的用户吗?不太优雅…… :(

答案1

问题是,xinput 列表在 udev 规则处理后刷新,后台进程超时无法解决这个问题。解决方案是通过 inotify 触发脚本。原始解决方案和所需的脚本源可以在以下位置找到:https://bbs.archlinux.org/viewtopic.php?pid=1626055#p1626055

答案2

ACTION=="bind"我也遇到了同样的问题。我的解决方案是使用而不是 来触发 udev 规则ACTION=="add"(因为我看到udevadm monitor这是我连接鼠标时的最后一个操作)

相关内容