From 1d89233047c68e5f16f302416436fbf478f9f8b2 Mon Sep 17 00:00:00 2001 From: nicm Date: Tue, 25 Nov 2025 20:27:23 +0000 Subject: [PATCH] Add a resize callback for menus so that they are correctly moved on resize. From m-einfalt at gmx dot de in GitHub issue 4696. --- menu.c | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/menu.c b/menu.c index fd3a9fe4..7449d88d 100644 --- a/menu.c +++ b/menu.c @@ -438,6 +438,38 @@ chosen: return (1); } +static void +menu_resize_cb(struct client *c, void *data) +{ + struct menu_data *md = data; + u_int nx, ny, w, h; + + if (md == NULL) + return; + + nx = md->px; + ny = md->py; + + w = md->menu->width + 4; + h = md->menu->count + 2; + + if (nx + w > c->tty.sx) { + if (c->tty.sx <= w) + nx = 0; + else + nx = c->tty.sx - w; + } + + if (ny + h > c->tty.sy) { + if (c->tty.sy <= h) + ny = 0; + else + ny = c->tty.sy - h; + } + md->px = nx; + md->py = ny; +} + static void menu_set_style(struct client *c, struct grid_cell *gc, const char *style, const char *option) @@ -551,6 +583,6 @@ menu_display(struct menu *menu, int flags, int starting_choice, if (md == NULL) return (-1); server_client_set_overlay(c, 0, NULL, menu_mode_cb, menu_draw_cb, - menu_key_cb, menu_free_cb, NULL, md); + menu_key_cb, menu_free_cb, menu_resize_cb, md); return (0); }