Wednesday, July 22, 2009

Sane terminal behaviour with PgUp and friends

In gnome-terminal on Solaris 10, if you hit the PgUp key, it scrolls the window up. The PgDn, Home, and End keys similarly move the scrollbar.

That's the behaviour I want. It's also what you've traditionally had with xterm, dtterm, and the like.

Recently, it's become fashionable to pass PgUp and friends through to the application, so you get the application running inside the terminal emulator to do its own interpretation, and require the shift key to be pressed in order to get the terminal window itself to scroll.

I find that incredibly disruptive. I don't run anything inside a terminal that does its own scrolling (other than more, and I don't need to reach as far as the PgUp key to manipulate that). Most of the more advanced applications I run are graphical anyway.

So, how to fix? In my exploration of xfce, the Terminal application uses a newer version of vte which suffers from the above problem. So I set out to fix it, and it was relatively simple.

I used vte-0.20.5, and if you look at around line 5055 of vte.c, you'll see some code that looks like:

case GDK_KP_Page_Up:
case GDK_Page_Up:
if (modifiers & GDK_SHIFT_MASK) {
vte_terminal_scroll_pages(terminal, -1);
scrolled = TRUE;
handled = TRUE;
suppress_meta_esc = TRUE;
}
break;

simply remove the test for the shift:

case GDK_KP_Page_Up:
case GDK_Page_Up:
vte_terminal_scroll_pages(terminal, -1);
scrolled = TRUE;
handled = TRUE;
suppress_meta_esc = TRUE;
break;

for all four keys of interest, and rebuild.

My life is so much better as a result.

It's a shame that's not the default, but there are others who rely on the opposite behaviour. It would be nice if it was customizable - it's OK for me to build a separate copy for my own use on my own machine, but that's not very flexible. It would be neat if it could autodetect the terminal mode and do the right thing.

No comments: