diff options
author | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-03-12 13:16:17 +0000 |
---|---|---|
committer | Nicholas Marriott <nicm@cvs.openbsd.org> | 2020-03-12 13:16:17 +0000 |
commit | 2a915ab1976251f0c3c7d57f865ecc655c60b585 (patch) | |
tree | ce1bf1042cde3a29877cd73f61e7046b48f8632b /usr.bin/tmux | |
parent | ff8468eca3beeac226b27831e0215a1f4266555f (diff) |
Change how double and triple clicks works so that one or the other is
fired - a double click is no longer triggered on the way to a triple
click.
Diffstat (limited to 'usr.bin/tmux')
-rw-r--r-- | usr.bin/tmux/server-client.c | 37 | ||||
-rw-r--r-- | usr.bin/tmux/tmux.h | 4 |
2 files changed, 29 insertions, 12 deletions
diff --git a/usr.bin/tmux/server-client.c b/usr.bin/tmux/server-client.c index c4ea4b85f4e..0af65b60ac5 100644 --- a/usr.bin/tmux/server-client.c +++ b/usr.bin/tmux/server-client.c @@ -1,4 +1,4 @@ -/* $OpenBSD: server-client.c,v 1.305 2020/02/19 14:25:00 nicm Exp $ */ +/* $OpenBSD: server-client.c,v 1.306 2020/03/12 13:16:16 nicm Exp $ */ /* * Copyright (c) 2009 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -419,7 +419,6 @@ server_client_check_mouse(struct client *c, struct key_event *event) struct winlink *wl; struct window_pane *wp; u_int x, y, b, sx, sy, px, py; - int flag; key_code key; struct timeval tv; struct style_range *sr; @@ -443,7 +442,11 @@ server_client_check_mouse(struct client *c, struct key_event *event) m->x, m->y, m->lx, m->ly, c->tty.mouse_drag_flag); /* What type of event is this? */ - if ((m->sgr_type != ' ' && + if (event->key == KEYC_DOUBLECLICK) { + type = DOUBLE; + x = m->x, y = m->y, b = m->b; + log_debug("double-click at %u,%u", x, y); + } else if ((m->sgr_type != ' ' && MOUSE_DRAG(m->sgr_b) && MOUSE_BUTTONS(m->sgr_b) == 3) || (m->sgr_type == ' ' && @@ -477,10 +480,8 @@ server_client_check_mouse(struct client *c, struct key_event *event) evtimer_del(&c->click_timer); c->flags &= ~CLIENT_DOUBLECLICK; if (m->b == c->click_button) { - type = DOUBLE; - x = m->x, y = m->y, b = m->b; - log_debug("double-click at %u,%u", x, y); - flag = CLIENT_TRIPLECLICK; + type = NOTYPE; + c->flags |= CLIENT_TRIPLECLICK; goto add_timer; } } else if (c->flags & CLIENT_TRIPLECLICK) { @@ -497,11 +498,11 @@ server_client_check_mouse(struct client *c, struct key_event *event) type = DOWN; x = m->x, y = m->y, b = m->b; log_debug("down at %u,%u", x, y); - flag = CLIENT_DOUBLECLICK; + c->flags |= CLIENT_DOUBLECLICK; add_timer: if (KEYC_CLICK_TIMEOUT != 0) { - c->flags |= flag; + memcpy(&c->click_event, m, sizeof c->click_event); c->click_button = m->b; tv.tv_sec = KEYC_CLICK_TIMEOUT / 1000; @@ -1047,7 +1048,7 @@ server_client_key_callback(struct cmdq_item *item, void *data) /* Check for mouse keys. */ m->valid = 0; - if (key == KEYC_MOUSE) { + if (key == KEYC_MOUSE || key == KEYC_DOUBLECLICK) { if (c->flags & CLIENT_READONLY) goto out; key = server_client_check_mouse(c, event); @@ -1549,8 +1550,22 @@ server_client_repeat_timer(__unused int fd, __unused short events, void *data) static void server_client_click_timer(__unused int fd, __unused short events, void *data) { - struct client *c = data; + struct client *c = data; + struct key_event *event; + + log_debug("click timer expired"); + if (c->flags & CLIENT_TRIPLECLICK) { + /* + * Waiting for a third click that hasn't happened, so this must + * have been a double click. + */ + event = xmalloc(sizeof *event); + event->key = KEYC_DOUBLECLICK; + memcpy(&event->m, &c->click_event, sizeof event->m); + if (!server_client_handle_key(c, event)) + free(event); + } c->flags &= ~(CLIENT_DOUBLECLICK|CLIENT_TRIPLECLICK); } diff --git a/usr.bin/tmux/tmux.h b/usr.bin/tmux/tmux.h index fdc88ee11c0..2213fa0387c 100644 --- a/usr.bin/tmux/tmux.h +++ b/usr.bin/tmux/tmux.h @@ -1,4 +1,4 @@ -/* $OpenBSD: tmux.h,v 1.956 2020/03/12 09:26:34 nicm Exp $ */ +/* $OpenBSD: tmux.h,v 1.957 2020/03/12 13:16:16 nicm Exp $ */ /* * Copyright (c) 2007 Nicholas Marriott <nicholas.marriott@gmail.com> @@ -166,6 +166,7 @@ enum { /* Mouse keys. */ KEYC_MOUSE, /* unclassified mouse event */ KEYC_DRAGGING, /* dragging in progress */ + KEYC_DOUBLECLICK, /* double click complete */ KEYC_MOUSE_KEY(MOUSEMOVE), KEYC_MOUSE_KEY(MOUSEDOWN1), KEYC_MOUSE_KEY(MOUSEDOWN2), @@ -1547,6 +1548,7 @@ struct client { struct event click_timer; u_int click_button; + struct mouse_event click_event; struct status_line status; |