8

How can I use xkb to map a key combination like Super + Shift + C to another combination like Ctrl + Shift + C?
The question is about doing so with xkb. I know about autokey or xmodmap but I want to do it with xkb as other options aren't as stable as xkb in current versions of X.

Update

It'd be awesome if these mappings can be application specific. It'd be super awesome if these mappings could be system wide except some applications.

Sassan
  • 161
  • 1
    xkb really isn't designed as a hotkey handler, so i can't think of a way to do this without impacting other keys. (a) could map Super keys to be Ctrl, but then you have no Super. (b) could invent a new type to handle Super+Shift → Ctrl+Shift, then define C to be a member of that type, but then it's no longer the normal type and may cause problems. the cleanest way i can think of would be adding an xkb_compatibility clause to handle only this combination: interpret Super+Shift+Exactly(C) { action= SetMods(modifiers=Control); } // or similar ... – quixotic Jun 26 '18 at 10:08
  • @quixotic The thing is all other ways I tried to map keys in linux were unstable solutions (xmodmap and autokey) But things I've done in xkb (like mapping left ctrl to hyper modifier) are absolutely robust. So I thought I should do the rest in xkb. Btw, where should I add this interpret line? – Sassan Jun 26 '18 at 10:48
  • Should I add a new file in .../xkb/compat/ directory? – Sassan Jun 26 '18 at 10:50
  • adding interpret Super+Exactly(C) { action= SetMods(modifiers=Control); } to .../xkb/compat/basic made my xserver unable to startup. – Sassan Jun 26 '18 at 11:21
  • yeah, i wouldn't add that to system files or default settings, especially before testing. use xkbcomp to create a base layout from your existing layout: xkbcomp $DISPLAY my-current.xkb ... edit the file and make changes there ... test with xkbcomp my-current.xkb $DISPLAY ... if it doesn't work, tweak the file and retry ... – quixotic Jun 26 '18 at 11:53
  • Nice I have another unanswered question here https://askubuntu.com/questions/1042392/xkb-settings-in-dotfiles and you partially answered it. I wonder where these info are documented. – Sassan Jun 26 '18 at 12:08
  • Btw I'm getting Identifier "C" of type int is unknown any idea? – Sassan Jun 26 '18 at 12:08
  • Exactly(C) may not be the appropriate way to specify that key. i'm guessing based on other interpret clauses in my own keymap, but there aren't a lot of Exactly()s in use. – quixotic Jun 26 '18 at 19:40
  • @Sassan, did you solve this problem? It would solve the question I have just asked here: https://askubuntu.com/q/1364352/13884 – Rasmus Sep 17 '21 at 23:00
  • No, my finding was that things done in Gnome settings (as well as undocumented key themes of Gnome) and things done in xkb are the only stable mappings I've tried, other stuff like autokey and xmodmap were unstable. – Sassan Sep 19 '21 at 11:01

0 Answers0