Use current window for opening menus from mouse so they do not appear to

be hidden when opened from status line.
This commit is contained in:
nicm
2026-10-15 22:16:32 +00:00
committed by tmux update bot
parent 4ab3dcac79
commit 330876a0a9
2 changed files with 39 additions and 22 deletions

View File

@@ -1,4 +1,4 @@
/* $OpenBSD: cmd-display-menu.c,v 1.56 2026/10/09 13:12:14 nicm Exp $ */ /* $OpenBSD: cmd-display-menu.c,v 1.57 2026/10/15 22:16:32 nicm Exp $ */
/* /*
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com> * Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -94,6 +94,30 @@ cmd_display_menu_args_parse(struct args *args, u_int idx, __unused char **cause)
return (type); return (type);
} }
static void
cmd_display_menu_set_mouse_pos(struct client *tc, struct mouse_event *m,
struct format_tree *ft, long *mouse_x, long *mouse_y)
{
u_int ox, oy, sx, sy;
if (!m->valid)
return;
tty_window_offset(&tc->tty, &ox, &oy, &sx, &sy);
*mouse_x = m->x + ox;
if (m->statusat == 0) {
if (m->y >= m->statuslines)
*mouse_y = m->y - m->statuslines + oy;
else
*mouse_y = oy;
} else if (m->statusat > 0 && m->y >= (u_int)m->statusat)
*mouse_y = oy + sy - 1;
else
*mouse_y = m->y + oy;
format_add(ft, "popup_mouse_x", "%ld", *mouse_x);
format_add(ft, "popup_mouse_y", "%ld", *mouse_y);
}
static int static int
cmd_display_menu_get_menu_pos(struct client *tc, struct cmdq_item *item, cmd_display_menu_get_menu_pos(struct client *tc, struct cmdq_item *item,
struct args *args, u_int *px, u_int *py, u_int w, u_int h) struct args *args, u_int *px, u_int *py, u_int w, u_int h)
@@ -112,27 +136,15 @@ cmd_display_menu_get_menu_pos(struct client *tc, struct cmdq_item *item,
long n, max_x, max_y, mouse_x = 0, mouse_y = 0; long n, max_x, max_y, mouse_x = 0, mouse_y = 0;
struct format_tree *ft; struct format_tree *ft;
if (event->m.valid)
window = tc->session->curw->window;
max_x = window->sx > w ? window->sx - w : 0; max_x = window->sx > w ? window->sx - w : 0;
max_y = window->sy > h ? window->sy - h : 0; max_y = window->sy > h ? window->sy - h : 0;
tty_window_offset(&tc->tty, &ox, &oy, &sx, &sy); tty_window_offset(&tc->tty, &ox, &oy, &sx, &sy);
ft = format_create_from_target(item); ft = format_create_from_target(item);
if (event->m.valid) { cmd_display_menu_set_mouse_pos(tc, &event->m, ft, &mouse_x, &mouse_y);
mouse_x = event->m.x + ox;
if (event->m.statusat == 0) {
if (event->m.y >= event->m.statuslines)
mouse_y = event->m.y - event->m.statuslines + oy;
else
mouse_y = oy;
} else if (event->m.statusat > 0 &&
event->m.y >= (u_int)event->m.statusat) {
mouse_y = oy + sy - 1;
} else
mouse_y = event->m.y + oy;
format_add(ft, "popup_mouse_x", "%ld", mouse_x);
format_add(ft, "popup_mouse_y", "%ld", mouse_y);
}
format_add(ft, "popup_last_x", "%u", window->menu_last_px); format_add(ft, "popup_last_x", "%u", window->menu_last_px);
format_add(ft, "popup_last_y", "%u", window->menu_last_py + h); format_add(ft, "popup_last_y", "%u", window->menu_last_py + h);

15
menu.c
View File

@@ -1,4 +1,4 @@
/* $OpenBSD: menu.c,v 1.72 2026/10/12 10:46:12 nicm Exp $ */ /* $OpenBSD: menu.c,v 1.73 2026/10/15 22:16:32 nicm Exp $ */
/* /*
* Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com> * Copyright (c) 2019 Nicholas Marriott <nicholas.marriott@gmail.com>
@@ -205,6 +205,7 @@ menu_reapply_styles(struct menu_data *md)
s = md->fs.s; s = md->fs.s;
wl = md->fs.wl; wl = md->fs.wl;
wp = md->fs.wp; wp = md->fs.wp;
o = md->fs.w->options;
} }
ft = format_create_defaults(NULL, NULL, s, wl, wp); ft = format_create_defaults(NULL, NULL, s, wl, wp);
@@ -606,17 +607,22 @@ menu_display(struct menu *menu, int flags, int starting_choice,
void *data) void *data)
{ {
struct menu_data *md; struct menu_data *md;
struct key_event *event; struct key_event *event = NULL;
int choice; int choice;
const char *name; const char *name;
u_int sx, sy; u_int sx, sy;
struct window *w; struct window *w;
struct options *o; struct options *o;
if (fs == NULL) if (item != NULL)
event = cmdq_get_event(item);
if (fs == NULL || (event != NULL && event->m.valid))
w = c->session->curw->window; w = c->session->curw->window;
else else
w = fs->w; w = fs->w;
if (fs != NULL)
o = fs->w->options;
else
o = w->options; o = w->options;
if (lines == BOX_LINES_DEFAULT) if (lines == BOX_LINES_DEFAULT)
@@ -639,8 +645,7 @@ menu_display(struct menu *menu, int flags, int starting_choice,
md->border_lines = lines; md->border_lines = lines;
md->key = KEYC_NONE; md->key = KEYC_NONE;
if (item != NULL) { if (event != NULL) {
event = cmdq_get_event(item);
md->key = event->key; md->key = event->key;
memcpy(&md->m, &event->m, sizeof md->m); memcpy(&md->m, &event->m, sizeof md->m);
} }