Ubuntu - 当我插入耳机时,我的键盘布局被重置为默认值,我该如何阻止它

Ubuntu - 当我插入耳机时,我的键盘布局被重置为默认值,我该如何阻止它

我将键盘布局设置为自定义布局,使用setxkbmap.它以“自动启动应用程序”( ) 启动~/.config/autostart并且工作正常。

但当我插入 Jabra 耳机时,它会重置为默认的 US QWERTY 耳机。我想阻止这一切。

我看到另一个帖子

如何设置udev设备连接触发的xinput属性?

防止插入 USB 键盘时重置键盘布局

但最好的答案是假设 OP 只是插入另一个新键盘;我认为这是一个错误的假设,这绝对不是我的情况。

我知道这是一个udev问题,而且是一个非常严重的错误。乌班图18.04。

使用 时udevadm monitor,插入 Jabra 耳机时我会看到以下几行:

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

KERNEL[514.356707] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2 (usb)
KERNEL[514.360571] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0 (usb)
KERNEL[514.384326] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0/sound/card1 (sound)
KERNEL[514.384427] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0/sound/card1/pcmC1D0p (sound)
KERNEL[514.384485] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0/sound/card1/pcmC1D0c (sound)
KERNEL[514.384542] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0/sound/card1/controlC1 (sound)
KERNEL[514.384584] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0 (usb)
KERNEL[514.384616] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.1 (usb)
KERNEL[514.384645] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.1 (usb)
KERNEL[514.384675] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.2 (usb)
KERNEL[514.384701] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.2 (usb)
KERNEL[514.384730] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3 (usb)
KERNEL[514.387245] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/0003:0B0E:0305.000B (hid)
KERNEL[514.387575] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/0003:0B0E:0305.000B/input/input18 (input)
KERNEL[514.444127] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/0003:0B0E:0305.000B/input/input18/event6 (input)
KERNEL[514.444169] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/0003:0B0E:0305.000B/input/input18/input18::mute (leds)
KERNEL[514.444318] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/usbmisc/hiddev0 (usbmisc)
KERNEL[514.444375] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/0003:0B0E:0305.000B/hidraw/hidraw1 (hidraw)
KERNEL[514.444438] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/0003:0B0E:0305.000B (hid)
KERNEL[514.444473] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3 (usb)
KERNEL[514.444510] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2 (usb)
UDEV  [514.967946] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2 (usb)
UDEV  [514.970785] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0 (usb)
UDEV  [514.971920] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.1 (usb)
UDEV  [514.972737] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.2 (usb)
UDEV  [514.973022] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3 (usb)
UDEV  [514.973854] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0/sound/card1 (sound)
UDEV  [514.974449] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.1 (usb)
UDEV  [514.975643] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.2 (usb)
UDEV  [514.976113] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/0003:0B0E:0305.000B (hid)
UDEV  [514.976909] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/usbmisc/hiddev0 (usbmisc)
UDEV  [514.979273] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/0003:0B0E:0305.000B/hidraw/hidraw1 (hidraw)
UDEV  [514.980161] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0/sound/card1/pcmC1D0c (sound)
UDEV  [514.980666] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/0003:0B0E:0305.000B/input/input18 (input)
UDEV  [514.980736] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0/sound/card1/pcmC1D0p (sound)
KERNEL[514.980866] change   /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0/sound/card1 (sound)
UDEV  [514.983803] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/0003:0B0E:0305.000B/input/input18/input18::mute (leds)
UDEV  [515.017334] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/0003:0B0E:0305.000B/input/input18/event6 (input)
UDEV  [515.019498] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3/0003:0B0E:0305.000B (hid)
UDEV  [515.020828] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.3 (usb)
UDEV  [515.790142] add      /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0/sound/card1/controlC1 (sound)
UDEV  [515.792199] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0 (usb)
UDEV  [515.794039] bind     /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2 (usb)
UDEV  [515.796084] change   /devices/pci0000:00/0000:00:14.0/usb3/3-3/3-3.2/3-3.2:1.0/sound/card1 (sound)

在它之后xinput list,我看到:

⎡ Virtual core pointer                      id=2    [master pointer  (3)]
⎜   ↳ Virtual core XTEST pointer                id=4    [slave  pointer  (2)]
⎜   ↳ HP HP USB 1000dpi Laser Mouse             id=8    [slave  pointer  (2)]
⎜   ↳ Chicony HP Business Slim Keyboard Consumer Control    id=13   [slave  pointer  (2)]
⎜   ↳ PS/2 Generic Mouse                        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)]
    ↳ Sleep Button                              id=7    [slave  keyboard (3)]
    ↳ Chicony HP Business Slim Keyboard         id=10   [slave  keyboard (3)]
    ↳ Chicony HP Business Slim Keyboard System Control  id=11   [slave  keyboard (3)]
    ↳ Chicony HP Business Slim Keyboard         id=12   [slave  keyboard (3)]
    ↳ Integrated_Webcam_FHD: Integrat           id=14   [slave  keyboard (3)]
    ↳ Integrated_Webcam_FHD: Integrat           id=15   [slave  keyboard (3)]
    ↳ Dell WMI hotkeys                          id=16   [slave  keyboard (3)]
    ↳ AT Translated Set 2 keyboard              id=17   [slave  keyboard (3)]
    ↳ Chicony HP Business Slim Keyboard Consumer Control    id=19   [slave  keyboard (3)]
    ↳ GN Netcom A/S Jabra EVOLVE LINK MS        id=9    [slave  keyboard (3)]

Chicony HP Business Slim Keyboard是我要设置布局的 USB 键盘,GN Netcom A/S Jabra EVOLVE LINK MS是耳机。

答案1

您的 Jabra 耳机显然包含一些作为“类似键盘”输入设备呈现给操作系统的按钮,并且显然,只要插入新的键盘设备,您的桌面环境就会根据它所了解的设置重置 X11 键盘布局。

setxkbmap桌面环境不会知道您的设置,因此桌面环境和桌面环境setxkbmap最终会互相争斗。

setxkbmap您应该首先使用桌面环境的配置工具来正确设置键盘,而不是使用。不幸的是,Gnome 桌面似乎只提供了简化的键盘布局选择器 GUI:但您仍然应该能够将设置直接放入/etc/default/keyboard.请参阅man 5 keyboard了解更多详情。

答案2

我通过在连接耳机时使用 Gnome 对话框设置键盘布局来解决这个问题。不知何故,当它们连接时,Gnome 认为根本没有设置布局。

一旦设置 - 无论耳机是否连接,它都会保留我的布局。

相关内容