From b248dd04a77c2094194e6baa32d89920e4b48150 Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Wed, 13 May 2026 17:02:05 +0200 Subject: [PATCH] Fix findMenu: use bounds checking instead of broken X11 window query findMenu always returned NULL because the refactored code set win=0 then checked 'if (win == None) return NULL'. Replace with geometric bounds checking against mapped menus. This fixes the menu disappearing on button release (closeCascade was called because smenu was NULL). --- src/menu.c | 50 ++++++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/src/menu.c b/src/menu.c index 3c7708f..3e243f7 100644 --- a/src/menu.c +++ b/src/menu.c @@ -1113,25 +1113,43 @@ static void selectEntry(WMenu * menu, int entry_no) static WMenu *findMenu(WScreen * scr, int *x_ret, int *y_ret) { WMenu *menu; - WObjDescriptor *desc; - Window root_ret, win, junk_win; - int x, y, wx, wy; - unsigned int mask; + int x, y; - wm_backend->pointer_get_position(&x, &y); wx = x; wy = y; win = 0; root_ret = scr->root_win; + wm_backend->pointer_get_position(&x, &y); - if (win == None) - return NULL; - - desc = wm_backend->context_find(win, WM_CTX_CLIENT_WIN); - if (!desc) - return NULL; - - if (desc->parent_type == WCLASS_MENU) { - menu = (WMenu *) desc->parent; - *x_ret = wx - menu->frame_x; *y_ret = wy - menu->frame_y; - return menu; + /* Check root menu and its cascades */ + menu = scr->root_menu; + if (menu && menu->flags.mapped) { + if (x >= menu->frame_x && x < menu->frame_x + MENUW(menu) && + y >= menu->frame_y && y < menu->frame_y + MENUH(menu)) { + *x_ret = x - menu->frame_x; + *y_ret = y - menu->frame_y; + return menu; + } + /* Check cascades */ + for (int i = 0; i < menu->cascade_no; i++) { + WMenu *sub = menu->cascades[i]; + if (sub && sub->flags.mapped && + x >= sub->frame_x && x < sub->frame_x + MENUW(sub) && + y >= sub->frame_y && y < sub->frame_y + MENUH(sub)) { + *x_ret = x - sub->frame_x; + *y_ret = y - sub->frame_y; + return sub; + } + } } + + /* Check switch menu */ + menu = scr->switch_menu; + if (menu && menu->flags.mapped) { + if (x >= menu->frame_x && x < menu->frame_x + MENUW(menu) && + y >= menu->frame_y && y < menu->frame_y + MENUH(menu)) { + *x_ret = x - menu->frame_x; + *y_ret = y - menu->frame_y; + return menu; + } + } + return NULL; }