Remapping keyboard keys on SteamOS every time a new device is connected

104 Views Asked by At

I'm attempting the remap some keys for a specific keyboard on my Steam Deck running SteamOS. I've managed to prepare script that:

  • Uses xinput to find ID of a specific keyboard.
  • Exports the current layout via xkbcomp.
  • Replaces selected key mappings in the exported file.
  • Overrides the layout settings with xkbcomp utilizing the -i flag.

The script is working when ran locally via a terminal. However, the layout settings are reset every time the keyboard is disconnected or the device is restarted.

To automatically run the script when the keyboard is connected, I've added a udev rule that executes it on add events. The script is correctly executed when the keyboard is connected, but it's unable to access the X server:

Unable to connect to X server

I've tried running the script via su - deck, but the result is the same.

Is there a way to trigger a script relying on xinput when a new bluetooth device is connected, either with or without udev? Ideally, I'd prefer to avoid scripts that run continuously in the background and rely on events instead.

0

There are 0 best solutions below