xkbcomp at startup in kde

I'm using kubuntu 20.04 and want to run xkbcomp ~/.Xkeymap $DISPLAY at startup to load a custom keymap. To this end I created a script with the content

#!/bin/bash

touch ~/test
xkbcomp ~/.Xkeymap $DISPLAY

and put it in ~/.config/autostart-scripts. I made it executable, and I see that it's indeed running at startup because the touch command timestamps a file in the home directory. However, the keys are not correctly remapped, and I have to rerun the script manually each time (which has the desired effect).

I assume the problem is that the scripts in the autostart directory are run too early during startup, before kde loads its own keymaps?

Is that the correct diagnosis? And does anybody know a way to fix the problem?


Can't tell if your assumption is correct, but possibly you can find out by delaying the execution of the xkbcomp command, i.e. replacing

xkbcomp ~/.Xkeymap $DISPLAY

with

{
    sleep 3
    xkbcomp ~/.Xkeymap $DISPLAY
} &