From 330876a0a917101fc997fcf7d68697f9896093ff Mon Sep 17 00:00:00 2001 From: nicm Date: Thu, 15 Oct 2026 22:16:32 +0000 Subject: [PATCH] Use current window for opening menus from mouse so they do not appear to be hidden when opened from status line. --- cmd-display-menu.c | 44 ++++++++++++++++++++++++++++---------------- menu.c | 17 +++++++++++------ 2 files changed, 39 insertions(+), 22 deletions(-) diff --git a/cmd-display-menu.c b/cmd-display-menu.c index 83e0da934..83f49456e 100644 --- a/cmd-display-menu.c +++ b/cmd-display-menu.c @@ -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 @@ -94,6 +94,30 @@ cmd_display_menu_args_parse(struct args *args, u_int idx, __unused char **cause) 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 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) @@ -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; struct format_tree *ft; + if (event->m.valid) + window = tc->session->curw->window; max_x = window->sx > w ? window->sx - w : 0; max_y = window->sy > h ? window->sy - h : 0; tty_window_offset(&tc->tty, &ox, &oy, &sx, &sy); ft = format_create_from_target(item); - if (event->m.valid) { - 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); - } + cmd_display_menu_set_mouse_pos(tc, &event->m, ft, &mouse_x, &mouse_y); format_add(ft, "popup_last_x", "%u", window->menu_last_px); format_add(ft, "popup_last_y", "%u", window->menu_last_py + h); diff --git a/menu.c b/menu.c index b7917fa72..9ca381fce 100644 --- a/menu.c +++ b/menu.c @@ -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 @@ -205,6 +205,7 @@ menu_reapply_styles(struct menu_data *md) s = md->fs.s; wl = md->fs.wl; wp = md->fs.wp; + o = md->fs.w->options; } ft = format_create_defaults(NULL, NULL, s, wl, wp); @@ -606,18 +607,23 @@ menu_display(struct menu *menu, int flags, int starting_choice, void *data) { struct menu_data *md; - struct key_event *event; + struct key_event *event = NULL; int choice; const char *name; u_int sx, sy; struct window *w; 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; else w = fs->w; - o = w->options; + if (fs != NULL) + o = fs->w->options; + else + o = w->options; if (lines == BOX_LINES_DEFAULT) lines = options_get_number(o, "menu-border-lines"); @@ -639,8 +645,7 @@ menu_display(struct menu *menu, int flags, int starting_choice, md->border_lines = lines; md->key = KEYC_NONE; - if (item != NULL) { - event = cmdq_get_event(item); + if (event != NULL) { md->key = event->key; memcpy(&md->m, &event->m, sizeof md->m); }