After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 600659 - Home / End generate wrong control sequences
Home / End generate wrong control sequences
Status: RESOLVED FIXED
Product: vte
Classification: Core
Component: general
0.22.x
Other Linux
: Normal normal
: ---
Assigned To: VTE Maintainers
VTE Maintainers
[fixed-0-36][needed-next][commit:f582...
: 157448 310305 425462 599634 612453 674216 763190 (view as bug list)
Depends on:
Blocks:
 
 
Reported: 2009-11-04 10:33 UTC by klaus.kusche
Modified: 2016-03-06 23:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
vte patch to solve mc <-> gnome-terminal keybindings problem (6.71 KB, patch)
2012-04-22 15:09 UTC, Alexej Ilin
needs-work Details | Review
0001-Home-End-generate-wrong-control-sequences.patch (6.87 KB, patch)
2013-12-21 21:41 UTC, Igor Gnatenko
none Details | Review
0001-Home-End-generate-wrong-control-sequences.patch (7.70 KB, patch)
2013-12-21 21:48 UTC, Igor Gnatenko
none Details | Review
0001-Home-End-generate-wrong-control-sequences.patch (6.75 KB, patch)
2013-12-21 22:15 UTC, Igor Gnatenko
none Details | Review
Fix F1-F4 with modifiers (3.35 KB, patch)
2014-01-04 00:15 UTC, Egmont Koblinger
committed Details | Review
Fix numpad /*-+ with modifiers (3.23 KB, patch)
2014-01-04 00:15 UTC, Egmont Koblinger
committed Details | Review
Fix Home and End, with and without modifiers (2.93 KB, patch)
2014-01-04 00:16 UTC, Egmont Koblinger
committed Details | Review
Fix Numpad 5 with modifiers (1.54 KB, patch)
2014-01-04 00:16 UTC, Egmont Koblinger
committed Details | Review
Fix Home/End on non-broken keyboards (1.42 KB, patch)
2014-04-28 11:18 UTC, Egmont Koblinger
rejected Details | Review
escapes.sh shell script to print almost all escape sequences (4.60 KB, text/plain)
2014-05-13 16:57 UTC, Egmont Koblinger
  Details
current vte escape sequences (67.41 KB, text/plain)
2014-05-13 16:58 UTC, Egmont Koblinger
  Details
current xterm escape sequences (67.41 KB, text/plain)
2014-05-13 16:58 UTC, Egmont Koblinger
  Details
Fix Home/End on non-broken keyboards, take 2 (2.18 KB, patch)
2014-05-14 15:12 UTC, Egmont Koblinger
committed Details | Review
current vte escape sequences (after comment 77) (67.41 KB, text/plain)
2014-05-14 15:15 UTC, Egmont Koblinger
  Details

Description klaus.kusche 2009-11-04 10:33:35 UTC
In my gnome terminal, the Home and End keys generate wrong control sequences
when compared to an xterm (version 250) running in the same environment:

1. In gnome-terminal, the base sequences are "^[OH" and "^[OF".
In xterm, they are "^[[H" and "^[[F".

2. gnome-terminal ignores all modifiers on Home and End, they always send the base sequence. 
In xterm, modifiers are added, giving e.g. "^[[1;5H" and "^[[1;3H" for
Ctrl-Home and Alt-Home.
(I noticed that because I've terminal applications which bind functionality to
Ctrl-Home and Ctrl-End)

I made the following change which made gnome-terminal behave like xterm for me:

--- keymap.c.orig       2009-11-04 10:18:09.000000000 +0100
+++ keymap.c    2009-11-04 10:51:08.000000000 +0100
@@ -276,17 +276,15 @@
 /* Home and End are strange cases because their sequences vary wildly from
  * system to system, or mine's just broken.  But anyway. */
 static const struct _vte_keymap_entry _vte_keymap_GDK_Home[] = {
-       {cursor_all, keypad_all, fkey_all, 0, X_NULL, 0, "kh"},
+       {cursor_all, keypad_all, fkey_nothpvt, 0, _VTE_CAP_CSI "H", -1, X_NULL},
        {cursor_all, keypad_all, fkey_vt220, 0, _VTE_CAP_CSI "1~", -1, X_NULL},
        {cursor_all, keypad_all, fkey_hp, 0, _VTE_CAP_ESC "h", -1, X_NULL},
-       {cursor_all, keypad_all, fkey_nothpvt, 0, X_NULL, 0, "kh"},
        {cursor_all, keypad_all, fkey_all, 0, X_NULL, 0, X_NULL},
 };
 
 static const struct _vte_keymap_entry _vte_keymap_GDK_End[] = {
-       {cursor_all, keypad_all, fkey_all, 0, X_NULL, 0, "@7"},
+       {cursor_all, keypad_all, fkey_notvt220, 0, _VTE_CAP_CSI "F", -1, X_NULL},
        {cursor_all, keypad_all, fkey_vt220, 0, _VTE_CAP_CSI "4~", -1, X_NULL},
-       {cursor_all, keypad_all, fkey_notvt220, 0, X_NULL, 0, "@7"},
        {cursor_all, keypad_all, fkey_all, 0, X_NULL, 0, X_NULL},
 };
 
@@ -1265,6 +1263,8 @@
        case GDK_Delete:
        case GDK_Page_Up:
        case GDK_Page_Down:
+       case GDK_Home:
+       case GDK_End:
        case GDK_KP_Up:
        case GDK_KP_Down:
        case GDK_KP_Left:
@@ -1273,6 +1273,8 @@
        case GDK_KP_Delete:
        case GDK_KP_Page_Up:
        case GDK_KP_Page_Down:
+       case GDK_KP_Home:
+       case GDK_KP_End:
        case GDK_F1:
        case GDK_F2:
        case GDK_F3:
Comment 1 klaus.kusche 2009-11-04 12:35:50 UTC
As the original author of the code noticed in his comment,
home and end are a can of worms.
I just noticed that what xterm actually does, what termcap says about it,
and what terminfo says about it are three quite different things.

My changes above work with bash/readline, with nano, with some other apps,
but break vi.

Next attempt:
1. Leave the base sequences unchanged as "^[OH" and "^[OF".
2. Add xterm's modifier sequences "^[[1;5H" and "^[[1;3H" etc.

Makes readline, nano and vi happy for me.

New patch:
--- keymap.c.orig       2009-11-04 10:18:09.000000000 +0100
+++ keymap.c    2009-11-04 13:22:20.000000000 +0100
@@ -279,14 +279,14 @@
        {cursor_all, keypad_all, fkey_all, 0, X_NULL, 0, "kh"},
        {cursor_all, keypad_all, fkey_vt220, 0, _VTE_CAP_CSI "1~", -1, X_NULL},
        {cursor_all, keypad_all, fkey_hp, 0, _VTE_CAP_ESC "h", -1, X_NULL},
-       {cursor_all, keypad_all, fkey_nothpvt, 0, X_NULL, 0, "kh"},
+       {cursor_all, keypad_all, fkey_nothpvt, 0, _VTE_CAP_SS3 "H", -1, X_NULL},
        {cursor_all, keypad_all, fkey_all, 0, X_NULL, 0, X_NULL},
 };
 
 static const struct _vte_keymap_entry _vte_keymap_GDK_End[] = {
        {cursor_all, keypad_all, fkey_all, 0, X_NULL, 0, "@7"},
        {cursor_all, keypad_all, fkey_vt220, 0, _VTE_CAP_CSI "4~", -1, X_NULL},
-       {cursor_all, keypad_all, fkey_notvt220, 0, X_NULL, 0, "@7"},
+       {cursor_all, keypad_all, fkey_notvt220, 0, _VTE_CAP_SS3 "F", -1, X_NULL},
        {cursor_all, keypad_all, fkey_all, 0, X_NULL, 0, X_NULL},
 };
 
@@ -1265,6 +1265,8 @@
        case GDK_Delete:
        case GDK_Page_Up:
        case GDK_Page_Down:
+       case GDK_Home:
+       case GDK_End:
        case GDK_KP_Up:
        case GDK_KP_Down:
        case GDK_KP_Left:
@@ -1273,6 +1275,8 @@
        case GDK_KP_Delete:
        case GDK_KP_Page_Up:
        case GDK_KP_Page_Down:
+       case GDK_KP_Home:
+       case GDK_KP_End:
        case GDK_F1:
        case GDK_F2:
        case GDK_F3:
@@ -1409,7 +1413,7 @@
                /* SS3 should have no modifiers so make it CSI instead. See
                 * http://cvsweb.xfree86.org/cvsweb/xc/programs/xterm/input.c.diff?r1=3.57&r2=3.58
                 */
-               if (cursor_app_mode &&
+               if (/*cursor_app_mode && */
                        g_str_has_prefix(nnormal, _VTE_CAP_SS3)
                        && is_cursor_key(keyval)) {
                        nnormal[1] = '[';
Comment 2 Yury V. Zaytsev 2010-04-09 20:50:23 UTC
As per https://bugzilla.gnome.org/show_bug.cgi?id=425462#c20 , moving my comments here. This bug is confirmed and has at least 2 duplicates:

https://bugzilla.gnome.org/show_bug.cgi?id=599634
https://bugzilla.gnome.org/show_bug.cgi?id=612453

Original comment below:

Behdad Esfahbod, I know you are the MAN that fixed the freaking invisible
cursor bug. This one has been around for 3 years already. Could you please look
into this?

I'm coming from the mc side. We recently mapped CTRL+Home and CTRL+End to the
movements to the beginning and the end of file to adhere to the standard set by
other editors. 

What we've got is that herds of vte-based terminal users are now screaming,
because vte and consequently gnome-terminal sends the same sequences for
Home/End and CTRL+Home / CTRL+End so that we can't distinguish them.

Xterm(243):

Home = ^[[H
End = ^[[F
CTRL+Home = ^[[1;5H
CTRL+End = ^[[1;5F

GNOME Terminal 2.28.1

Home = ^[OH
End = ^[OF
CTRL+Home = ^[OH
CTRL+End = ^[OF

PLEASE PLEASE PLEASE!

FYI in Konsole / Xterm mode I get correct Xterm sequences, it's just VTE that
does not distinguish between Home and CTRL+Home.

Behdad to the rescue!!! The last patch looks good to me.
Comment 3 Behdad Esfahbod 2010-04-10 04:04:34 UTC
*** Bug 599634 has been marked as a duplicate of this bug. ***
Comment 4 Behdad Esfahbod 2010-04-10 04:04:50 UTC
*** Bug 612453 has been marked as a duplicate of this bug. ***
Comment 5 Behdad Esfahbod 2010-04-10 04:06:42 UTC
Copying useful script from one of the dupe bugs:

#!/usr/bin/perl -w

use Term::ReadKey;
ReadMode('cbreak');
print "Press keys to see their ASCII values.  Use Ctrl-C to quit.\n";

while (1) {
    $char = ReadKey(0);
    last unless defined $char;
    printf(" Decimal: %d\tHex: %x\n", ord($char), ord($char));
}

ReadMode('normal');
Comment 6 Yury V. Zaytsev 2010-05-06 13:09:04 UTC
Friendly ping: it's been a month since my last comment and the bug exists for more than half a year. A reasonably looking patch is floating around. Please finish it! 

Thanks!
Comment 7 Yury V. Zaytsev 2011-01-03 13:09:37 UTC
Hello?

Right now, I kind of worked around this issue for Debian by building mc --with-x in order to detect the sequences via XQuery* but people keep on complaining, because then it breaks with mc via ssh / with disabled X forwarding... :-(

Please!
Comment 8 Behdad Esfahbod 2011-01-05 17:45:28 UTC
Taking a look at this one one...
Comment 9 Yury V. Zaytsev 2011-01-05 17:48:05 UTC
Many thanks! Keep us posted...
Comment 10 Behdad Esfahbod 2011-01-05 18:13:08 UTC
Humm.  After spending half hour on it, I can't claim that I understand how this should be fixed :(.
Comment 11 Steve Rainwater 2011-01-05 18:53:11 UTC
As long as it's fixed in a way so that the home and end keys in Midnight Commander start working again when running under GNOME terminal, I'll be happy.
Comment 12 klaus.kusche 2011-01-05 18:59:42 UTC
What's wrong with my second patch?

That Home and End should accept modifiers
(and the key sequences Home and End should generate 
when they are pressed together with modifiers) are universally agreed on,
there were no objections, they work for me for a year now,
they are what MC expects, ...

The only remaining problem is whether Home and End 
without modifiers should generate ^[[H / ^[[F or ^[OH / ^[OF.
As both xterm and gnome terminal have ^[OH / ^[OF for the Home and End keys
in their terminfo database,
and as ^[[H / ^[[F breaks vim among others,
I think they should remain ^[OH / ^[OF.

And that's what my patch does.
Comment 13 Behdad Esfahbod 2011-01-05 19:04:33 UTC
I don't understand your patch.  And I guess you don't understand why it works either.  For example, I expected a non-zero mod_mask field, but I don't see any.

Or what this line is about:

-               if (cursor_app_mode &&
+               if (/*cursor_app_mode && */


I guess it just made it work for you without having an explanation.  I don't know how to test these in app-mode off the top of my head.
Comment 14 Yury V. Zaytsev 2011-01-05 19:08:30 UTC
Could you please explain what you mean by "app-mode"? Sorry, I'm not familiar with vte development.
Comment 15 Behdad Esfahbod 2011-01-05 19:09:42 UTC
Apparently apps (like mc) can switch the terminal to an application mode, in which some keys produce different sequences than in normal mode.  It's all over the place.  And confusing.  And I don't fully understand it either.
Comment 16 Yury V. Zaytsev 2011-01-05 19:20:28 UTC
I am extremely confused by your follow-up. We are not doing anything fancy inside mc with regards to terminal interaction. We mainly use two libraries (alternatively): SLang or ncurses. These libraries provide us with the escape sequences which are generated by the terminal and then we interpret them ourselves.

I am not aware of any code in mc to instruct these libraries to switch the terminal in the "application mode". I'm not even sure what exactly is this mode and where it is supposed to be documented so that I can check up on this.

Usually we just run cat and press keys in order to visualize which escape sequences are being generated. I am not aware of the cases when they didn't match those that we were getting from our TUI libraries. Alternatively, you can use the Perl script visualize them in a fancier way.

Maybe you are referring to the termcap / terminfo databases?
Comment 17 Behdad Esfahbod 2011-01-05 19:23:48 UTC
There's Application Keypad, Application Cursor Keys, etc.  Look for it in ctlseq.txt from xterm.  I don't fully understand it either, but it's relevant to the part of code being touched (and in the way the proposed patch touches it without explanation).
Comment 18 klaus.kusche 2011-01-05 19:26:18 UTC
Comment #13:

You're right. I tried to make it work, mostly by looking at and copying
things from other keys, without fully analyzing why the code is the way it is.

But basically, we all don't care why it works as long as it works...
Comment 19 Yury V. Zaytsev 2011-01-05 19:37:46 UTC
Behdad, I've shown this report to my colleagues and they are telling me that I'm lying to you:

void
application_keypad_mode (void)
{
    if (console_flag || xterm_flag)
    {
        fputs ("\033=", stdout);
        fflush (stdout);
    }
}

Maybe it will be useful for you if you want to test your code in the application mode.
Comment 20 Yury V. Zaytsev 2011-01-05 19:44:39 UTC
Additional information: they claim that mc uses "application mode", because otherwise, the keypad doesn't work.
Comment 21 klaus.kusche 2011-01-05 19:54:51 UTC
Again about Comment #13:

The "if (cursor_app_mode &&" controls changing the "O" in "^[OH" 
to a "[" before inserting the modifier code sequence.

Without commenting out "cursor_app_mode &&",
I think we would get "^[O1;5H" instead of "^[[1;5H" in non-app mode,
which is not what we want:
We always want the the "O" -> "[" change, at least for Home and End.
(however, I did not check what other keys are affected by this change,
and if the change is ok for them. But I didn't notice any breakage up to now).
Comment 22 Behdad Esfahbod 2011-01-05 20:06:45 UTC
Thanks both.  These help. I digged into xterm and found some clues about how to handle these.  I'll take another look.
Comment 23 Yury V. Zaytsev 2011-04-12 07:56:20 UTC
As I noted in

https://bugzilla.gnome.org/show_bug.cgi?id=425462

the bug

https://bugzilla.gnome.org/show_bug.cgi?id=375652

seems to be related to both this and the other bug.
Comment 24 Alexej Ilin 2012-04-22 15:09:19 UTC
Created attachment 212545 [details] [review]
vte patch to solve mc <-> gnome-terminal keybindings problem

    Please look through my patch for vte. This patch is intended to solve some wide-known problems remaining with some key combinations in (gnome-terminal + mc and mcedit) and creates more comfortable thick blinking underling cursor.
    I don't think it is worth doing to accept this without changes. But it really works. It could be nice if the people who use vi or vim, and gnome-terminal developers, will test, cleare up and finally accept this patch.
    The patch makes the following changes:
    - switching on scrolling for Shift+Up/Down. It does not prevent normal work "inside" mcedit (as I understood, this is "application mode"), so this function was unreasonably moved to Alt+Shiht+Up/Down.
    - unlocked the \e-seq child application feedeng for all the Shift+ - scrolling combinations. These are: Alt+Shiht+Up/Down -> Shiht+Up/Down, Shiht+PgUp/PgDown, Shiht+Home/End.
    - The \e-seq. for all modif.+arrow, modif.+PgUp/PgDown appeared to be correct for me - leaved them unchanged.
    - Adjusted all the \e-seq. for the modif.+Home/End combinations,
    - added double \e\e for Esc that permits to leave mcedit quickly (this is the thing mc-users usially doing),
    - added \e\r for Ctrl+Enter to insert current file in mc to the command string (this tradition is very popular in Russia),
    - provides 1 pixel more thick cursor in underling mode.
    I assumed the \e-seq. for the keys combinations should be:

		Home	End	PgUp	PgDwn	Up	Down
      <>	[OH ([1~)[OF ([4~)[5~	[6~	[A	[B
Alt  +<>	[1;3H	[1;3F	[5;3~	[6;3~	[1;3A	[1;3B
Shiht+<>	[1;2H	[1;2F	[5;2~	[6;2~	[1;2A	[1;2B
Ctrl +<>	[1;5H	[1;5F	[5;5~	[6;5~	[1;5A	[1;5B
Ctrl+Shiht+<>	[1;6H	[1;6F	-	-	-	-
Ctrl+  Alt+<>	[1;7H	[1;7F	-	-	-	-
Shiht+ Alt+<>	[1;4H	[1;4F	[5;4~	[6;4~	[1;4A	[1;4B
Ctrl+Shiht+Alt+<>[1;8H	[1;8F	-	-	-	-

    I failed to provide correct \e-seq. for double-modifiers combinations. For example, you still can not highlight text till the end of file by Shift+Ctrl+End pressing. Sorry, voluntaries welcome.
   The system is: Scientific Linux 6.1, KDE 4.3.4, Gnome-terminal 2.31.3, vte 0.25.1

   And, last but not least. I'm joinig the people who vote that no keybindings should be hardcoded. Of course, gnome-terminal become much flexible, convienient and popular if all the keybindings will be adjustable in the  simple unified manner.
Comment 25 Christian Persch 2012-05-29 21:30:32 UTC
Comment on attachment 212545 [details] [review]
vte patch to solve mc <-> gnome-terminal keybindings problem

Obviously not commit-quality; marking the patch as needs-work.
Comment 26 klaus.kusche 2013-08-15 09:51:31 UTC
Anything going on here?

Having no solution is worse than having a 95 % solution...
Comment 27 André Klapper 2013-08-15 11:12:45 UTC
Somebody needs to rework the patch.
Comment 28 Igor Gnatenko 2013-12-21 21:41:20 UTC
Created attachment 264737 [details] [review]
0001-Home-End-generate-wrong-control-sequences.patch

(In reply to comment #25)
> (From update of attachment 212545 [details] [review])
> Obviously not commit-quality; marking the patch as needs-work.

Ok. Well, I've prepared this patch for committing, but according to comment #24 it has problems.
Comment 29 Igor Gnatenko 2013-12-21 21:48:00 UTC
Created attachment 264739 [details] [review]
0001-Home-End-generate-wrong-control-sequences.patch

more better description
Comment 30 Igor Gnatenko 2013-12-21 22:15:22 UTC
Created attachment 264740 [details] [review]
0001-Home-End-generate-wrong-control-sequences.patch

v3: drop comments in sources
Comment 31 Alexei Panov 2013-12-21 22:36:09 UTC
This patch works for me. I've tried it with vte3-0.34.9-1.fc20 in Fedora 20.
Comment 32 Behdad Esfahbod 2013-12-22 19:27:34 UTC
Egmont, you seem to know these things best.  Can you take a look?
Comment 33 Egmont Koblinger 2013-12-22 19:51:18 UTC
I hardly know anything about terminfo related stuff, it's always been a mystery to me. Anyway, I'll try to take a look as time permits, probably in January. Please ping me in about a month should I forget about it, the patch changes behavior so is a good candidate for a new major release but not for minor ones.

The original concern seems to be valid, vte indeed generates different escape than other terminals and ignores modifiers. However, home/end work for me in mc, I'm not sure how/why.

It's indeed true that in application mode (like mc, where there's no scrollback) certain keys generate different sequences, and I'm really not sure how to conveniently test them, perhaps stracing vte is the easiest...

A quick note: increasing cursor width is something that's always been bugging me, I'm using I-beam with my own patch to make it 2px wide instead of 1px, I was just too lazy to file a bug, but I'm all for it -- but it should be a separate patch with a separate bug record, not piggybacked on something completely irrelevant.
Comment 34 Igor Gnatenko 2013-12-22 19:54:46 UTC
(In reply to comment #33)
> I hardly know anything about terminfo related stuff, it's always been a mystery
> to me. Anyway, I'll try to take a look as time permits, probably in January.
> Please ping me in about a month should I forget about it, the patch changes
> behavior so is a good candidate for a new major release but not for minor ones.
will do.
> The original concern seems to be valid, vte indeed generates different escape
> than other terminals and ignores modifiers. However, home/end work for me in
> mc, I'm not sure how/why.
> 
> It's indeed true that in application mode (like mc, where there's no
> scrollback) certain keys generate different sequences, and I'm really not sure
> how to conveniently test them, perhaps stracing vte is the easiest...
you can run gnome-terminal, run vim, write some strings and test ^Home and ^End.
It doesn't work now. W/ this patch it works again.
P.S. ^ == Ctrl
> A quick note: increasing cursor width is something that's always been bugging
> me, I'm using I-beam with my own patch to make it 2px wide instead of 1px, I
> was just too lazy to file a bug, but I'm all for it -- but it should be a
> separate patch with a separate bug record, not piggybacked on something
> completely irrelevant.
Comment 35 Yury V. Zaytsev 2013-12-22 20:43:25 UTC
Hi Egmont,

It could be the case that it works for you in mc, because we query the modifiers using X, when possible. You can check by disabling it explicitly and see if it still works.

Z.
Comment 36 Egmont Koblinger 2013-12-22 20:46:22 UTC
Thanks Yury for the reminder, it suddenly didn't occur to me that mc does this, but indeed it does. I'll take care of testing mc both with and without X11 support.
Comment 37 Egmont Koblinger 2014-01-03 14:10:09 UTC
F1-F4 with modifiers also generate different sequences in vte and xterm.
Comment 38 Egmont Koblinger 2014-01-03 17:33:54 UTC
First, I'm trying to understand what xterm does, and which subset of that we'd like to implement. The doc (http://invisible-island.net/xterm/ctlseqs/ctlseqs.html) is not always clear to me or doesn't seem to always match the behavior. I'll take xterm-300's behavior as the reference.

Stuff I believe we shouldn't care about: alt/meta related resources, numLock resource (along with DECSET 1035), oldXtermFKeys, non-PC style (vt220, vt52, sun, hp) function keys.

Stuff we should care about: apparently there are two orthogonal internal states that influence the sequences generated by keys:

- Application Cursor Keys (\e[?1h) vs Normal Cursor Keys (\e[?1l). This modifies the behavior of seven symbols (most of which are accessible by two physical keys when numlock is off): Home, End, Left, Right, Up, Down and "Begin" (numpad 5 when numlock is off, whatever it is supposed to mean). When Application Cursor Keys mode is enabled, the escapes begin with \eO rather than \e[.

- Application Keypad (\e=) vs Normal Keypad (\e>). This modifies the behavior of the four numpad math operators only (although the doc says it should modify the behavior of space, tab and enter too). When Application Keypad mode is enabled, these keys generate escape sequences, rather than plain ascii characters.

There's also the external state: the NumLock modifier. Whenever NumLock is enabled, numpad keys ignore both of the internal states mentioned above, and just emit the corresponding digit or ./*-+ symbol. Standalone Home/End keys still depend on App/Normal Cursor Keys mode. Whenever NumLock is disabled, the ten numpad keys: up, down, left, right, home, end, pgup, pgdn, insert, delete always produce the same escapes as their standalone key counterparts.
Comment 39 Egmont Koblinger 2014-01-03 18:09:14 UTC
*** Bug 425462 has been marked as a duplicate of this bug. ***
Comment 40 Egmont Koblinger 2014-01-03 20:16:24 UTC
Igor, I've tried your patch but unfortunately I really don't get what you're doing.

Following the comments in your patch:

1. ^[OH vs ^[[H as per the original report, you didn't fix it.

2. Modifiers: these ones are fixed.

The bullet points starting with "-" characters:

- 1st, 2nd and 4th: Unfortunately I don't understand their descriptions - could you maybe describe them like "press this and that, previously it did foo, but now it does bar"?

- 5th and 6th: They change the behavior in ways incompatible with any other terminal emulator for the benefit of one particular application, likely breaking many others. Clearly unacceptable for inclusion in mainstream.

- 7th: Irrelevant to the current bugreport.
Comment 41 Egmont Koblinger 2014-01-04 00:15:12 UTC
Created attachment 265276 [details] [review]
Fix F1-F4 with modifiers
Comment 42 Egmont Koblinger 2014-01-04 00:15:37 UTC
Created attachment 265277 [details] [review]
Fix numpad /*-+ with modifiers
Comment 43 Egmont Koblinger 2014-01-04 00:16:04 UTC
Created attachment 265278 [details] [review]
Fix Home and End, with and without modifiers
Comment 44 Egmont Koblinger 2014-01-04 00:16:37 UTC
Created attachment 265279 [details] [review]
Fix Numpad 5 with modifiers
Comment 45 Egmont Koblinger 2014-01-04 00:21:45 UTC
I hope these patches make vte generate the same escapes as XTerm, whatever the state of the Application/Normal Cursor Mode flag, whatever the state of the Application Keypad flag, and whatever the status of NumLock is.

I didn't pay attention to the non-default emulation modes (vt220 and such), I didn't spend time figuring out how to enable them.

There's one difference I'm aware of: with NumLock enabled, pressing Shift + numpad 1, 3, 7 or 9 generate escapes in XTerm, while scroll the buffer in VTE. I'd be happy to live with it.
Comment 46 Egmont Koblinger 2014-01-04 00:35:17 UTC
I think there's one nontrivial part that deserves explanation. In the F1-F4 patch I add a separate entry for each modifier. This is because OR-ing them would require *all* of them to be pressed, but there we need to catch when *any* of them are active. Building up an infrastructure for this would have been overkill. When multiple modifiers are pressed at the same time, one of the branches will match and the code that encodes the modifiers will properly encode all of them, so it's okay.
Comment 47 Igor Gnatenko 2014-01-04 14:48:39 UTC
(In reply to comment #40)
> Igor, I've tried your patch but unfortunately I really don't get what you're
> doing.
This isn't my patch. I've got old patch and rebase it, because author unresponsive.
Comment 48 Igor Gnatenko 2014-01-04 15:50:00 UTC
Review of attachment 265279 [details] [review]:

Tested-by: Igor Gnatenko <i.gnatenko@gnome.org>
Comment 49 Igor Gnatenko 2014-01-04 15:50:05 UTC
Review of attachment 265278 [details] [review]:

Tested-by: Igor Gnatenko <i.gnatenko@gnome.org>
Comment 50 Igor Gnatenko 2014-01-04 15:50:09 UTC
Review of attachment 265277 [details] [review]:

Tested-by: Igor Gnatenko <i.gnatenko@gnome.org>
Comment 51 Igor Gnatenko 2014-01-04 15:50:18 UTC
Review of attachment 265276 [details] [review]:

Tested-by: Igor Gnatenko <i.gnatenko@gnome.org>
Comment 52 Igor Gnatenko 2014-01-04 15:52:25 UTC
whoops.. my mail is ignatenko@gnome.org ;)

I've tested this patch-set and it fixes all problems.
Comment 53 Egmont Koblinger 2014-01-04 21:12:10 UTC
(In reply to comment #47)
> This isn't my patch. I've got old patch and rebase it, because author
> unresponsive.

Indeed, these were created by Alexej, probably based on Klaus's patch. Sorry for that.

Thanks for testing my patches! :)
Comment 54 Egmont Koblinger 2014-01-04 21:22:05 UTC
In the mean time I also got a reply from Thomas E. Dickey (author of XTerm), basically boiling down to:

- ctlseqs.txt might be slightly out of date or incomplete, XTerm's actual behavior should be the reference.

- F1..F4 indeed switch to a completely different escape upon pressing any modifier.

- Most escape sequences switch to SS3 prefix on Application mode, but revert to CSI when a modifier is pressed. Numpad math operators are different, they get the modifiers with SS3.

- The story is more complicated than I stated above in comment 38, e.g. there are modifyCursorKeys and modifyFunctionKeys resources that also influence the behavior, but I don't think we should try to mimic all possible configurations of XTerm.
Comment 55 Egmont Koblinger 2014-01-05 22:18:32 UTC
(Unrelated note: the cursor width, which Alexej tried to change in his patch, can be configured dynamically as per bug 586950 comment 17.)
Comment 56 Egmont Koblinger 2014-01-05 23:32:26 UTC
*** Bug 157448 has been marked as a duplicate of this bug. ***
Comment 57 Egmont Koblinger 2014-01-07 18:55:25 UTC
Fixed in 0-36, keeping open for vte-next.
Comment 58 Yury V. Zaytsev 2014-01-07 18:59:11 UTC
Excellent work, Egmont, and highly appreciated!
Comment 59 Alexei Panov 2014-01-08 09:13:27 UTC
Thanks Egmont.
Comment 60 Igor Gnatenko 2014-01-08 09:19:42 UTC
Egmont, thank you! ;)

Don't forget close bug ;)
Comment 61 Egmont Koblinger 2014-01-08 21:16:30 UTC
*** Bug 310305 has been marked as a duplicate of this bug. ***
Comment 62 Egmont Koblinger 2014-01-08 21:53:35 UTC
*** Bug 674216 has been marked as a duplicate of this bug. ***
Comment 63 Christian Persch 2014-04-04 17:51:08 UTC
Hmm. I still get different behaviour in vte master compared to xterm 303 for the keypad keys:

key:     vte:    xterm:
KP Home: ^[[1~   ^[[H
KP End:  ^[[4~   ^[[F
Comment 64 Egmont Koblinger 2014-04-04 18:06:08 UTC
I get H and F in vte. Could the difference come from terminfo maybe?

Are you testing by a simple "cat", or something more complicated? There might be a numpad mode which changes the escape (although should do it consistently with xterm).
Comment 65 Christian Persch 2014-04-04 18:30:15 UTC
Just using cat. Numlock is off.
Comment 66 Egmont Koblinger 2014-04-04 18:47:51 UTC
keymap.c _vte_keymap_GDK_Home (and _End): which of those lines actually work for you? Change the escape sequence and see if it actually changes. For me it's the cursor_default lines that win with their hardcoded H/F. For you it could be the hardcoded 1~/4~ or via terminfo hk/@7.

I don't quite understand the process behind that selects the matching entry.

What's your TERM? Mine is xterm-256color.
Comment 67 Egmont Koblinger 2014-04-28 00:52:44 UTC
Seems I've accidentally found the reason for the ^[[1~ vs. ^[[H discrepancy. I have a broken laptop that alters the keycodes when numlock is turned off, so even from the keypad I emit Home instead of KP_Home.

I can temporarily disable this bug by holding down Fn, in which case I also get ^[[1~.

Details: https://bugs.freedesktop.org/show_bug.cgi?id=78012
Comment 68 Egmont Koblinger 2014-04-28 11:18:03 UTC
Created attachment 275319 [details] [review]
Fix Home/End on non-broken keyboards

I still have no clue what I'm doing, and no clue about vt220/notvt220/hp/sun. stuff. All I tested is the normal cursor mode (Home/End should generate ^[[F and ^[[H by default) and the application cursor mode (after executing echo -ne '\e[?1h', they should generate ^[OF and ^[OH), and it seems to work. Please verify.

Do we use that vt220/nonvt220 at all? Couldn't we just get rid of these vt220/hp/sun/etc fkey modes completely? I mean, if they are used anywhere, they are sure be quite broken by now.

It also looks that the whole mapping table deserves a big cleanup (maybe as part of bug 728900?). The three columns for the cursor, keypad and fkey values should hopefully each only influence a disjoint subset of the keys (numpad digits, numpad math operators and function keys respectively). I don't understand any of the keymap entry tables where more than one of these have a specific (rather than a match-all) entry.
Comment 69 klaus.kusche 2014-04-28 15:06:41 UTC
I can't test the patch now, but did you make sure that the home and end
control sequences get properly prefixed when home or end are pressed
together with modifiers (Shift / Alt / Ctrl)?

That's what this bug report was initially about:
Ctrl / Alt / Shift were completely ignored,
Home and End always sent the same sequence, 
even when combined with modifiers.
I (and others) need Ctrl/Home etc. for special fuctionality,
which is impossible right now in all vte-based terminals.
Comment 70 Egmont Koblinger 2014-04-28 15:18:28 UTC
That was fixed recently as part of this bug, and the new patch doesn't break it, I verified.
Comment 71 Christian Persch 2014-05-11 08:21:23 UTC
Re-opening. I had to revert the commit cbc73b6d40aa099643cce07400c31028cfaa7e8c because it caused a crash here, simply by starting vteapp, then pressing Ctrl-D to exit the shell:

Vte:ERROR:keymap.c:1080:_vte_keymap_map: assertion failed: ((fkey_mode == 0) || (fkey_mode == fkey_all))

Program received signal SIGABRT, Aborted.
0xb7fde424 in __kernel_vsyscall ()
(gdb) where
  • #0 __kernel_vsyscall
  • #1 __GI_raise
    at ../nptl/sysdeps/unix/sysv/linux/raise.c line 56
  • #2 __GI_abort
    at abort.c line 90
  • #3 g_assertion_message
  • #4 g_assertion_message_expr
  • #5 _vte_keymap_map
    at keymap.c line 1056
  • #6 vte_terminal_key_press
    at vte.c line 5144

Comment 72 Egmont Koblinger 2014-05-11 18:55:44 UTC
Indeed. Note: --enable-debug is required for this crash. I'll take a look.
Comment 73 Egmont Koblinger 2014-05-12 13:10:21 UTC
Could we please drop all these fkey_* stuff? (default, legacy, vt220, hp, sun; and we'd also need sco and termcap for full xterm parity)

It's a maintenance hell, just look at e.g. the definition of _vte_keymap_GDK_F1. It's encoding a 2x2x5 matrix (should be 2x2x7 for full xterm parity) for each and every single key (and even a single cell might have multiple entries, to try to look up termcap and then fall back to something hardcoded). I'm pretty sure I broke plenty of them (except fkey_default) with my recent changes and noone noticed :P Lack of unittests makes these tables pretty much unverifiable.

In xterm their availability is subject to configure flags, some being enabled, others being disabled by default. Konsole doesn't support these (although it lets you choose from some predefined keymaps and lets you create your own one). Putty, Terminology, St, Urxvt don't seem to support these either.

Without them, we'd only have a 2x2 matrix for each key which is easy to verify.

I'm happy to do this if you approve.
Comment 74 Egmont Koblinger 2014-05-13 16:57:18 UTC
Created attachment 276464 [details]
escapes.sh shell script to print almost all escape sequences

I created a script that dumps the keycodes generated by xterm or vte. It does it by synthesising keypresses, so you should leave it running for about 3 minutes without touching the keyboard.

The output (attached) reveals that the normal fkey mode is pretty much okay, KP_Home/KP_End are the only remaining serious issue. The other fkey modes are quite off from xterm, probably a good reason to drop them.

After cleaning up, this script could be put in git. One remaining TODO: we could pass the window id to xdotool, but that'd require vteapp to set $WINDOWID.
Comment 75 Egmont Koblinger 2014-05-13 16:58:03 UTC
Created attachment 276465 [details]
current vte escape sequences
Comment 76 Egmont Koblinger 2014-05-13 16:58:32 UTC
Created attachment 276466 [details]
current xterm escape sequences
Comment 77 Egmont Koblinger 2014-05-14 15:12:43 UTC
Created attachment 276538 [details] [review]
Fix Home/End on non-broken keyboards, take 2

This one really fixes keypad home/end. This time I've verified with the script :) so I'm committing right away.

Only the default fkey mode is fixed, vt220 is unchanged (correct), hp/sun/legacy were broken anyways and now they are still broken in a slightly different way.
Comment 78 Egmont Koblinger 2014-05-14 15:15:02 UTC
Created attachment 276539 [details]
current vte escape sequences (after comment 77)
Comment 79 Egmont Koblinger 2014-05-14 15:43:20 UTC
Escape sequences of the "default" kbd mode should be okay now.

Removal of non-default kbd modes is continued in bug 730137.
Comment 80 dann 2014-05-15 00:48:32 UTC
(In reply to comment #76)
> Created an attachment (id=276466) [details]
> current xterm escape sequences

Any plan to add support for xterm's modifyOtherKeys=2 key bindings?
Those are very useful...
Comment 81 Egmont Koblinger 2014-05-15 01:15:00 UTC
Nope, no plans, sorry – at least not from me. I'd even wish to eliminate some of the rarely used features (like sun/hp/etc. function keys), not even add a new one.

If you have good reasons and you'd like to convince us, please open a new enhancement request, cc me, and tell us which applications and how would benefit from this. I still don't promise anything, but at least we won't forget about the request. Thanks.
Comment 82 klaus.kusche 2014-06-08 11:44:52 UTC
Could we please have that committed also to vte 2.x?

Both privately and at our university, we use xfce, which is gtk 2.x.
Moreover, the primary editor here is geany,
which also uses gtk 2's vte for its integrated terminal.
Comment 83 Christian Persch 2014-06-08 12:38:02 UTC
I don't think so. vte 2.x is unmaintained and likely contains unfixed security bugs, so anything that prolongs its use should be discouraged. If xfce still depends on it, it's them that should step up to maintain it...
Comment 84 Egmont Koblinger 2016-03-06 23:37:04 UTC
*** Bug 763190 has been marked as a duplicate of this bug. ***