Store a key event not a mouse event in the shared data.

This commit is contained in:
nicm
2020-04-13 13:42:35 +00:00
parent 53d6b94e8a
commit 77d5b0cc53
11 changed files with 27 additions and 22 deletions

View File

@ -70,7 +70,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
} }
if (args_has(args, 'M')) { if (args_has(args, 'M')) {
if ((wp = cmd_mouse_pane(&shared->mouse, &s, NULL)) == NULL) if ((wp = cmd_mouse_pane(&shared->event.m, &s, NULL)) == NULL)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
if (c == NULL || c->session != s) if (c == NULL || c->session != s)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
@ -87,7 +87,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item)
swp = wp; swp = wp;
if (!window_pane_set_mode(wp, swp, &window_copy_mode, NULL, args)) { if (!window_pane_set_mode(wp, swp, &window_copy_mode, NULL, args)) {
if (args_has(args, 'M')) if (args_has(args, 'M'))
window_copy_start_drag(c, &shared->mouse); window_copy_start_drag(c, &shared->event.m);
} }
if (args_has(args, 'u')) if (args_has(args, 'u'))
window_copy_pageup(wp, 0); window_copy_pageup(wp, 0);

View File

@ -99,9 +99,9 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item,
*px = wp->xoff - ox; *px = wp->xoff - ox;
else else
*px = 0; *px = 0;
} else if (strcmp(xp, "M") == 0 && shared->mouse.valid) { } else if (strcmp(xp, "M") == 0) {
if (shared->mouse.x > w / 2) if (shared->event.m.valid && shared->event.m.x > w / 2)
*px = shared->mouse.x - w / 2; *px = shared->event.m.x - w / 2;
else else
*px = 0; *px = 0;
} else if (strcmp(xp, "W") == 0) { } else if (strcmp(xp, "W") == 0) {
@ -133,9 +133,12 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item,
*py = wp->yoff + wp->sy - oy; *py = wp->yoff + wp->sy - oy;
else else
*py = 0; *py = 0;
} else if (strcmp(yp, "M") == 0 && shared->mouse.valid) } else if (strcmp(yp, "M") == 0) {
*py = shared->mouse.y + h; if (shared->event.m.valid)
else if (strcmp(yp, "S") == 0) { *py = shared->event.m.y + h;
else
*py = 0;
} else if (strcmp(yp, "S") == 0) {
if (options_get_number(s->options, "status-position") == 0) { if (options_get_number(s->options, "status-position") == 0) {
if (lines != 0) if (lines != 0)
*py = lines + h; *py = lines + h;
@ -147,8 +150,7 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item,
else else
*py = c->tty.sy; *py = c->tty.sy;
} }
} } else if (strcmp(yp, "W") == 0) {
else if (strcmp(yp, "W") == 0) {
if (options_get_number(s->options, "status-position") == 0) { if (options_get_number(s->options, "status-position") == 0) {
if (lines != 0) if (lines != 0)
*py = line + 1 + h; *py = line + 1 + h;
@ -228,7 +230,7 @@ cmd_display_menu_exec(struct cmd *self, struct cmdq_item *item)
cmd_display_menu_get_position(c, item, args, &px, &py, menu->width + 4, cmd_display_menu_get_position(c, item, args, &px, &py, menu->width + 4,
menu->count + 2); menu->count + 2);
if (!shared->mouse.valid) if (!shared->event.m.valid)
flags |= MENU_NOMOUSE; flags |= MENU_NOMOUSE;
if (menu_display(menu, flags, item, px, py, c, target, NULL, NULL) != 0) if (menu_display(menu, flags, item, px, py, c, target, NULL, NULL) != 0)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);

View File

@ -982,7 +982,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item,
/* Mouse target is a plain = or {mouse}. */ /* Mouse target is a plain = or {mouse}. */
if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) { if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) {
m = &cmdq_get_shared(item)->mouse; m = &cmdq_get_shared(item)->event.m;
switch (type) { switch (type) {
case CMD_FIND_PANE: case CMD_FIND_PANE:
fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl); fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl);

View File

@ -65,7 +65,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item)
struct args *args = cmd_get_args(self); struct args *args = cmd_get_args(self);
struct cmdq_shared *shared = cmdq_get_shared(item); struct cmdq_shared *shared = cmdq_get_shared(item);
struct cmd_find_state *target = cmdq_get_target(item); struct cmd_find_state *target = cmdq_get_target(item);
struct mouse_event *m = &shared->mouse; struct mouse_event *m = &shared->event.m;
struct cmd_if_shell_data *cdata; struct cmd_if_shell_data *cdata;
char *shellcmd, *cmd; char *shellcmd, *cmd;
const char *file; const char *file;

View File

@ -333,8 +333,11 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current,
cmd_find_copy_state(&shared->current, current); cmd_find_copy_state(&shared->current, current);
else else
cmd_find_clear_state(&shared->current, 0); cmd_find_clear_state(&shared->current, 0);
if (m != NULL) if (m != NULL) {
memcpy(&shared->mouse, m, sizeof shared->mouse); shared->event.key = KEYC_NONE;
memcpy(&shared->event.m, m,
sizeof shared->event.m);
}
shared->flags = flags; shared->flags = flags;
last_group = group; last_group = group;
} }

View File

@ -76,12 +76,12 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item)
} }
if (args_has(args, 'M')) { if (args_has(args, 'M')) {
if (cmd_mouse_window(&shared->mouse, &s) == NULL) if (cmd_mouse_window(&shared->event.m, &s) == NULL)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
if (c == NULL || c->session != s) if (c == NULL || c->session != s)
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
c->tty.mouse_drag_update = cmd_resize_pane_mouse_update; c->tty.mouse_drag_update = cmd_resize_pane_mouse_update;
cmd_resize_pane_mouse_update(c, &shared->mouse); cmd_resize_pane_mouse_update(c, &shared->event.m);
return (CMD_RETURN_NORMAL); return (CMD_RETURN_NORMAL);
} }

View File

@ -140,7 +140,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item)
struct window_pane *wp = target->wp; struct window_pane *wp = target->wp;
struct session *s = target->s; struct session *s = target->s;
struct winlink *wl = target->wl; struct winlink *wl = target->wl;
struct mouse_event *m = &shared->mouse; struct mouse_event *m = &shared->event.m;
struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes); struct window_mode_entry *wme = TAILQ_FIRST(&wp->modes);
int i; int i;
key_code key; key_code key;

View File

@ -1133,7 +1133,7 @@ format_create_add_item(struct format_tree *ft, struct cmdq_item *item)
if (shared == NULL) if (shared == NULL)
return; return;
m = &shared->mouse; m = &shared->event.m;
if (m->valid && ((wp = cmd_mouse_pane(m, NULL, NULL)) != NULL)) { if (m->valid && ((wp = cmd_mouse_pane(m, NULL, NULL)) != NULL)) {
format_add(ft, "mouse_pane", "%%%u", wp->id); format_add(ft, "mouse_pane", "%%%u", wp->id);
if (cmd_mouse_at(wp, m, &x, &y, 0) == 0) { if (cmd_mouse_at(wp, m, &x, &y, 0) == 0) {

2
menu.c
View File

@ -282,7 +282,7 @@ chosen:
break; break;
case CMD_PARSE_SUCCESS: case CMD_PARSE_SUCCESS:
if (md->item != NULL) if (md->item != NULL)
m = &cmdq_get_shared(md->item)->mouse; m = &cmdq_get_shared(md->item)->event.m;
else else
m = NULL; m = NULL;
new_item = cmdq_get_command(pr->cmdlist, &md->fs, m, 0); new_item = cmdq_get_command(pr->cmdlist, &md->fs, m, 0);

View File

@ -305,7 +305,7 @@ popup_key_cb(struct client *c, struct key_event *event)
break; break;
case CMD_PARSE_SUCCESS: case CMD_PARSE_SUCCESS:
if (pd->item != NULL) if (pd->item != NULL)
m = &cmdq_get_shared(pd->item)->mouse; m = &cmdq_get_shared(pd->item)->event.m;
else else
m = NULL; m = NULL;
new_item = cmdq_get_command(pr->cmdlist, fs, m, 0); new_item = cmdq_get_command(pr->cmdlist, fs, m, 0);

2
tmux.h
View File

@ -1389,7 +1389,7 @@ struct cmdq_shared {
struct format_tree *formats; struct format_tree *formats;
struct mouse_event mouse; struct key_event event;
struct cmd_find_state current; struct cmd_find_state current;
}; };