diff options
author | nicm <nicm> | 2019-05-03 14:51:30 +0000 |
---|---|---|
committer | nicm <nicm> | 2019-05-03 14:51:30 +0000 |
commit | 33298d6df67e2ba3d90abdc94250eeaa963c3730 (patch) | |
tree | cce81fff5e3c4c4272eb5a1a6476c0dcc6ede966 /tty-keys.c | |
parent | 4bb48998e075017707b0fd8d61499409bd144c6d (diff) | |
download | rtmux-33298d6df67e2ba3d90abdc94250eeaa963c3730.tar.gz rtmux-33298d6df67e2ba3d90abdc94250eeaa963c3730.tar.bz2 rtmux-33298d6df67e2ba3d90abdc94250eeaa963c3730.zip |
Instead of processing keys all together, put them up on the client
command queue so they are ordered correctly with the commands that they
execute.
Diffstat (limited to 'tty-keys.c')
-rw-r--r-- | tty-keys.c | 60 |
1 files changed, 36 insertions, 24 deletions
@@ -46,7 +46,8 @@ static struct tty_key *tty_keys_find(struct tty *, const char *, size_t, static int tty_keys_next1(struct tty *, const char *, size_t, key_code *, size_t *, int); static void tty_keys_callback(int, short, void *); -static int tty_keys_mouse(struct tty *, const char *, size_t, size_t *); +static int tty_keys_mouse(struct tty *, const char *, size_t, size_t *, + struct mouse_event *); static int tty_keys_clipboard(struct tty *, const char *, size_t, size_t *); static int tty_keys_device_attributes(struct tty *, const char *, size_t, @@ -560,25 +561,26 @@ tty_keys_next1(struct tty *tty, const char *buf, size_t len, key_code *key, return (-1); } -/* - * Process at least one key in the buffer and invoke tty->key_callback. Return - * 0 if there are no further keys, or 1 if there could be more in the buffer. - */ -key_code +/* Process at least one key in the buffer. Return 0 if no keys present. */ +int tty_keys_next(struct tty *tty) { - struct client *c = tty->client; - struct timeval tv; - const char *buf; - size_t len, size; - cc_t bspace; - int delay, expired = 0, n; - key_code key; + struct client *c = tty->client; + struct timeval tv; + const char *buf; + size_t len, size; + cc_t bspace; + int delay, expired = 0, n; + key_code key; + struct cmdq_item *item; + struct mouse_event m = { 0 }; + struct key_event *event; + + gettimeofday(&tv, NULL); /* Get key buffer. */ buf = EVBUFFER_DATA(tty->in); len = EVBUFFER_LENGTH(tty->in); - if (len == 0) return (0); log_debug("%s: keys are %zu (%.*s)", c->name, len, (int)len, buf); @@ -606,7 +608,7 @@ tty_keys_next(struct tty *tty) } /* Is this a mouse key press? */ - switch (tty_keys_mouse(tty, buf, len, &size)) { + switch (tty_keys_mouse(tty, buf, len, &size, &m)) { case 0: /* yes */ key = KEYC_MOUSE; goto complete_key; @@ -725,8 +727,14 @@ complete_key: } /* Fire the key. */ - if (key != KEYC_UNKNOWN) - server_client_handle_key(tty->client, key); + if (key != KEYC_UNKNOWN) { + event = xmalloc(sizeof *event); + event->key = key; + memcpy(&event->m, &m, sizeof event->m); + + item = cmdq_get_callback(server_client_key_callback, event); + cmdq_append(c, item); + } return (1); @@ -756,12 +764,12 @@ tty_keys_callback(__unused int fd, __unused short events, void *data) * (probably a mouse sequence but need more data). */ static int -tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size) +tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size, + struct mouse_event *m) { - struct client *c = tty->client; - struct mouse_event *m = &tty->mouse; - u_int i, x, y, b, sgr_b; - u_char sgr_type, ch; + struct client *c = tty->client; + u_int i, x, y, b, sgr_b; + u_char sgr_type, ch; /* * Standard mouse sequences are \033[M followed by three characters @@ -882,15 +890,19 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size) return (-1); /* Fill mouse event. */ - m->lx = m->x; + m->lx = tty->mouse_last_x; m->x = x; - m->ly = m->y; + m->ly = tty->mouse_last_y; m->y = y; m->lb = m->b; m->b = b; m->sgr_type = sgr_type; m->sgr_b = sgr_b; + /* Update last mouse state. */ + tty->mouse_last_x = x; + tty->mouse_last_y = y; + return (0); } |