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).
This commit is contained in:
Levi Neely 2026-05-13 17:02:05 +02:00
parent 1905fdf08a
commit b248dd04a7
1 changed files with 34 additions and 16 deletions

View File

@ -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;
}