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.
pull/1/head
Nicholas Marriott 2009-10-11 07:01:10 +00:00
parent f68ade7b1d
commit 4bc0f6e7e9
7 changed files with 52 additions and 45 deletions

View File

@ -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);
}
}

View File

@ -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;
}

16
tmux.h
View File

@ -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 *);

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}

View File

@ -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