diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-10-11 07:01:11 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2009-10-11 07:01:11 +0000 |
commit | 3349c90a7d8ef703d35563da2596b500032a7d54 (patch) | |
tree | d3671d845adabdb4e4e28603b88c09eecd974f98 /usr.bin/tmux | |
parent | 0ac4ee24fd18d5a19768920e53edc59ed16988ee (diff) |
Clean up by introducing a wrapper struct for mouse clicks rather than passing
three u_chars around.
As a side-effect this fixes incorrectly rejecting high cursor positions
(because it was comparing them as signed char), reported by Tom Doherty.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/input-keys.c | 10 | ||||
-rw-r--r-- | usr.bin/tmux/server.c | 10 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 18 | ||||
-rw-r--r-- | usr.bin/tmux/tty-keys.c | 23 | ||||
-rw-r--r-- | usr.bin/tmux/window-choose.c | 16 | ||||
-rw-r--r-- | usr.bin/tmux/window-copy.c | 16 | ||||
-rw-r--r-- | usr.bin/tmux/window.c | 18 |
7 files changed, 59 insertions, 52 deletions
diff --git a/usr.bin/tmux/input-keys.c b/usr.bin/tmux/input-keys.c index 5fa4640c98b..a284f9decda 100644 --- a/usr.bin/tmux/input-keys.c +++ b/usr.bin/tmux/input-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: input-keys.c,v 1.3 2009/07/26 21:42:08 nicm Exp $ */ +/* $OpenBSD: input-keys.c,v 1.4 2009/10/11 07:01:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -219,12 +219,12 @@ input_key(struct window_pane *wp, int key) /* Handle input mouse. */ void -input_mouse(struct window_pane *wp, u_char b, u_char x, u_char y) +input_mouse(struct window_pane *wp, struct mouse_event *m) { if (wp->screen->mode & MODE_MOUSE) { buffer_write(wp->out, "\033[M", 3); - buffer_write8(wp->out, b + 32); - buffer_write8(wp->out, x + 33); - buffer_write8(wp->out, y + 33); + buffer_write8(wp->out, m->b + 32); + buffer_write8(wp->out, m->x + 33); + buffer_write8(wp->out, m->y + 33); } } diff --git a/usr.bin/tmux/server.c b/usr.bin/tmux/server.c index d649876440f..2396639f516 100644 --- a/usr.bin/tmux/server.c +++ b/usr.bin/tmux/server.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server.c,v 1.51 2009/10/11 00:53:14 nicm Exp $ */ +/* $OpenBSD: server.c,v 1.52 2009/10/11 07:01:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -880,9 +880,9 @@ server_handle_client(struct client *c) struct timeval tv; struct key_binding *bd; struct keylist *keylist; + struct mouse_event mouse; int key, status, xtimeout, mode, isprefix; u_int i; - u_char mouse[3]; xtimeout = options_get_number(&c->session->options, "repeat-time"); if (xtimeout != 0 && c->flags & CLIENT_REPEAT) { @@ -894,7 +894,7 @@ server_handle_client(struct client *c) /* Process keys. */ keylist = options_get_data(&c->session->options, "prefix"); - while (tty_keys_next(&c->tty, &key, mouse) == 0) { + while (tty_keys_next(&c->tty, &key, &mouse) == 0) { if (c->session == NULL) return; @@ -922,10 +922,10 @@ server_handle_client(struct client *c) /* Check for mouse keys. */ if (key == KEYC_MOUSE) { if (options_get_number(oo, "mouse-select-pane")) { - window_set_active_at(w, mouse[1], mouse[2]); + window_set_active_at(w, mouse.x, mouse.y); wp = w->active; } - window_pane_mouse(wp, c, mouse[0], mouse[1], mouse[2]); + window_pane_mouse(wp, c, &mouse); continue; } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index 72cfed5dfb2..f3518de76eb 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.128 2009/10/10 18:42:14 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.129 2009/10/11 07:01:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -674,13 +674,14 @@ struct input_ctx { */ struct client; struct window; +struct mouse_event; struct window_mode { struct screen *(*init)(struct window_pane *); void (*free)(struct window_pane *); void (*resize)(struct window_pane *, u_int, u_int); void (*key)(struct window_pane *, struct client *, int); void (*mouse)(struct window_pane *, - struct client *, u_char, u_char, u_char); + struct client *, struct mouse_event *); void (*timer)(struct window_pane *); }; @@ -951,6 +952,13 @@ struct tty_ctx { u_int orlower; }; +/* Mouse input. */ +struct mouse_event { + u_char b; + u_char x; + u_char y; +}; + /* Client connection. */ struct client { struct imsgbuf ibuf; @@ -1285,7 +1293,7 @@ int tty_keys_cmp(struct tty_key *, struct tty_key *); RB_PROTOTYPE(tty_keys, tty_key, entry, tty_keys_cmp); void tty_keys_init(struct tty *); void tty_keys_free(struct tty *); -int tty_keys_next(struct tty *, int *, u_char *); +int tty_keys_next(struct tty *, int *, struct mouse_event *); /* options-cmd.c */ const char *set_option_print( @@ -1542,7 +1550,7 @@ void input_parse(struct window_pane *); /* input-key.c */ void input_key(struct window_pane *, int); -void input_mouse(struct window_pane *, u_char, u_char, u_char); +void input_mouse(struct window_pane *, struct mouse_event *); /* colour.c */ void colour_set_fg(struct grid_cell *, int); @@ -1705,7 +1713,7 @@ void window_pane_reset_mode(struct window_pane *); void window_pane_parse(struct window_pane *); void window_pane_key(struct window_pane *, struct client *, int); void window_pane_mouse(struct window_pane *, - struct client *, u_char, u_char, u_char); + struct client *, struct mouse_event *); int window_pane_visible(struct window_pane *); char *window_pane_search( struct window_pane *, const char *, u_int *); diff --git a/usr.bin/tmux/tty-keys.c b/usr.bin/tmux/tty-keys.c index 4e2e13f3668..c8af2bd1b56 100644 --- a/usr.bin/tmux/tty-keys.c +++ b/usr.bin/tmux/tty-keys.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tty-keys.c,v 1.4 2009/09/20 14:58:12 nicm Exp $ */ +/* $OpenBSD: tty-keys.c,v 1.5 2009/10/11 07:01:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -27,7 +27,7 @@ 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_parse_mouse(struct tty *, char *, size_t, size_t *, u_char *); +int tty_keys_parse_mouse(char *, size_t, size_t *, struct mouse_event *); struct tty_key_ent { enum tty_code_code code; @@ -231,7 +231,7 @@ tty_keys_find(struct tty *tty, char *buf, size_t len, size_t *size) } int -tty_keys_next(struct tty *tty, int *key, u_char *mouse) +tty_keys_next(struct tty *tty, int *key, struct mouse_event *mouse) { struct tty_key *tk; struct timeval tv; @@ -269,7 +269,7 @@ tty_keys_next(struct tty *tty, int *key, u_char *mouse) } /* Not found. Is this a mouse key press? */ - *key = tty_keys_parse_mouse(tty, buf, len, &size, mouse); + *key = tty_keys_parse_mouse(buf, len, &size, mouse); if (*key != KEYC_NONE) { buffer_remove(tty->in, size); goto found; @@ -331,8 +331,7 @@ found: } int -tty_keys_parse_mouse( - unused struct tty *tty, char *buf, size_t len, size_t *size, u_char *mouse) +tty_keys_parse_mouse(char *buf, size_t len, size_t *size, struct mouse_event *m) { /* * Mouse sequences are \033[M followed by three characters indicating @@ -344,12 +343,14 @@ tty_keys_parse_mouse( return (KEYC_NONE); *size = 6; - if (buf[3] < 32 || buf[4] < 33 || buf[5] < 33) + m->b = buf[3]; + m->x = buf[4]; + m->y = buf[5]; + if (m->b < 32 || m->x < 33 || m->y < 33) return (KEYC_NONE); - - mouse[0] = buf[3] - 32; - mouse[1] = buf[4] - 33; - mouse[2] = buf[5] - 33; + m->b -= 32; + m->x -= 33; + m->y -= 33; return (KEYC_MOUSE); } diff --git a/usr.bin/tmux/window-choose.c b/usr.bin/tmux/window-choose.c index 45db4eec550..cb129e09004 100644 --- a/usr.bin/tmux/window-choose.c +++ b/usr.bin/tmux/window-choose.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-choose.c,v 1.9 2009/09/10 17:16:24 nicm Exp $ */ +/* $OpenBSD: window-choose.c,v 1.10 2009/10/11 07:01:10 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicm@users.sourceforge.net> @@ -27,7 +27,7 @@ void window_choose_free(struct window_pane *); void window_choose_resize(struct window_pane *, u_int, u_int); void window_choose_key(struct window_pane *, struct client *, int); void window_choose_mouse( - struct window_pane *, struct client *, u_char, u_char, u_char); + struct window_pane *, struct client *, struct mouse_event *); void window_choose_redraw_screen(struct window_pane *); void window_choose_write_line( @@ -264,22 +264,22 @@ window_choose_key(struct window_pane *wp, unused struct client *c, int key) } void -window_choose_mouse(struct window_pane *wp, - unused struct client *c, u_char b, u_char x, u_char y) +window_choose_mouse( + struct window_pane *wp, unused struct client *c, struct mouse_event *m) { struct window_choose_mode_data *data = wp->modedata; struct screen *s = &data->screen; struct window_choose_mode_item *item; u_int idx; - if ((b & 3) == 3) + if ((m->b & 3) == 3) return; - if (x >= screen_size_x(s)) + if (m->x >= screen_size_x(s)) return; - if (y >= screen_size_y(s)) + if (m->y >= screen_size_y(s)) return; - idx = data->top + y; + idx = data->top + m->y; if (idx >= ARRAY_LENGTH(&data->list)) return; data->selected = idx; diff --git a/usr.bin/tmux/window-copy.c b/usr.bin/tmux/window-copy.c index 00223e5142a..502af6073f3 100644 --- a/usr.bin/tmux/window-copy.c +++ b/usr.bin/tmux/window-copy.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window-copy.c,v 1.28 2009/10/06 07:09:00 nicm Exp $ */ +/* $OpenBSD: window-copy.c,v 1.29 2009/10/11 07:01:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -29,7 +29,7 @@ void window_copy_resize(struct window_pane *, u_int, u_int); void window_copy_key(struct window_pane *, struct client *, int); int window_copy_key_input(struct window_pane *, int); void window_copy_mouse( - struct window_pane *, struct client *, u_char, u_char, u_char); + struct window_pane *, struct client *, struct mouse_event *); void window_copy_redraw_lines(struct window_pane *, u_int, u_int); void window_copy_redraw_screen(struct window_pane *); @@ -418,20 +418,20 @@ window_copy_key_input(struct window_pane *wp, int key) } void -window_copy_mouse(struct window_pane *wp, - unused struct client *c, u_char b, u_char x, u_char y) +window_copy_mouse( + struct window_pane *wp, unused struct client *c, struct mouse_event *m) { struct window_copy_mode_data *data = wp->modedata; struct screen *s = &data->screen; - if ((b & 3) == 3) + if ((m->b & 3) == 3) return; - if (x >= screen_size_x(s)) + if (m->x >= screen_size_x(s)) return; - if (y >= screen_size_y(s)) + if (m->y >= screen_size_y(s)) return; - window_copy_update_cursor(wp, x, y); + window_copy_update_cursor(wp, m->x, m->y); if (window_copy_update_selection(wp)) window_copy_redraw_screen(wp); } diff --git a/usr.bin/tmux/window.c b/usr.bin/tmux/window.c index cb0f1cc1a88..f77e7cd758c 100644 --- a/usr.bin/tmux/window.c +++ b/usr.bin/tmux/window.c @@ -1,4 +1,4 @@ -/* $OpenBSD: window.c,v 1.30 2009/10/10 15:29:34 nicm Exp $ */ +/* $OpenBSD: window.c,v 1.31 2009/10/11 07:01:10 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicm@users.sourceforge.net> @@ -653,25 +653,23 @@ window_pane_key(struct window_pane *wp, struct client *c, int key) void window_pane_mouse( - struct window_pane *wp, struct client *c, u_char b, u_char x, u_char y) + struct window_pane *wp, struct client *c, struct mouse_event *m) { if (!window_pane_visible(wp)) return; - /* XXX convert from 1-based? */ - - if (x < wp->xoff || x >= wp->xoff + wp->sx) + if (m->x < wp->xoff || m->x >= wp->xoff + wp->sx) return; - if (y < wp->yoff || y >= wp->yoff + wp->sy) + if (m->y < wp->yoff || m->y >= wp->yoff + wp->sy) return; - x -= wp->xoff; - y -= wp->yoff; + m->x -= wp->xoff; + m->y -= wp->yoff; if (wp->mode != NULL) { if (wp->mode->mouse != NULL) - wp->mode->mouse(wp, c, b, x, y); + wp->mode->mouse(wp, c, m); } else if (wp->fd != -1) - input_mouse(wp, b, x, y); + input_mouse(wp, m); } int |