version 1.68, 2020/03/16 06:12:42 |
version 1.69, 2020/03/19 14:03:48 |
|
|
return (1); |
return (1); |
} |
} |
|
|
|
/* Translate a key code into an output key sequence for a pane. */ |
|
int |
|
input_key_pane(struct window_pane *wp, key_code key, struct mouse_event *m) |
|
{ |
|
log_debug("writing key 0x%llx (%s) to %%%u", key, |
|
key_string_lookup_key(key), wp->id); |
|
|
|
if (KEYC_IS_MOUSE(key)) { |
|
if (m != NULL && m->wp != -1 && (u_int)m->wp == wp->id) |
|
input_key_mouse(wp, m); |
|
return (0); |
|
} |
|
return (input_key(wp, wp->screen, wp->event, key)); |
|
} |
|
|
/* Translate a key code into an output key sequence. */ |
/* Translate a key code into an output key sequence. */ |
int |
int |
input_key(struct window_pane *wp, key_code key, struct mouse_event *m) |
input_key(struct window_pane *wp, struct screen *s, struct bufferevent *bev, |
|
key_code key) |
{ |
{ |
const struct input_key_ent *ike; |
const struct input_key_ent *ike; |
u_int i; |
u_int i; |
|
|
key_code justkey, newkey; |
key_code justkey, newkey; |
struct utf8_data ud; |
struct utf8_data ud; |
|
|
log_debug("writing key 0x%llx (%s) to %%%u", key, |
/* Mouse keys need a pane. */ |
key_string_lookup_key(key), wp->id); |
if (KEYC_IS_MOUSE(key)) |
|
|
/* If this is a mouse key, pass off to mouse function. */ |
|
if (KEYC_IS_MOUSE(key)) { |
|
if (m != NULL && m->wp != -1 && (u_int)m->wp == wp->id) |
|
input_key_mouse(wp, m); |
|
return (0); |
return (0); |
} |
|
|
|
/* Literal keys go as themselves (can't be more than eight bits). */ |
/* Literal keys go as themselves (can't be more than eight bits). */ |
if (key & KEYC_LITERAL) { |
if (key & KEYC_LITERAL) { |
ud.data[0] = (u_char)key; |
ud.data[0] = (u_char)key; |
bufferevent_write(wp->event, &ud.data[0], 1); |
bufferevent_write(bev, &ud.data[0], 1); |
return (0); |
return (0); |
} |
} |
|
|
|
|
justkey = (key & ~(KEYC_XTERM|KEYC_ESCAPE)); |
justkey = (key & ~(KEYC_XTERM|KEYC_ESCAPE)); |
if (justkey <= 0x7f) { |
if (justkey <= 0x7f) { |
if (key & KEYC_ESCAPE) |
if (key & KEYC_ESCAPE) |
bufferevent_write(wp->event, "\033", 1); |
bufferevent_write(bev, "\033", 1); |
ud.data[0] = justkey; |
ud.data[0] = justkey; |
bufferevent_write(wp->event, &ud.data[0], 1); |
bufferevent_write(bev, &ud.data[0], 1); |
return (0); |
return (0); |
} |
} |
if (justkey > 0x7f && justkey < KEYC_BASE) { |
if (justkey > 0x7f && justkey < KEYC_BASE) { |
if (utf8_split(justkey, &ud) != UTF8_DONE) |
if (utf8_split(justkey, &ud) != UTF8_DONE) |
return (-1); |
return (-1); |
if (key & KEYC_ESCAPE) |
if (key & KEYC_ESCAPE) |
bufferevent_write(wp->event, "\033", 1); |
bufferevent_write(bev, "\033", 1); |
bufferevent_write(wp->event, ud.data, ud.size); |
bufferevent_write(bev, ud.data, ud.size); |
return (0); |
return (0); |
} |
} |
|
|
|
|
* Then try to look this up as an xterm key, if the flag to output them |
* Then try to look this up as an xterm key, if the flag to output them |
* is set. |
* is set. |
*/ |
*/ |
if (options_get_number(wp->window->options, "xterm-keys")) { |
if (wp == NULL || options_get_number(wp->window->options, "xterm-keys")) { |
if ((out = xterm_keys_lookup(key)) != NULL) { |
if ((out = xterm_keys_lookup(key)) != NULL) { |
bufferevent_write(wp->event, out, strlen(out)); |
bufferevent_write(bev, out, strlen(out)); |
free(out); |
free(out); |
return (0); |
return (0); |
} |
} |
|
|
for (i = 0; i < nitems(input_keys); i++) { |
for (i = 0; i < nitems(input_keys); i++) { |
ike = &input_keys[i]; |
ike = &input_keys[i]; |
|
|
if ((ike->flags & INPUTKEY_KEYPAD) && |
if ((ike->flags & INPUTKEY_KEYPAD) && (~s->mode & MODE_KKEYPAD)) |
!(wp->screen->mode & MODE_KKEYPAD)) |
|
continue; |
continue; |
if ((ike->flags & INPUTKEY_CURSOR) && |
if ((ike->flags & INPUTKEY_CURSOR) && (~s->mode & MODE_KCURSOR)) |
!(wp->screen->mode & MODE_KCURSOR)) |
|
continue; |
continue; |
|
|
if ((key & KEYC_ESCAPE) && (ike->key | KEYC_ESCAPE) == key) |
if ((key & KEYC_ESCAPE) && (ike->key | KEYC_ESCAPE) == key) |
|
|
|
|
/* Prefix a \033 for escape. */ |
/* Prefix a \033 for escape. */ |
if (key & KEYC_ESCAPE) |
if (key & KEYC_ESCAPE) |
bufferevent_write(wp->event, "\033", 1); |
bufferevent_write(bev, "\033", 1); |
bufferevent_write(wp->event, ike->data, dlen); |
bufferevent_write(bev, ike->data, dlen); |
return (0); |
return (0); |
} |
} |
|
|