1

I have made a custom xkb keymap that I am happy with, and I can load it with no issues using the following script

xkbcomp -I$HOME/.xkb ~/.xkb/keymap/mykeys $DISPLAY

and it works the way I want when I do it manually.

My problem is, I could not find any reasonable place to put it where it could be run on login and NOT get overwritten by the default configuration. I have tried ~/.xinitrc, ~/.xsession, ~/.xsessionrc, ~/.xprofile, even ~/.config/autostart-scripts

Most of those scripts are run (checked with zenity), but it looks like something downstream apparently reverts back to the default configuration later, so that when my KDE plasma loads, the keys I remapped do not work until I run this script again manually.

How could I fix this?

UPDATE: I also noticed that I need to re-run the script after the laptop wakes up from sleep. Is there a way to make it more permanent without modifying the default config in /usr/share/X11/xkb ?

UPDATE 2: When the laptop wakes up from sleep, my keys are actually still working for about 2-3 seconds, and then suddenly stop (around the same time my bluetooth mouse reconnects: not sure whether this could be related or not) until I re-run the script.

UPDATE 3: Here's the contents of ~/.xkb/keymap/mykeys :

xkb_keymap {
    xkb_keycodes  { include "evdev+aliases(qwerty)" };
    xkb_types     { include "complete"  };
    xkb_compat    { include "complete"  };
    xkb_symbols   { include "pc+us+inet(evdev)+mysymbols(super_arrows)" };
    xkb_geometry  { include "pc(pc105)" };
};

and this is ~/.xkb/symbols/mysymbols:

partial modifier_keys
xkb_symbols "super_arrows" {
    key <LEFT>  {
        type = "PC_SUPER_LEVEL2",
        symbols[Group1] = [    Left,   Home      ],
        actions[Group1] = [    NoAction(),  RedirectKey(keycode=<HOME>, clearmods=Mod4) ]
    };
    key <RGHT>  {
        type = "PC_SUPER_LEVEL2",
        symbols[Group1] = [    Right,  End       ],
        actions[Group1] = [    NoAction(),  RedirectKey(keycode=<END>, clearmods=Mod4) ]
    };
    key <UP>  {
        type = "PC_SUPER_LEVEL2",
        symbols[Group1] = [    Up,  Prior       ],
        actions[Group1] = [    NoAction(),  RedirectKey(keycode=<PGUP>, clearmods=Mod4) ]
    };
    key <DOWN>  {
        type = "PC_SUPER_LEVEL2",
        symbols[Group1] = [    Down,  Next       ],
        actions[Group1] = [    NoAction(),  RedirectKey(keycode=<PGDN>, clearmods=Mod4) ]
    };
    key <INS> {
        symbols[Group1] = [    Print             ],
        actions[Group1] = [    RedirectKey(keycode=<PRSC>) ]
    };
};

If I put include "mysymbols(super_arrows)" into /usr/share/X11/xkb/symbols/pc, and a symlink to mysymbols into /usr/share/X11/xkb/symbols, then my config becomes stable, but after re-login the redefined keys seize to auto-repeat (when pressed and held). So my current process is: after login:

  • launch xkbcomp -I$HOME/.xkb ~/.xkb/keymap/mykeys $DISPLAY manually
  • uncomment include "mysymbols(super_arrows)" in /usr/share/X11/xkb/symbols/pc Then I can use the config normally until the next restart (re-login) :) Linux is really full of magic ! ;)
Dmitry
  • 111
  • Same problem for me : I had a working file loaded with kubuntu 18.04 and xkbcomp but with kubuntu 20.04 xkbcomp ~/.xkbfrperso.xkb "$DISPLAY" does only work in a terminal for the current session and I don't know how to pus this command line. – Oli Oct 25 '20 at 12:51

1 Answers1

-2

This is explained (for another layout, but you'll find your way) at the bottom of this page.

Adriaan
  • 322
  • I don't see how that page is relevant to my question. It is all about modifying stuff in /usr/share/X11/xkb which works, but has some other undesirable side effects in my case (e.g. redefined keys do not repeat anymore). My question was actually: how to prevent KDE from automatically re-reading the configuration from /usr/share/X11/xkb from time to time, and instead keep on using the one I load with xkbcomp manually – Dmitry Sep 29 '20 at 06:53
  • Without the contents of your 'mykeys' file and the constraint that you do not want to change /usr/share/X11/xkb... makes it difficult (for me to help you). You mention ~/.config/autostart-scripts (which my system does not have). Maybe you meant ~/.config/autostart - in that case the answer that @Evgeni Sergeev gave may be useful for you – Adriaan Oct 01 '20 at 09:20
  • Thank you for the pointers. I tried the recipe in @Evgeni Sergeev 's answer, but it didn't work for me. KDE is still re-reading the config from /usr/share/X11/xkb after it executes all autostart scripts. I put the contents of all my scripts in UPDATE 3 to my question above. The constraint not to change /usr/share/X11/xkb is not that important for me, but, as I mentioned, it has side effects for some reason: the redefined keys stop repeating. I don't see this problem if I launch the script manually after login. – Dmitry Oct 07 '20 at 01:47
  • Would you be so kind as to explain what your intention is with super_arrows? Do you want (for example) DOWN to function as PGDN when pressed with SUPER? You may have a conflicting definition that happens to work when invoked 'manually' but gets reset after /usr/share/X11/xkb is re-read. – Adriaan Oct 09 '20 at 09:55
  • Yes, this is precisely what I want to achieve. I am a "lucky" owner of one of those Dell laptops, whose "ingenious" designers have decided that users don't need Home and End keys on Fn+Left and Fn+Right anymore. Those combinations do not generate any keyboard events at all. So substituting Fn with Super is an attempt to restore some reasonable level of productivity. – Dmitry Oct 10 '20 at 13:20
  • Do you have any idea why the keys might stop repeating when redefined in /usr/share/X11/xkb? – Dmitry Oct 10 '20 at 13:25
  • I suspect the RedirectKey, but I cannot find a confirmation. I'm working on another solution but I lack the time to test it (and my daily keyboard does not have a SUPER key - must get the laptop first). I'll get back to this. – Adriaan Oct 11 '20 at 15:20
  • My idea was to use level5 as a modifier for the arrow keys. In /usr/share/X11/xkb/symbols/pc, I changed the UP key into: key <UP> { type="EIGHT_LEVEL", [ Up, Up, Prior, Prior, Prior ] }; And the other keys similarly. Then, I chose the Super key to be Level5Shift (include "level5(lwin_switch_lock)" in the current keymap). It looks promising, but breaks some other stuff... The Prior in level 3 and 4 make it work with AltGr (which is Level4Shift on my keyboards). No solution as you wanted. Sorry. – Adriaan Oct 12 '20 at 14:40