我已完成以下
# Saved as /etc/udev/rules.d/81-MSSP3-dock.rules
# Microsoft Surface Pro Keyboard
SUBSYSTEM=="input", ENV{ID_VENDOR_ID}=="045e", ENV{ID_MODEL_ID}=="07e3, GOTO="MSSP3_rules"
GOTO="MSSP3_rules_end"
LABEL="MSSP3_rules"
ACTION=="add", RUN+="/home/joshuarobison/Documents/Scripts/landscape.sh"
ACTION=="remove", RUN+="/home/joshuarobison/Documents/Scripts/portrait.sh"
LABEL="MSSP3_rules_end"
我的udev如下
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
UDEV [2672.635429] remove /devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/0003:045E:07E3.0012/input/input303/event3 (input)
ACTION=remove
BACKSPACE=guess
DEVLINKS=/dev/input/by-path/pci-0000:00:14.0-usb-0:3:1.0-event-kbd /dev/input/by-id/usb-Microsoft_Surface_Type_Cover-event-kbd
DEVNAME=/dev/input/event3
DEVPATH=/devices/pci0000:00/0000:00:14.0/usb1/1-3/1-3:1.0/0003:045E:07E3.0012/input/input303/event3
ID_BUS=usb
ID_INPUT=1
ID_INPUT_KEY=1
ID_INPUT_KEYBOARD=1
ID_MODEL=Surface_Type_Cover
ID_MODEL_ENC=Surface\x20Type\x20Cover
ID_MODEL_ID=07e3
ID_PATH=pci-0000:00:14.0-usb-0:3:1.0
ID_PATH_TAG=pci-0000_00_14_0-usb-0_3_1_0
ID_REVISION=0307
ID_SERIAL=Microsoft_Surface_Type_Cover
ID_TYPE=hid
ID_USB_DRIVER=usbhid
ID_USB_INTERFACES=:030000:
ID_USB_INTERFACE_NUM=00
ID_VENDOR=Microsoft
ID_VENDOR_ENC=Microsoft
ID_VENDOR_ID=045e
LIBINPUT_DEVICE_GROUP=3/45e/7e3:usb-0000:00:14.0-3
MAJOR=13
MINOR=67
SEQNUM=4374
SUBSYSTEM=input
TAGS=:power-switch:
USEC_INITIALIZED=2297576881
XKBLAYOUT=jp
XKBMODEL=pc105
横向和纵向脚本已经可以工作了。我知道问题出在 udev 规则中。当我移除和停靠键盘时,脚本不会运行。
即使 Portrait 或 Landscape.sh 脚本只是一个简单的 echo 命令,也不会发生任何事情。
答案1
下面将设置 Microsoft SP3,以便在键盘移除时切换到纵向模式。脚本确保有源触控笔和电容式触摸方向正确。
感谢@george udeson 提供帮助我编写本文的教程链接。
UDEV 规则
# Saved as /etc/udev/rules.d/81-MSSP3-dock.rules
# Microsoft Surface Pro Keyboard
ACTION=="add" \
, ATTRS{idProduct}=="07e3" \
, ATTRS{idVendor}=="045e" \
, ENV{DISPLAY}=":0" \
, ENV{XAUTHORITY}="/home/joshuarobison/.Xauthority" \
, RUN+="//home/joshuarobison/Documents/Scripts/landscape.sh"
ACTION=="remove" \
, ATTRS{idProduct}=="07e3" \
, ATTRS{idVendor}=="045e" \
, ENV{DISPLAY}=":0" \
, ENV{XAUTHORITY}="/home/joshuarobison/.Xauthority" \
, RUN+="//home/joshuarobison/Documents/Scripts/portrait.sh"
Portrait.sh脚本
#!/bin/sh
#Portrait
xrandr -o left
xinput set-prop "NTRG0001:01 1B96:1B05" --type=float "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
xinput set-prop "NTRG0001:01 1B96:1B05" --type=float "Coordinate Transformation Matrix" 0 -1 1 1 0 0 0 0 1
xsetwacom set "NTRG0001:01 1B96:1B05 Pen stylus" Rotate ccw
Landscape.sh 脚本
#!/bin/sh
#landscape
xrandr -o normal
xinput set-prop "NTRG0001:01 1B96:1B05" --type=float "Coordinate Transformation Matrix" 0 0 0 0 0 0 0 0 0
xinput set-prop "NTRG0001:01 1B96:1B05" --type=float "Coordinate Transformation Matrix" 0 0 0 0 0 0 0 0 0
xsetwacom set "NTRG0001:01 1B96:1B05 Pen stylus" Rotate 0
创建 udev 规则文件后,不要忘记运行
sudo udevadm control --reload