Add names for mouse button bits rather than using magic numbers, from

Marcel Partap.
This commit is contained in:
nicm 2014-03-31 21:40:21 +00:00
parent fcdae6925a
commit 46593e7aa2
2 changed files with 15 additions and 7 deletions

12
tmux.h
View File

@ -1128,18 +1128,26 @@ struct tty_term {
}; };
LIST_HEAD(tty_terms, tty_term); LIST_HEAD(tty_terms, tty_term);
/* Mouse button masks. */
#define MOUSE_MASK_BUTTONS 3
#define MOUSE_MASK_SHIFT 4
#define MOUSE_MASK_META 8
#define MOUSE_MASK_CTRL 16
#define MOUSE_MASK_DRAG 32
#define MOUSE_MASK_WHEEL 64
/* Mouse wheel states. */ /* Mouse wheel states. */
#define MOUSE_WHEEL_UP 0 #define MOUSE_WHEEL_UP 0
#define MOUSE_WHEEL_DOWN 1 #define MOUSE_WHEEL_DOWN 1
/* Mouse events. */ /* Mouse event bits. */
#define MOUSE_EVENT_DOWN 0x1 #define MOUSE_EVENT_DOWN 0x1
#define MOUSE_EVENT_DRAG 0x2 #define MOUSE_EVENT_DRAG 0x2
#define MOUSE_EVENT_UP 0x4 #define MOUSE_EVENT_UP 0x4
#define MOUSE_EVENT_CLICK 0x8 #define MOUSE_EVENT_CLICK 0x8
#define MOUSE_EVENT_WHEEL 0x10 #define MOUSE_EVENT_WHEEL 0x10
/* Mouse flags. */ /* Mouse flag bits. */
#define MOUSE_RESIZE_PANE 0x1 #define MOUSE_RESIZE_PANE 0x1
/* /*

View File

@ -748,21 +748,21 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size)
m->sgr_rel = sgr_rel; m->sgr_rel = sgr_rel;
m->x = x; m->x = x;
m->y = y; m->y = y;
if (b & 64) { /* wheel button */ if (b & MOUSE_MASK_WHEEL) {
b &= 3; b &= MOUSE_MASK_BUTTONS;
if (b == 0) if (b == 0)
m->wheel = MOUSE_WHEEL_UP; m->wheel = MOUSE_WHEEL_UP;
else if (b == 1) else if (b == 1)
m->wheel = MOUSE_WHEEL_DOWN; m->wheel = MOUSE_WHEEL_DOWN;
m->event = MOUSE_EVENT_WHEEL; m->event = MOUSE_EVENT_WHEEL;
} else if ((b & 3) == 3) { } else if ((b & MOUSE_MASK_BUTTONS) == 3) {
if (~m->event & MOUSE_EVENT_DRAG && x == m->x && y == m->y) { if (~m->event & MOUSE_EVENT_DRAG && x == m->x && y == m->y) {
m->event = MOUSE_EVENT_CLICK; m->event = MOUSE_EVENT_CLICK;
} else } else
m->event = MOUSE_EVENT_DRAG; m->event = MOUSE_EVENT_DRAG;
m->event |= MOUSE_EVENT_UP; m->event |= MOUSE_EVENT_UP;
} else { } else {
if (b & 32) /* drag motion */ if (b & MOUSE_MASK_DRAG)
m->event = MOUSE_EVENT_DRAG; m->event = MOUSE_EVENT_DRAG;
else { else {
if (m->event & MOUSE_EVENT_UP && x == m->x && y == m->y) if (m->event & MOUSE_EVENT_UP && x == m->x && y == m->y)
@ -773,7 +773,7 @@ tty_keys_mouse(struct tty *tty, const char *buf, size_t len, size_t *size)
m->sy = y; m->sy = y;
m->event = MOUSE_EVENT_DOWN; m->event = MOUSE_EVENT_DOWN;
} }
m->button = (b & 3); m->button = (b & MOUSE_MASK_BUTTONS);
} }
return (0); return (0);