From b26ea8462ec0bb7d3d5cbeed115f6f4bbd4e1072 Mon Sep 17 00:00:00 2001 From: Tiago Cunha Date: Mon, 12 Oct 2009 00:18:19 +0000 Subject: [PATCH] Sync OpenBSD patchset 381: 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. --- input-keys.c | 10 +++++----- server.c | 10 +++++----- tmux.h | 18 +++++++++++++----- tty-keys.c | 23 ++++++++++++----------- window-choose.c | 16 ++++++++-------- window-copy.c | 16 ++++++++-------- window.c | 18 ++++++++---------- 7 files changed, 59 insertions(+), 52 deletions(-) diff --git a/input-keys.c b/input-keys.c index e8c4804a..a279fdb6 100644 --- a/input-keys.c +++ b/input-keys.c @@ -1,4 +1,4 @@ -/* $Id: input-keys.c,v 1.29 2009-07-28 22:37:02 tcunha Exp $ */ +/* $Id: input-keys.c,v 1.30 2009-10-12 00:18:19 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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/server.c b/server.c index d81506b9..cd855b98 100644 --- a/server.c +++ b/server.c @@ -1,4 +1,4 @@ -/* $Id: server.c,v 1.202 2009-10-12 00:14:44 tcunha Exp $ */ +/* $Id: server.c,v 1.203 2009-10-12 00:18:19 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -883,9 +883,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) { @@ -897,7 +897,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; @@ -925,10 +925,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/tmux.h b/tmux.h index 8a5c09a9..75b8cfc9 100644 --- a/tmux.h +++ b/tmux.h @@ -1,4 +1,4 @@ -/* $Id: tmux.h,v 1.466 2009-10-12 00:12:33 tcunha Exp $ */ +/* $Id: tmux.h,v 1.467 2009-10-12 00:18:19 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -672,13 +672,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 *); }; @@ -949,6 +950,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; @@ -1283,7 +1291,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( @@ -1540,7 +1548,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); @@ -1703,7 +1711,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/tty-keys.c b/tty-keys.c index d6bd5f2e..99ba6b9b 100644 --- a/tty-keys.c +++ b/tty-keys.c @@ -1,4 +1,4 @@ -/* $Id: tty-keys.c,v 1.30 2009-09-20 22:11:27 tcunha Exp $ */ +/* $Id: tty-keys.c,v 1.31 2009-10-12 00:18:19 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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/window-choose.c b/window-choose.c index aa6bc5ea..a2b21df1 100644 --- a/window-choose.c +++ b/window-choose.c @@ -1,4 +1,4 @@ -/* $Id: window-choose.c,v 1.23 2009-09-11 14:13:52 tcunha Exp $ */ +/* $Id: window-choose.c,v 1.24 2009-10-12 00:18:19 tcunha Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott @@ -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/window-copy.c b/window-copy.c index 66273d45..34f587ec 100644 --- a/window-copy.c +++ b/window-copy.c @@ -1,4 +1,4 @@ -/* $Id: window-copy.c,v 1.87 2009-10-06 14:10:10 tcunha Exp $ */ +/* $Id: window-copy.c,v 1.88 2009-10-12 00:18:19 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -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/window.c b/window.c index 39f40053..29960994 100644 --- a/window.c +++ b/window.c @@ -1,4 +1,4 @@ -/* $Id: window.c,v 1.113 2009-10-12 00:04:56 tcunha Exp $ */ +/* $Id: window.c,v 1.114 2009-10-12 00:18:19 tcunha Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott @@ -660,25 +660,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