Merge branch 'obsd-master'

This commit is contained in:
Thomas Adam 2020-04-01 12:01:27 +01:00
commit 66db12db31
4 changed files with 87 additions and 26 deletions

View File

@ -256,26 +256,20 @@ input_key(struct window_pane *wp, struct screen *s, struct bufferevent *bev,
return (0); return (0);
} }
/* Translate mouse and output. */ /* Get mouse event string. */
static void int
input_key_mouse(struct window_pane *wp, struct mouse_event *m) 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; static char buf[40];
char buf[40];
size_t len; size_t len;
u_int x, y;
/* Ignore events if no mouse mode or the pane is not visible. */ *rbuf = NULL;
if (m->ignore || (s->mode & ALL_MOUSE_MODES) == 0) *rlen = 0;
return;
if (cmd_mouse_at(wp, m, &x, &y, 0) != 0)
return;
if (!window_pane_visible(wp))
return;
/* If this pane is not in button or all mode, discard motion events. */ /* If this pane is not in button or all mode, discard motion events. */
if (MOUSE_DRAG(m->b) && (s->mode & MOTION_MOUSE_MODES) == 0) 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. * If this event is a release event and not in all mode, discard it.
@ -287,13 +281,13 @@ input_key_mouse(struct window_pane *wp, struct mouse_event *m)
if (MOUSE_DRAG(m->sgr_b) && if (MOUSE_DRAG(m->sgr_b) &&
MOUSE_BUTTONS(m->sgr_b) == 3 && MOUSE_BUTTONS(m->sgr_b) == 3 &&
(~s->mode & MODE_MOUSE_ALL)) (~s->mode & MODE_MOUSE_ALL))
return; return (0);
} else { } else {
if (MOUSE_DRAG(m->b) && if (MOUSE_DRAG(m->b) &&
MOUSE_BUTTONS(m->b) == 3 && MOUSE_BUTTONS(m->b) == 3 &&
MOUSE_BUTTONS(m->lb) == 3 && MOUSE_BUTTONS(m->lb) == 3 &&
(~s->mode & MODE_MOUSE_ALL)) (~s->mode & MODE_MOUSE_ALL))
return; return (0);
} }
/* /*
@ -310,19 +304,43 @@ input_key_mouse(struct window_pane *wp, struct mouse_event *m)
m->sgr_b, x + 1, y + 1, m->sgr_type); m->sgr_b, x + 1, y + 1, m->sgr_type);
} else if (s->mode & MODE_MOUSE_UTF8) { } else if (s->mode & MODE_MOUSE_UTF8) {
if (m->b > 0x7ff - 32 || x > 0x7ff - 33 || y > 0x7ff - 33) if (m->b > 0x7ff - 32 || x > 0x7ff - 33 || y > 0x7ff - 33)
return; return (0);
len = xsnprintf(buf, sizeof buf, "\033[M"); len = xsnprintf(buf, sizeof buf, "\033[M");
len += input_split2(m->b + 32, &buf[len]); len += input_split2(m->b + 32, &buf[len]);
len += input_split2(x + 33, &buf[len]); len += input_split2(x + 33, &buf[len]);
len += input_split2(y + 33, &buf[len]); len += input_split2(y + 33, &buf[len]);
} else { } else {
if (m->b > 223) if (m->b > 223)
return; return (0);
len = xsnprintf(buf, sizeof buf, "\033[M"); len = xsnprintf(buf, sizeof buf, "\033[M");
buf[len++] = m->b + 32; buf[len++] = m->b + 32;
buf[len++] = x + 33; buf[len++] = x + 33;
buf[len++] = y + 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); log_debug("writing mouse %.*s to %%%u", (int)len, buf, wp->id);
bufferevent_write(wp->event, buf, len); 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 cmdq_item *new_item;
struct cmd_parse_result *pr; struct cmd_parse_result *pr;
struct format_tree *ft; struct format_tree *ft;
const char *cmd; const char *cmd, *buf;
size_t len;
if (KEYC_IS_MOUSE(event->key)) { if (KEYC_IS_MOUSE(event->key)) {
if (pd->dragging != OFF) { 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 (pd->ictx != NULL && (pd->flags & POPUP_WRITEKEYS)) {
if (KEYC_IS_MOUSE(event->key))
return (0);
if (((pd->flags & (POPUP_CLOSEEXIT|POPUP_CLOSEEXITZERO)) == 0 || if (((pd->flags & (POPUP_CLOSEEXIT|POPUP_CLOSEEXITZERO)) == 0 ||
pd->job == NULL) && pd->job == NULL) &&
(event->key == '\033' || event->key == '\003')) (event->key == '\033' || event->key == '\003'))
return (1); return (1);
if (pd->job == NULL) if (pd->job == NULL)
return (0); 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); input_key(NULL, &pd->s, job_get_event(pd->job), event->key);
return (0); return (0);
} }

2
tmux.h
View File

@ -2317,6 +2317,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_pane(struct window_pane *, key_code, struct mouse_event *);
int input_key(struct window_pane *, struct screen *, struct bufferevent *, int input_key(struct window_pane *, struct screen *, struct bufferevent *,
key_code); key_code);
int input_key_get_mouse(struct screen *, struct mouse_event *, u_int,
u_int, const char **, size_t *);
/* xterm-keys.c */ /* xterm-keys.c */
char *xterm_keys_lookup(key_code); char *xterm_keys_lookup(key_code);

View File

@ -261,6 +261,9 @@ struct window_copy_mode_data {
int searchy; int searchy;
int searcho; int searcho;
int timeout; /* search has timed out */
#define WINDOW_COPY_SEARCH_TIMEOUT 10
int jumptype; int jumptype;
char jumpchar; char jumpchar;
@ -316,6 +319,7 @@ window_copy_common_init(struct window_mode_entry *wme)
} }
data->searchmark = NULL; data->searchmark = NULL;
data->searchx = data->searchy = data->searcho = -1; data->searchx = data->searchy = data->searcho = -1;
data->timeout = 0;
data->jumptype = WINDOW_COPY_OFF; data->jumptype = WINDOW_COPY_OFF;
data->jumpchar = '\0'; data->jumpchar = '\0';
@ -680,8 +684,8 @@ window_copy_resize(struct window_mode_entry *wme, u_int sx, u_int sy)
window_copy_write_lines(wme, &ctx, 0, screen_size_y(s) - 1); window_copy_write_lines(wme, &ctx, 0, screen_size_y(s) - 1);
screen_write_stop(&ctx); screen_write_stop(&ctx);
if (search) if (search && !data->timeout)
window_copy_search_marks(wme, NULL, 1); window_copy_search_marks(wme, NULL, data->searchregex);
data->searchx = data->cx; data->searchx = data->cx;
data->searchy = data->cy; data->searchy = data->cy;
data->searcho = data->oy; data->searcho = data->oy;
@ -1800,6 +1804,7 @@ window_copy_cmd_search_backward(struct window_copy_cmd_state *cs)
if (data->searchstr != NULL) { if (data->searchstr != NULL) {
data->searchtype = WINDOW_COPY_SEARCHUP; data->searchtype = WINDOW_COPY_SEARCHUP;
data->searchregex = 1; data->searchregex = 1;
data->timeout = 0;
for (; np != 0; np--) for (; np != 0; np--)
window_copy_search_up(wme, 1); window_copy_search_up(wme, 1);
} }
@ -1819,6 +1824,7 @@ window_copy_cmd_search_backward_text(struct window_copy_cmd_state *cs)
if (data->searchstr != NULL) { if (data->searchstr != NULL) {
data->searchtype = WINDOW_COPY_SEARCHUP; data->searchtype = WINDOW_COPY_SEARCHUP;
data->searchregex = 0; data->searchregex = 0;
data->timeout = 0;
for (; np != 0; np--) for (; np != 0; np--)
window_copy_search_up(wme, 0); window_copy_search_up(wme, 0);
} }
@ -1838,6 +1844,7 @@ window_copy_cmd_search_forward(struct window_copy_cmd_state *cs)
if (data->searchstr != NULL) { if (data->searchstr != NULL) {
data->searchtype = WINDOW_COPY_SEARCHDOWN; data->searchtype = WINDOW_COPY_SEARCHDOWN;
data->searchregex = 1; data->searchregex = 1;
data->timeout = 0;
for (; np != 0; np--) for (; np != 0; np--)
window_copy_search_down(wme, 1); window_copy_search_down(wme, 1);
} }
@ -1857,6 +1864,7 @@ window_copy_cmd_search_forward_text(struct window_copy_cmd_state *cs)
if (data->searchstr != NULL) { if (data->searchstr != NULL) {
data->searchtype = WINDOW_COPY_SEARCHDOWN; data->searchtype = WINDOW_COPY_SEARCHDOWN;
data->searchregex = 0; data->searchregex = 0;
data->timeout = 0;
for (; np != 0; np--) for (; np != 0; np--)
window_copy_search_down(wme, 0); window_copy_search_down(wme, 0);
} }
@ -1873,6 +1881,8 @@ window_copy_cmd_search_backward_incremental(struct window_copy_cmd_state *cs)
char prefix; char prefix;
enum window_copy_cmd_action action = WINDOW_COPY_CMD_NOTHING; enum window_copy_cmd_action action = WINDOW_COPY_CMD_NOTHING;
data->timeout = 0;
prefix = *argument++; prefix = *argument++;
if (data->searchx == -1 || data->searchy == -1) { if (data->searchx == -1 || data->searchy == -1) {
data->searchx = data->cx; data->searchx = data->cx;
@ -1924,6 +1934,8 @@ window_copy_cmd_search_forward_incremental(struct window_copy_cmd_state *cs)
char prefix; char prefix;
enum window_copy_cmd_action action = WINDOW_COPY_CMD_NOTHING; enum window_copy_cmd_action action = WINDOW_COPY_CMD_NOTHING;
data->timeout = 0;
prefix = *argument++; prefix = *argument++;
if (data->searchx == -1 || data->searchy == -1) { if (data->searchx == -1 || data->searchy == -1) {
data->searchx = data->cx; data->searchx = data->cx;
@ -2721,6 +2733,9 @@ window_copy_search(struct window_mode_entry *wme, int direction, int regex)
if (regex && str[strcspn(str, "^$*+()?[].\\")] == '\0') if (regex && str[strcspn(str, "^$*+()?[].\\")] == '\0')
regex = 0; regex = 0;
if (data->timeout)
return (0);
free(wp->searchstr); free(wp->searchstr);
wp->searchstr = xstrdup(str); wp->searchstr = xstrdup(str);
wp->searchregex = regex; wp->searchregex = regex;
@ -2768,6 +2783,7 @@ window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,
u_int ssize = 1; u_int ssize = 1;
char *sbuf; char *sbuf;
regex_t reg; regex_t reg;
time_t tstart, t;
if (ssp == NULL) { if (ssp == NULL) {
width = screen_write_strlen("%s", data->searchstr); width = screen_write_strlen("%s", data->searchstr);
@ -2797,6 +2813,7 @@ window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,
return (0); return (0);
} }
} }
time(&tstart);
for (py = 0; py < gd->hsize + gd->sy; py++) { for (py = 0; py < gd->hsize + gd->sy; py++) {
px = 0; px = 0;
for (;;) { for (;;) {
@ -2822,11 +2839,21 @@ window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,
px++; px++;
} }
time(&t);
if (t - tstart > WINDOW_COPY_SEARCH_TIMEOUT) {
data->timeout = 1;
break;
}
} }
if (regex) { if (regex) {
free(sbuf); free(sbuf);
regfree(&reg); regfree(&reg);
} }
if (data->timeout) {
window_copy_clear_marks(wme);
return (1);
}
if (which != -1) if (which != -1)
data->searchthis = 1 + nfound - which; data->searchthis = 1 + nfound - which;
@ -2836,7 +2863,7 @@ window_copy_search_marks(struct window_mode_entry *wme, struct screen *ssp,
if (ssp == &ss) if (ssp == &ss)
screen_free(&ss); screen_free(&ss);
return (nfound); return (1);
} }
static void static void
@ -2895,8 +2922,15 @@ window_copy_write_line(struct window_mode_entry *wme,
if (py == 0 && s->rupper < s->rlower && !data->hide_position) { if (py == 0 && s->rupper < s->rlower && !data->hide_position) {
if (data->searchmark == NULL) { if (data->searchmark == NULL) {
size = xsnprintf(hdr, sizeof hdr, if (data->timeout) {
"[%u/%u]", data->oy, screen_hsize(data->backing)); size = xsnprintf(hdr, sizeof hdr,
"(timed out) [%u/%u]", data->oy,
screen_hsize(data->backing));
} else {
size = xsnprintf(hdr, sizeof hdr,
"[%u/%u]", data->oy,
screen_hsize(data->backing));
}
} else { } else {
if (data->searchthis == -1) { if (data->searchthis == -1) {
size = xsnprintf(hdr, sizeof hdr, size = xsnprintf(hdr, sizeof hdr,