For the past few weeks, I've been wrestling with a frustrating issue involving my new Logitech MX Keys keyboard connected via Bluetooth on PopOS with i3.
As someone accustomed to using English international keyboards with dead keys (essential for typing accented and special characters), I initially had everything configured correctly. Upon system boot, the keyboard layout worked flawlessly. However, after some time, the configuration would inexplicably revert to a standard English layout. The only way to restore my preferred setup was to manually execute the command
setxkbmap us -variant intl
The random nature of this reconfiguration was perplexing. I'm running PopOS with the i3 window manager, and while some settings are managed through the gnome-control-center, my keyboard layout was correctly set there.
After considerable troubleshooting, I finally pinpointed the culprit: the Bluetooth connection. Whenever the keyboard disconnected and reconnected, it would default to a different layout. This discovery, while seemingly simple in hindsight, was a time-consuming process.
Interestingly, neither Gemini nor ChatGPT were able to provide a direct solution, although they did offer some helpful insights along the way.
Ultimately, I realized two key configurations were necessary:
This led me to believe that the background processes handling Bluetooth connections and disconnections were referencing these default settings.
Here's the configuration of my /etc/default/keyboard file:
File: /etc/default/keyboard
XKBLAYOUT="us"
BACKSPACE="guess"
XKBMODEL="logitech_base"
XKBVARIANT="intl"
XKBOPTIONS="lv3:ralt_switch,terminate:ctrl_alt_bksp"
The crucial missing piece was the XKBVARIANT entry. Adding this immediately resolved the issue.
Furthermore, I created the following configuration file for X11:
File: /etc/X11/xorg.conf.d/40-keyboard.conf
Section "InputDevice"
Identifier "Logitech MX Keys"
Driver "evdev"
Option "XkbLayout" "us"
Option "XkbVariant" "intl"
EndSection
After a system reboot, everything now works as expected. Disconnecting and reconnecting the Bluetooth keyboard no longer results in a layout change.
To verify the configuration, here are the outputs of the relevant commands:
$ localectl status
System Locale: LANG=en_US.UTF-8
VC Keymap: us
X11 Layout: us
X11 Model: logitech_base
X11 Variant: intl
X11 Options: lv3:ralt_switch,terminate:ctrl_alt_bksp
$ setxkbmap -query
rules: evdev
model: logitech_base
layout: us
variant: intl
options: lv3:ralt_switch,terminate:ctrl_alt_bksp
Hopefully, this detailed explanation can save someone else the frustration I experienced.
PS: For this post I make work the Spatie Markdown Highlight Code library, the problem was that the Shiki Highlighter depends on node, it needs the node executable in the path, see this for more info