diff options
author | nicm <nicm> | 2017-02-01 09:55:07 +0000 |
---|---|---|
committer | nicm <nicm> | 2017-02-01 09:55:07 +0000 |
commit | dd0c8147795c518de443c33895c614e52b42677f (patch) | |
tree | 2260ebc6d5ff2559ac2fd6156add15cc580407a3 /input-keys.c | |
parent | 3408595f77920764bf6c4c313a0abc6a1cfb8048 (diff) | |
download | rtmux-dd0c8147795c518de443c33895c614e52b42677f.tar.gz rtmux-dd0c8147795c518de443c33895c614e52b42677f.tar.bz2 rtmux-dd0c8147795c518de443c33895c614e52b42677f.zip |
Implement "all event" (1003) mouse mode but in a way that works. The
main issue is that if we have two panes, A with 1002 and B with 1003, we
need to set 1003 outside tmux in order to get all the mouse events, but
then we need to suppress the ones that pane A doesn't want. This is easy
in SGR mouse mode, because buttons == 3 is only used for movement events
(for other events the trailing m/M marks a release instead), but in
normal mouse mode we can't tell so easily. So for that, look at the
previous event instead - if it is drag+release as well, then the current
event is a movement event.
Diffstat (limited to 'input-keys.c')
-rw-r--r-- | input-keys.c | 40 |
1 files changed, 31 insertions, 9 deletions
diff --git a/input-keys.c b/input-keys.c index 767c5ca9..eb2879a9 100644 --- a/input-keys.c +++ b/input-keys.c @@ -235,20 +235,42 @@ input_key(struct window_pane *wp, key_code key, struct mouse_event *m) static void input_key_mouse(struct window_pane *wp, struct mouse_event *m) { - char buf[40]; - size_t len; - u_int x, y; + struct screen *s = wp->screen; + int mode = s->mode; + char buf[40]; + size_t len; + u_int x, y; - if ((wp->screen->mode & ALL_MOUSE_MODES) == 0) + if ((mode & ALL_MOUSE_MODES) == 0) return; if (!window_pane_visible(wp)) return; if (cmd_mouse_at(wp, m, &x, &y, 0) != 0) return; - /* If this pane is not in button mode, discard motion events. */ - if (!(wp->screen->mode & MODE_MOUSE_BUTTON) && (m->b & MOUSE_MASK_DRAG)) - return; + /* If this pane is not in button or all mode, discard motion events. */ + if (MOUSE_DRAG(m->b) && + (mode & (MODE_MOUSE_BUTTON|MODE_MOUSE_ALL)) == 0) + return; + + /* + * If this event is a release event and not in all mode, discard it. + * In SGR mode we can tell absolutely because a release is normally + * shown by the last character. Without SGR, we check if the last + * buttons was also a release. + */ + if (m->sgr_type != ' ') { + if (MOUSE_DRAG(m->sgr_b) && + MOUSE_BUTTONS(m->sgr_b) == 3 && + (~mode & MODE_MOUSE_ALL)) + return; + } else { + if (MOUSE_DRAG(m->b) && + MOUSE_BUTTONS(m->b) == 3 && + MOUSE_BUTTONS(m->lb) == 3 && + (~mode & MODE_MOUSE_ALL)) + return; + } /* * Use the SGR (1006) extension only if the application requested it @@ -259,10 +281,10 @@ input_key_mouse(struct window_pane *wp, struct mouse_event *m) * UTF-8 (1005) extension if the application requested, or to the * legacy format. */ - if (m->sgr_type != ' ' && (wp->screen->mode & MODE_MOUSE_SGR)) { + if (m->sgr_type != ' ' && (s->mode & MODE_MOUSE_SGR)) { len = xsnprintf(buf, sizeof buf, "\033[<%u;%u;%u%c", m->sgr_b, x + 1, y + 1, m->sgr_type); - } else if (wp->screen->mode & MODE_MOUSE_UTF8) { + } else if (s->mode & MODE_MOUSE_UTF8) { if (m->b > 0x7ff - 32 || x > 0x7ff - 33 || y > 0x7ff - 33) return; len = xsnprintf(buf, sizeof buf, "\033[M"); |