version 1.5, 2009/10/11 07:01:10 |
version 1.6, 2009/10/26 13:02:53 |
|
|
#include "tmux.h" |
#include "tmux.h" |
|
|
void tty_keys_add(struct tty *, const char *, int, int); |
void tty_keys_add(struct tty *, const char *, int, int); |
int tty_keys_parse_xterm(struct tty *, char *, size_t, size_t *); |
int tty_keys_mouse(char *, size_t, size_t *, struct mouse_event *); |
int tty_keys_parse_mouse(char *, size_t, size_t *, struct mouse_event *); |
|
|
|
struct tty_key_ent { |
struct tty_key_ent { |
enum tty_code_code code; |
enum tty_code_code code; |
|
|
} |
} |
|
|
/* Not found. Is this a mouse key press? */ |
/* Not found. Is this a mouse key press? */ |
*key = tty_keys_parse_mouse(buf, len, &size, mouse); |
*key = tty_keys_mouse(buf, len, &size, mouse); |
if (*key != KEYC_NONE) { |
if (*key != KEYC_NONE) { |
buffer_remove(tty->in, size); |
buffer_remove(tty->in, size); |
goto found; |
goto found; |
} |
} |
|
|
/* Not found. Try to parse xterm-type arguments. */ |
|
*key = tty_keys_parse_xterm(tty, buf, len, &size); |
|
if (*key != KEYC_NONE) { |
|
buffer_remove(tty->in, size); |
|
goto found; |
|
} |
|
|
|
/* Escape but no key string. If the timer isn't started, start it. */ |
/* Escape but no key string. If the timer isn't started, start it. */ |
if (!(tty->flags & TTY_ESCAPE)) { |
if (!(tty->flags & TTY_ESCAPE)) { |
tv.tv_sec = 0; |
tv.tv_sec = 0; |
|
|
} |
} |
|
|
int |
int |
tty_keys_parse_mouse(char *buf, size_t len, size_t *size, struct mouse_event *m) |
tty_keys_mouse(char *buf, size_t len, size_t *size, struct mouse_event *m) |
{ |
{ |
/* |
/* |
* Mouse sequences are \033[M followed by three characters indicating |
* Mouse sequences are \033[M followed by three characters indicating |
|
|
m->x -= 33; |
m->x -= 33; |
m->y -= 33; |
m->y -= 33; |
return (KEYC_MOUSE); |
return (KEYC_MOUSE); |
} |
|
|
|
int |
|
tty_keys_parse_xterm(struct tty *tty, char *buf, size_t len, size_t *size) |
|
{ |
|
struct tty_key *tk; |
|
char tmp[5]; |
|
size_t tmplen; |
|
int key; |
|
|
|
/* |
|
* xterm sequences with modifier keys are of the form: |
|
* |
|
* ^[[1;xD becomes ^[[D |
|
* ^[[5;x~ becomes ^[[5~ |
|
* |
|
* This function is a bit of a hack. Need to figure out what exact |
|
* format and meaning xterm outputs and fix it. XXX |
|
*/ |
|
|
|
log_debug("xterm input is: %.*s", (int) len, buf); |
|
if (len != 6 || memcmp(buf, "\033[1;", 4) != 0) |
|
return (KEYC_NONE); |
|
*size = 6; |
|
|
|
tmplen = 0; |
|
tmp[tmplen++] = '['; |
|
if (buf[5] == '~') { |
|
tmp[tmplen++] = buf[2]; |
|
tmp[tmplen++] = '~'; |
|
} else |
|
tmp[tmplen++] = buf[5]; |
|
log_debug("xterm output is: %.*s", (int) tmplen, tmp); |
|
|
|
tk = tty_keys_find(tty, tmp, tmplen, size); |
|
if (tk == NULL) |
|
return (KEYC_NONE); |
|
key = tk->key; |
|
|
|
switch (buf[4]) { |
|
case '8': |
|
key |= KEYC_SHIFT|KEYC_ESCAPE|KEYC_CTRL; |
|
break; |
|
case '7': |
|
key |= KEYC_ESCAPE|KEYC_CTRL; |
|
break; |
|
case '6': |
|
key |= KEYC_SHIFT|KEYC_CTRL; |
|
break; |
|
case '5': |
|
key |= KEYC_CTRL; |
|
break; |
|
case '4': |
|
key |= KEYC_SHIFT|KEYC_ESCAPE; |
|
break; |
|
case '3': |
|
key |= KEYC_ESCAPE; |
|
break; |
|
case '2': |
|
key |= KEYC_SHIFT; |
|
break; |
|
} |
|
|
|
*size = 6; |
|
return (key); |
|
} |
} |