From 77d5b0cc538138fd036dca0f9b2ba198a94c009d Mon Sep 17 00:00:00 2001 From: nicm Date: Mon, 13 Apr 2020 13:42:35 +0000 Subject: [PATCH] Store a key event not a mouse event in the shared data. --- cmd-copy-mode.c | 4 ++-- cmd-display-menu.c | 20 +++++++++++--------- cmd-find.c | 2 +- cmd-if-shell.c | 2 +- cmd-queue.c | 7 +++++-- cmd-resize-pane.c | 4 ++-- cmd-send-keys.c | 2 +- format.c | 2 +- menu.c | 2 +- popup.c | 2 +- tmux.h | 2 +- 11 files changed, 27 insertions(+), 22 deletions(-) diff --git a/cmd-copy-mode.c b/cmd-copy-mode.c index d5e132f9..2fa6ae2e 100644 --- a/cmd-copy-mode.c +++ b/cmd-copy-mode.c @@ -70,7 +70,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item) } 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); if (c == NULL || c->session != s) return (CMD_RETURN_NORMAL); @@ -87,7 +87,7 @@ cmd_copy_mode_exec(struct cmd *self, struct cmdq_item *item) swp = wp; if (!window_pane_set_mode(wp, swp, &window_copy_mode, NULL, args)) { 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')) window_copy_pageup(wp, 0); diff --git a/cmd-display-menu.c b/cmd-display-menu.c index ada3ef23..ff9276d3 100644 --- a/cmd-display-menu.c +++ b/cmd-display-menu.c @@ -99,9 +99,9 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, *px = wp->xoff - ox; else *px = 0; - } else if (strcmp(xp, "M") == 0 && shared->mouse.valid) { - if (shared->mouse.x > w / 2) - *px = shared->mouse.x - w / 2; + } else if (strcmp(xp, "M") == 0) { + if (shared->event.m.valid && shared->event.m.x > w / 2) + *px = shared->event.m.x - w / 2; else *px = 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; else *py = 0; - } else if (strcmp(yp, "M") == 0 && shared->mouse.valid) - *py = shared->mouse.y + h; - else if (strcmp(yp, "S") == 0) { + } else if (strcmp(yp, "M") == 0) { + if (shared->event.m.valid) + *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 (lines != 0) *py = lines + h; @@ -147,8 +150,7 @@ cmd_display_menu_get_position(struct client *c, struct cmdq_item *item, else *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 (lines != 0) *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, menu->count + 2); - if (!shared->mouse.valid) + if (!shared->event.m.valid) flags |= MENU_NOMOUSE; if (menu_display(menu, flags, item, px, py, c, target, NULL, NULL) != 0) return (CMD_RETURN_NORMAL); diff --git a/cmd-find.c b/cmd-find.c index a258a10f..665f8eb5 100644 --- a/cmd-find.c +++ b/cmd-find.c @@ -982,7 +982,7 @@ cmd_find_target(struct cmd_find_state *fs, struct cmdq_item *item, /* Mouse target is a plain = or {mouse}. */ if (strcmp(target, "=") == 0 || strcmp(target, "{mouse}") == 0) { - m = &cmdq_get_shared(item)->mouse; + m = &cmdq_get_shared(item)->event.m; switch (type) { case CMD_FIND_PANE: fs->wp = cmd_mouse_pane(m, &fs->s, &fs->wl); diff --git a/cmd-if-shell.c b/cmd-if-shell.c index a385f9f7..ee056520 100644 --- a/cmd-if-shell.c +++ b/cmd-if-shell.c @@ -65,7 +65,7 @@ cmd_if_shell_exec(struct cmd *self, struct cmdq_item *item) struct args *args = cmd_get_args(self); struct cmdq_shared *shared = cmdq_get_shared(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; char *shellcmd, *cmd; const char *file; diff --git a/cmd-queue.c b/cmd-queue.c index aecb7734..7e1788cc 100644 --- a/cmd-queue.c +++ b/cmd-queue.c @@ -333,8 +333,11 @@ cmdq_get_command(struct cmd_list *cmdlist, struct cmd_find_state *current, cmd_find_copy_state(&shared->current, current); else cmd_find_clear_state(&shared->current, 0); - if (m != NULL) - memcpy(&shared->mouse, m, sizeof shared->mouse); + if (m != NULL) { + shared->event.key = KEYC_NONE; + memcpy(&shared->event.m, m, + sizeof shared->event.m); + } shared->flags = flags; last_group = group; } diff --git a/cmd-resize-pane.c b/cmd-resize-pane.c index 0579616a..cd68fd4a 100644 --- a/cmd-resize-pane.c +++ b/cmd-resize-pane.c @@ -76,12 +76,12 @@ cmd_resize_pane_exec(struct cmd *self, struct cmdq_item *item) } 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); if (c == NULL || c->session != s) return (CMD_RETURN_NORMAL); 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); } diff --git a/cmd-send-keys.c b/cmd-send-keys.c index 384cb460..7c73a995 100644 --- a/cmd-send-keys.c +++ b/cmd-send-keys.c @@ -140,7 +140,7 @@ cmd_send_keys_exec(struct cmd *self, struct cmdq_item *item) struct window_pane *wp = target->wp; struct session *s = target->s; 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); int i; key_code key; diff --git a/format.c b/format.c index 3b361e00..e29c17af 100644 --- a/format.c +++ b/format.c @@ -1133,7 +1133,7 @@ format_create_add_item(struct format_tree *ft, struct cmdq_item *item) if (shared == NULL) return; - m = &shared->mouse; + m = &shared->event.m; if (m->valid && ((wp = cmd_mouse_pane(m, NULL, NULL)) != NULL)) { format_add(ft, "mouse_pane", "%%%u", wp->id); if (cmd_mouse_at(wp, m, &x, &y, 0) == 0) { diff --git a/menu.c b/menu.c index e38b5fa5..87b4782b 100644 --- a/menu.c +++ b/menu.c @@ -282,7 +282,7 @@ chosen: break; case CMD_PARSE_SUCCESS: if (md->item != NULL) - m = &cmdq_get_shared(md->item)->mouse; + m = &cmdq_get_shared(md->item)->event.m; else m = NULL; new_item = cmdq_get_command(pr->cmdlist, &md->fs, m, 0); diff --git a/popup.c b/popup.c index 91246538..66c71741 100644 --- a/popup.c +++ b/popup.c @@ -305,7 +305,7 @@ popup_key_cb(struct client *c, struct key_event *event) break; case CMD_PARSE_SUCCESS: if (pd->item != NULL) - m = &cmdq_get_shared(pd->item)->mouse; + m = &cmdq_get_shared(pd->item)->event.m; else m = NULL; new_item = cmdq_get_command(pr->cmdlist, fs, m, 0); diff --git a/tmux.h b/tmux.h index 88cf16d8..fc10d880 100644 --- a/tmux.h +++ b/tmux.h @@ -1389,7 +1389,7 @@ struct cmdq_shared { struct format_tree *formats; - struct mouse_event mouse; + struct key_event event; struct cmd_find_state current; };