input: make the Ctrl+Arrow keys work on a Linux console

If this breaks your build, please send report or instructions or patch.
This commit is contained in:
Benno Schulenberg 2016-07-29 09:15:07 +02:00
parent 8edb096821
commit 290d278f68
4 changed files with 26 additions and 0 deletions

View File

@ -33,6 +33,8 @@ volatile sig_atomic_t sigwinch_counter = 0;
/* Is incremented by the handler whenever a SIGWINCH occurs. */
#endif
bool console;
/* Whether we're running on a Linux VC (TRUE) or under X (FALSE). */
bool meta_key;
/* Whether the current keystroke is a Meta key. */
bool focusing = TRUE;

View File

@ -2482,6 +2482,9 @@ int main(int argc, char **argv)
/* Set up the terminal state. */
terminal_init();
/* Check whether we're running on a Linux console. */
console = (getenv("DISPLAY") == NULL);
#ifdef DEBUG
fprintf(stderr, "Main: set up windows\n");
#endif

View File

@ -30,6 +30,7 @@
extern volatile sig_atomic_t sigwinch_counter;
#endif
extern bool console;
extern bool meta_key;
extern bool focusing;

View File

@ -23,6 +23,8 @@
#include "proto.h"
#include "revision.h"
#include <sys/ioctl.h>
#include <stdio.h>
#include <stdarg.h>
#include <string.h>
@ -502,6 +504,24 @@ int parse_kbinput(WINDOW *win)
return sc_seq_or(do_next_block, 0);
#endif
/* When not running under X, check for the bare arrow keys whether
* the Ctrl key is being held together with them. */
if (console && (retval == KEY_UP || retval == KEY_DOWN ||
retval == KEY_LEFT || retval == KEY_RIGHT)) {
unsigned char modifiers = 6;
if (ioctl(0, TIOCLINUX, &modifiers) >= 0 && (modifiers & 0x04)) {
if (retval == KEY_UP)
return sc_seq_or(do_prev_block, 0);
else if (retval == KEY_DOWN)
return sc_seq_or(do_next_block, 0);
else if (retval == KEY_LEFT)
return sc_seq_or(do_prev_word_void, 0);
else
return sc_seq_or(do_next_word_void, 0);
}
}
switch (retval) {
#ifdef KEY_SLEFT
/* Slang doesn't support KEY_SLEFT. */