将蓝牙耳机连接到座位的 udev 规则

将蓝牙耳机连接到座位的 udev 规则

我使用的是多座设置loginctl,但我在使用蓝牙耳机时遇到了问题。

USB 蓝牙适配器打开,seat0但我的显示器编号:N在重新启动时随机变化,并且我的耳机会连接到上次连接的任何显示器编号,或者seat0如果没有其他活动席位。

连接耳机给我...

❯ sudo udevadm -d monitor -p
monitor will print the received events for:
UDEV - the event which udev sends out after rule processing
KERNEL - the kernel uevent

KERNEL[11828.639536] add      /devices/pci0000:00/0000:00:05.0/0000:06:00.0/usb8/8-2/8-2:1.0/bluetooth/hci0/hci0:12 (bluetooth)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:05.0/0000:06:00.0/usb8/8-2/8-2:1.0/bluetooth/hci0/hci0:12
SUBSYSTEM=bluetooth
DEVTYPE=link
SEQNUM=5747

UDEV  [11828.643688] add      /devices/pci0000:00/0000:00:05.0/0000:06:00.0/usb8/8-2/8-2:1.0/bluetooth/hci0/hci0:12 (bluetooth)
ACTION=add
DEVPATH=/devices/pci0000:00/0000:00:05.0/0000:06:00.0/usb8/8-2/8-2:1.0/bluetooth/hci0/hci0:12
SUBSYSTEM=bluetooth
DEVTYPE=link
SEQNUM=5747
USEC_INITIALIZED=11828643524
SYSTEMD_ALIAS=/sys/subsystem/bluetooth/devices/hci0:12
SYSTEMD_WANTS=bluetooth.target
SYSTEMD_USER_WANTS=bluetooth.target
TAGS=:systemd:
CURRENT_TAGS=:systemd:

KERNEL[11830.906947] add      /devices/virtual/input/input74 (input)
ACTION=add
DEVPATH=/devices/virtual/input/input74
SUBSYSTEM=input
PRODUCT=5/0/0/0
NAME="NC-25 (AVRCP)"
PHYS="5c:f3:70:6a:03:6c"
PROP=0
EV=100007
KEY=2fc800 145200000000 0 10300 49e800000c00 e16800000000f f810000010000ffc
REL=0
MODALIAS=input:b0005v0000p0000e0000-e0,1,2,14,k71,72,73,8A,8B,A3,A5,A6,A7,A8,AB,AE,C8,C9,D0,161,164,166,16A,16C,18B,18E,18F,190,191,192,193,195,ramlsfw
SEQNUM=5748

KERNEL[11830.907167] add      /devices/virtual/input/input74/event265 (input)
ACTION=add
DEVPATH=/devices/virtual/input/input74/event265
SUBSYSTEM=input
DEVNAME=/dev/input/event265
SEQNUM=5749
MAJOR=13
MINOR=265

UDEV  [11831.445222] add      /devices/virtual/input/input74 (input)
ACTION=add
DEVPATH=/devices/virtual/input/input74
SUBSYSTEM=input
PRODUCT=5/0/0/0
NAME="NC-25 (AVRCP)"
PHYS="5c:f3:70:6a:03:6c"
PROP=0
EV=100007
KEY=2fc800 145200000000 0 10300 49e800000c00 e16800000000f f810000010000ffc
REL=0
MODALIAS=input:b0005v0000p0000e0000-e0,1,2,14,k71,72,73,8A,8B,A3,A5,A6,A7,A8,AB,AE,C8,C9,D0,161,164,166,16A,16C,18B,18E,18F,190,191,192,193,195,ramlsfw
SEQNUM=5748
USEC_INITIALIZED=11830908664
ID_INPUT=1
ID_INPUT_KEY=1
ID_BUS=bluetooth
TAGS=:seat:
CURRENT_TAGS=:seat:

UDEV  [11832.553850] add      /devices/virtual/input/input74/event265 (input)
ACTION=add
DEVPATH=/devices/virtual/input/input74/event265
SUBSYSTEM=input
DEVNAME=/dev/input/event265
SEQNUM=5749
USEC_INITIALIZED=11831463188
ID_INPUT=1
ID_INPUT_KEY=1
ID_BUS=bluetooth
LIBINPUT_DEVICE_GROUP=5/0/0:5c:f3:70:6a:03:6c
MAJOR=13
MINOR=265
TAGS=:power-switch:
CURRENT_TAGS=:power-switch:

loginctl创建 udev 规则以将特定设备连接到特定席位,但蓝牙设备根本不会显示在 上loginctl seat-status seat0,仅显示蓝牙适配器,但默认情况下已打开seat0。没有一个声音设备与蓝牙耳机匹配:

❯ loginctl seat-status seat0 | grep sound
                  ├─/sys/devices/pci0000:00/0000:00:02.0/0000:01:00.0/0000:02:00.0/0000:03:00.1/sound/card3
                  │ sound:card3 "HDMI_1"
                  │ ├─/sys/devices/pci0000:00/0000:00:02.0/0000:01:00.0/0000:02:00.0/0000:03:00.1/sound/card3/input27
                  │ ├─/sys/devices/pci0000:00/0000:00:02.0/0000:01:00.0/0000:02:00.0/0000:03:00.1/sound/card3/input28
                  │ ├─/sys/devices/pci0000:00/0000:00:02.0/0000:01:00.0/0000:02:00.0/0000:03:00.1/sound/card3/input29
                  │ ├─/sys/devices/pci0000:00/0000:00:02.0/0000:01:00.0/0000:02:00.0/0000:03:00.1/sound/card3/input30
                  │ └─/sys/devices/pci0000:00/0000:00:02.0/0000:01:00.0/0000:02:00.0/0000:03:00.1/sound/card3/input31
                  ├─/sys/devices/pci0000:00/0000:00:14.2/sound/card2
                  │ sound:card2 "SB"
                  │ ├─/sys/devices/pci0000:00/0000:00:14.2/sound/card2/input40
                  │ ├─/sys/devices/pci0000:00/0000:00:14.2/sound/card2/input41
                  │ ├─/sys/devices/pci0000:00/0000:00:14.2/sound/card2/input42
                  │ ├─/sys/devices/pci0000:00/0000:00:14.2/sound/card2/input43
                  │ ├─/sys/devices/pci0000:00/0000:00:14.2/sound/card2/input44
                  │ ├─/sys/devices/pci0000:00/0000:00:14.2/sound/card2/input45
                  │ ├─/sys/devices/pci0000:00/0000:00:14.2/sound/card2/input46
                  │ └─/sys/devices/pci0000:00/0000:00:14.2/sound/card2/input47

我可以编写类似于创建的 udev 规则loginctl来强制蓝牙耳机始终绑定到seat0吗?

❯ cat /etc/udev/rules.d/72-seat-sound-pci-0000_04_00_1.rules
TAG=="seat", ENV{ID_FOR_SEAT}=="sound-pci-0000_04_00_1", ENV{ID_SEAT}="seat1"

相关内容