From b59ddffce60a1456ff27cb08ba91fe79ea9f540e Mon Sep 17 00:00:00 2001 From: IoIxD Date: Mon, 28 Sep 2026 18:46:12 -0700 Subject: [PATCH] menu fix --- include/Mw/TypeDefs.h | 1 + src/backend/wayland/wayland.c | 9 ++++++++- src/widget/menu.c | 1 + src/widget/submenu.c | 14 ++++++++++---- 4 files changed, 20 insertions(+), 5 deletions(-) diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index 2a4093a5..0ace3fc4 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -169,6 +169,7 @@ struct _MwMenu { MwMenu* sub; void* opaque; int cleaned; + int bold; }; struct _MwEntry { diff --git a/src/backend/wayland/wayland.c b/src/backend/wayland/wayland.c index 4373af62..74b0df66 100644 --- a/src/backend/wayland/wayland.c +++ b/src/backend/wayland/wayland.c @@ -628,6 +628,8 @@ static void setup_popup(MwLL r, int x, int y, MwLL parent) { xdg_positioner_set_anchor(r->wayland.popup->xdg_positioner, XDG_POSITIONER_ANCHOR_NONE); xdg_positioner_set_gravity(r->wayland.popup->xdg_positioner, XDG_POSITIONER_GRAVITY_NONE); + /* we can't see where we are on screen, so let the compositor keep the popup on it */ + xdg_positioner_set_constraint_adjustment(r->wayland.popup->xdg_positioner, XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_X | XDG_POSITIONER_CONSTRAINT_ADJUSTMENT_SLIDE_Y); r->wayland.xkb_keymap = topmost_parent->wayland.xkb_keymap; r->wayland.xkb_state = topmost_parent->wayland.xkb_state; @@ -1776,7 +1778,12 @@ static void MwLLDetachImpl(MwLL handle, MwPoint* point) { while(p != NULL) { /* a layer surface's x/y is its position on screen, which like a toplevel's isn't part of the offset */ - if(p->wayland.type != MwLL_WAYLAND_TOPLEVEL && p->wayland.type != MwLL_WAYLAND_LAYER_SURFACE) { + if(p->wayland.type == MwLL_WAYLAND_POPUP) { + /* a popup's x/y is already relative to the topmost surface, so anything above it is counted already */ + x += p->wayland.x; + y += p->wayland.y; + break; + } else if(p->wayland.type != MwLL_WAYLAND_TOPLEVEL && p->wayland.type != MwLL_WAYLAND_LAYER_SURFACE) { x += p->wayland.x; y += p->wayland.y; } else { diff --git a/src/widget/menu.c b/src/widget/menu.c index 92820548..0a4b4377 100644 --- a/src/widget/menu.c +++ b/src/widget/menu.c @@ -248,6 +248,7 @@ static MwMenu mwMenuAddImpl(MwWidget handle, MwMenu menu, const char* name) { new->wsub = NULL; new->keep = 0; new->cleaned = 0; + new->bold = 0; arrput(m->sub, new); diff --git a/src/widget/submenu.c b/src/widget/submenu.c index e2bab1cc..74b53ba7 100644 --- a/src/widget/submenu.c +++ b/src/widget/submenu.c @@ -57,8 +57,9 @@ static void draw(MwWidget handle) { p.y += 2 + 1; } else { - int tw = MwTextWidth(handle, NULL, menu->sub[i]->name); - int th = MwTextHeight(handle, NULL, menu->sub[i]->name); + MwFLFont font = MwFLBuildFont(menu->sub[i]->wsub != NULL ? MwFLFlagBold : 0); + int tw = MwTextWidth(handle, font, menu->sub[i]->name); + int th = MwTextHeight(handle, NULL, menu->sub[i]->name); if(menu->sub[i]->wsub != NULL) { r.x = MwGetInteger(handle, MwNleftPadding); @@ -71,7 +72,7 @@ static void draw(MwWidget handle) { p.x = 5 + tw / 2 + MwGetInteger(handle, MwNleftPadding); p.y += th / 2; - MwDrawText(handle, MwFLBuildFont(menu->sub[i]->wsub != NULL ? MwFLFlagBold : 0), &p, menu->sub[i]->name, MwALIGNMENT_CENTER, text); + MwDrawText(handle, font, &p, menu->sub[i]->name, MwALIGNMENT_CENTER, text); if(arrlen(menu->sub[i]->sub) > 0) { MwRect tr; @@ -182,6 +183,11 @@ static void mwSubMenuAppearImpl(MwWidget handle, MwMenu menu, MwPoint* point, in MwLLMakeToolWindow(handle->lowlevel); MwLLDetach(handle->lowlevel, &p); + MwVaApply(handle, + MwNwidth, sz.width, + MwNheight, sz.height, + NULL); + if(handle->lowlevel->common.coordinate_type == MwCOORDINATE_GLOBAL) { if(MwGetInteger(handle, MwNy) + sz.height > rc.height) { MwVaApply(handle, @@ -208,7 +214,7 @@ static void mwSubMenuGetSizeImpl(MwWidget handle, MwMenu menu, MwRect* rect) { if(strcmp(menu->sub[i]->name, "----") == 0) { rect->height += 2 + 2; } else { - int tw = MwTextWidth(handle, NULL, menu->sub[i]->name); + int tw = MwTextWidth(handle, MwFLBuildFont(arrlen(menu->sub[i]->sub) > 0 ? MwFLFlagBold : 0), menu->sub[i]->name); rect->height += MwTextHeight(handle, NULL, menu->sub[i]->name) + 3; if(tw > rect->width) { rect->width = tw;