Bug 423990 - Implement "ModifyOtherKeys"
Summary: Implement "ModifyOtherKeys"
Status: REPORTED
Alias: None
Product: konsole
Classification: Applications
Component: keyboard (show other bugs)
Version: unspecified
Platform: Other Linux
: NOR wishlist
Target Milestone: ---
Assignee: Konsole Developer
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-08 10:31 UTC by Jerôme Pouiller
Modified: 2021-04-09 14:19 UTC (History)
2 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jerôme Pouiller 2020-07-08 10:31:56 UTC
Xterm implements a feature called "ModifyOtherKeys"[1]. As user of vim, I wait for this feature for 15 years (and I know that emacs users also wait for it).

Vim and emacs support it for a while. It would be great if my favorite terminal emuletor would implement it.

https://invisible-island.net/xterm/modified-keys.html
Comment 1 Jerôme Pouiller 2020-09-25 09:25:11 UTC
I can get the expected behavior by adding all the key sequences to the keytab file[1][2]:

   key A+Shift+Ctrl : "\E[65;6u"
   key A-Shift+Ctrl : "\E[65;5u"
   ...
   key *+Ctrl : "\E[42;5u"
   key 8+Ctrl : "\E[56;5u"

It works with vim. However, it breaks all other applications. I tried to keep original behavior for already defined key sequences (ie. nearly all <letter>-Shift+Ctrl and a few other ones).

Unfortunately, vim does not support that. Either it use ModifyOtherKeys and it won't recognize <\x11> is same than <C-q> or it won't understand <C-S-q>[3][4].

If I understand right, the correct behavior would be use the ModifyOtherKeys sequence only once Konsole has received '\E[>4;2m'[5]. Once ModifyOtherKeys is enabled, it should be enabled for all the keys (Ctrl+A should send '\E[65;5u').

It is interesting to keep an eyes on other bug reports for the other terminals:
   - Gnome Terminal: https://bugzilla.gnome.org/show_bug.cgi?id=477068
   - iTerm2: https://gitlab.com/gnachman/iterm2/-/issues/5377
   - alacritty: https://github.com/alacritty/alacritty/issues/3101


[1] To keep thing simple, I have not add support for Alt modifier
[2] Note that I wasn't able to map keys ':' and '#' and using symbolic names from Qt::Key neither works.
[3] Vim automatically enable the ModifyOtherKeys as soon as it receive one ModifyOtherKeys sequence.
[4] A workaround is to use raw key sequences (eg. <Esc>[93;5u) instead of symbolic control sequence (C-S-q) to define mapping.
[5] https://bugzilla.gnome.org/show_bug.cgi?id=730157#c1
Comment 2 tcanabrava 2020-09-25 10:03:51 UTC
Jerome, are you willing to dig into konsole code to implement this? I can help you get started if needed.
Comment 3 Jerôme Pouiller 2020-09-25 10:31:40 UTC
In fact I have already checked if could do something. I have found Vt102Emulation.cpp and Vt102Emulation::processToken().

I have stopped here. This code looks complex enough and I have not the time to implement that myself :-(
Comment 4 tcanabrava 2020-09-25 10:50:25 UTC
yeah, that code is really complex and I don't think there's a single person currently on konsole that actually fully understand it. I only touched bits of it and with extreme caution as it's quite fragile. =/
Comment 5 Jerôme Pouiller 2021-04-09 14:19:27 UTC
FYI, you can force vim to use ModifyOtherKeys by adding that to your .vimrc[1]:

    let &t_TI = "\<Esc>[>4;2m"
    let &t_TE = "\<Esc>[>4;m"

[1] https://vimhelp.org/map.txt.html#modifyOtherKeys