From 7d7d7c960593de4c37962ca2d74dbd13e5a3cc2b Mon Sep 17 00:00:00 2001 From: nicm Date: Fri, 13 Aug 2021 23:05:40 +0000 Subject: [PATCH] Tweak how mouse works on popup: only Meta alone resizes or moves, not Meta with other modifiers; button 2 on the left or top border opens menu, right or bottom resizes; button 1 on any border moves. --- popup.c | 27 +++++++++++++++------------ tmux.h | 1 + 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/popup.c b/popup.c index 95de58a9..d4fc3833 100644 --- a/popup.c +++ b/popup.c @@ -442,6 +442,7 @@ popup_key_cb(struct client *c, void *data, struct key_event *event) const char *buf; size_t len; u_int px, py, x; + enum { NONE, LEFT, RIGHT, TOP, BOTTOM } border = NONE; if (pd->md != NULL) { if (menu_key_cb(c, pd->md, event) == 1) { @@ -468,20 +469,22 @@ popup_key_cb(struct client *c, void *data, struct key_event *event) goto menu; return (0); } - if ((~pd->flags & POPUP_NOBORDER) && - (~m->b & MOUSE_MASK_META) && + if (~pd->flags & POPUP_NOBORDER) { + if (m->x == pd->px) + border = LEFT; + else if (m->x == pd->px + pd->sx - 1) + border = RIGHT; + else if (m->y == pd->py) + border = TOP; + else if (m->y == pd->py + pd->sy - 1) + border = BOTTOM; + } + if ((m->b & MOUSE_MASK_MODIFIERS) == 0 && MOUSE_BUTTONS(m->b) == 2 && - (m->x == pd->px || - m->x == pd->px + pd->sx - 1 || - m->y == pd->py || - m->y == pd->py + pd->sy - 1)) + (border == LEFT || border == TOP)) goto menu; - if ((m->b & MOUSE_MASK_META) || - ((~pd->flags & POPUP_NOBORDER) && - (m->x == pd->px || - m->x == pd->px + pd->sx - 1 || - m->y == pd->py || - m->y == pd->py + pd->sy - 1))) { + if (((m->b & MOUSE_MASK_MODIFIERS) == MOUSE_MASK_META) || + border != NONE) { if (!MOUSE_DRAG(m->b)) goto out; if (MOUSE_BUTTONS(m->lb) == 0) diff --git a/tmux.h b/tmux.h index d1ae5e43..e6ba8e86 100644 --- a/tmux.h +++ b/tmux.h @@ -1158,6 +1158,7 @@ RB_HEAD(sessions, session); #define MOUSE_MASK_CTRL 16 #define MOUSE_MASK_DRAG 32 #define MOUSE_MASK_WHEEL 64 +#define MOUSE_MASK_MODIFIERS (MOUSE_MASK_SHIFT|MOUSE_MASK_META|MOUSE_MASK_CTRL) /* Mouse wheel states. */ #define MOUSE_WHEEL_UP 0