Support mouse in popups.

This commit is contained in:
nicm 2020-04-01 09:05:27 +00:00
parent cd30633d10
commit dd2fdcda79
3 changed files with 48 additions and 21 deletions

View File

@ -257,26 +257,20 @@ input_key(struct window_pane *wp, struct screen *s, struct bufferevent *bev,
return (0);
}
/* Translate mouse and output. */
static void
input_key_mouse(struct window_pane *wp, struct mouse_event *m)
/* Get mouse event string. */
int
input_key_get_mouse(struct screen *s, struct mouse_event *m, u_int x, u_int y,
const char **rbuf, size_t *rlen)
{
struct screen *s = wp->screen;
char buf[40];
static char buf[40];
size_t len;
u_int x, y;
/* Ignore events if no mouse mode or the pane is not visible. */
if (m->ignore || (s->mode & ALL_MOUSE_MODES) == 0)
return;
if (cmd_mouse_at(wp, m, &x, &y, 0) != 0)
return;
if (!window_pane_visible(wp))
return;
*rbuf = NULL;
*rlen = 0;
/* If this pane is not in button or all mode, discard motion events. */
if (MOUSE_DRAG(m->b) && (s->mode & MOTION_MOUSE_MODES) == 0)
return;
return (0);
/*
* If this event is a release event and not in all mode, discard it.
@ -288,13 +282,13 @@ input_key_mouse(struct window_pane *wp, struct mouse_event *m)
if (MOUSE_DRAG(m->sgr_b) &&
MOUSE_BUTTONS(m->sgr_b) == 3 &&
(~s->mode & MODE_MOUSE_ALL))
return;
return (0);
} else {
if (MOUSE_DRAG(m->b) &&
MOUSE_BUTTONS(m->b) == 3 &&
MOUSE_BUTTONS(m->lb) == 3 &&
(~s->mode & MODE_MOUSE_ALL))
return;
return (0);
}
/*
@ -311,19 +305,43 @@ input_key_mouse(struct window_pane *wp, struct mouse_event *m)
m->sgr_b, x + 1, y + 1, m->sgr_type);
} else if (s->mode & MODE_MOUSE_UTF8) {
if (m->b > 0x7ff - 32 || x > 0x7ff - 33 || y > 0x7ff - 33)
return;
return (0);
len = xsnprintf(buf, sizeof buf, "\033[M");
len += input_split2(m->b + 32, &buf[len]);
len += input_split2(x + 33, &buf[len]);
len += input_split2(y + 33, &buf[len]);
} else {
if (m->b > 223)
return;
return (0);
len = xsnprintf(buf, sizeof buf, "\033[M");
buf[len++] = m->b + 32;
buf[len++] = x + 33;
buf[len++] = y + 33;
}
*rbuf = buf;
*rlen = len;
return (1);
}
/* Translate mouse and output. */
static void
input_key_mouse(struct window_pane *wp, struct mouse_event *m)
{
struct screen *s = wp->screen;
u_int x, y;
const char *buf;
size_t len;
/* Ignore events if no mouse mode or the pane is not visible. */
if (m->ignore || (s->mode & ALL_MOUSE_MODES) == 0)
return;
if (cmd_mouse_at(wp, m, &x, &y, 0) != 0)
return;
if (!window_pane_visible(wp))
return;
if (!input_key_get_mouse(s, m, x, y, &buf, &len))
return;
log_debug("writing mouse %.*s to %%%u", (int)len, buf, wp->id);
bufferevent_write(wp->event, buf, len);
}

13
popup.c
View File

@ -225,7 +225,8 @@ popup_key_cb(struct client *c, struct key_event *event)
struct cmdq_item *new_item;
struct cmd_parse_result *pr;
struct format_tree *ft;
const char *cmd;
const char *cmd, *buf;
size_t len;
if (KEYC_IS_MOUSE(event->key)) {
if (pd->dragging != OFF) {
@ -258,14 +259,20 @@ popup_key_cb(struct client *c, struct key_event *event)
}
if (pd->ictx != NULL && (pd->flags & POPUP_WRITEKEYS)) {
if (KEYC_IS_MOUSE(event->key))
return (0);
if (((pd->flags & (POPUP_CLOSEEXIT|POPUP_CLOSEEXITZERO)) == 0 ||
pd->job == NULL) &&
(event->key == '\033' || event->key == '\003'))
return (1);
if (pd->job == NULL)
return (0);
if (KEYC_IS_MOUSE(event->key)) {
/* Must be inside, checked already. */
if (!input_key_get_mouse(&pd->s, m, m->x - pd->px,
m->y - pd->py, &buf, &len))
return (0);
bufferevent_write(job_get_event(pd->job), buf, len);
return (0);
}
input_key(NULL, &pd->s, job_get_event(pd->job), event->key);
return (0);
}

2
tmux.h
View File

@ -2315,6 +2315,8 @@ void input_parse_screen(struct input_ctx *, struct screen *, u_char *,
int input_key_pane(struct window_pane *, key_code, struct mouse_event *);
int input_key(struct window_pane *, struct screen *, struct bufferevent *,
key_code);
int input_key_get_mouse(struct screen *, struct mouse_event *, u_int,
u_int, const char **, size_t *);
/* xterm-keys.c */
char *xterm_keys_lookup(key_code);