From d2c9a59344b6207775895f823785719e11b8d063 Mon Sep 17 00:00:00 2001 From: lkn Date: Sun, 7 Jun 2026 13:08:21 +0200 Subject: [PATCH] popUpMenu: init highlight from pointer position on open, not selectedItemIndex When the popup opens via ButtonPress on the main button, compute the highlighted item from the pointer position relative to the menu view, matching upstream WINGs semantics. Previously highlightedItem was set to selectedItemIndex, which might be -1 (no prior selection), causing the popup to open with no visible highlight until the first motion event. The fix uses event->u.button.y_root - menuView->pos.y divided by item height to determine which item the pointer is over when the menu appears. This item is painted as highlighted immediately on open. --- WINGs/wpopupbutton.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/WINGs/wpopupbutton.c b/WINGs/wpopupbutton.c index 8140131..01e210f 100644 --- a/WINGs/wpopupbutton.c +++ b/WINGs/wpopupbutton.c @@ -685,8 +685,20 @@ static void handleActionEvents(WMEvent * event, void *data) } else { popUpMenu(bPtr); if (!bPtr->flags.pullsDown) { - bPtr->highlightedItem = bPtr->selectedItemIndex; + /* Compute highlighted item from pointer position relative + * to the menu view, matching upstream WINGs semantics: + * the item under the pointer is highlighted on open. */ + int rel_y = event->u.button.y_root - bPtr->menuView->pos.y; + int item = rel_y / bPtr->view->size.height; + int count = WMGetArrayItemCount(bPtr->items); + if (item >= count) item = count - 1; + if (item < 0) item = 0; + bPtr->highlightedItem = item; bPtr->flags.insideMenu = 1; + if (bPtr->highlightedItem < count) { + WMMenuItem *mi = WMGetPopUpButtonMenuItem(bPtr, item); + paintMenuEntry(bPtr, item, WMGetMenuItemEnabled(mi)); + } } else { bPtr->highlightedItem = -1; bPtr->flags.insideMenu = 0;