From 784b4c89cea0993ba1885f0b9be991f0cf36d161 Mon Sep 17 00:00:00 2001 From: Ollie Date: Thu, 28 May 2026 20:37:51 +0200 Subject: [PATCH] balloon: fix leave tracking + multi-line height in wl_balloon_draw --- WINGs/wballoon_x11.c | 8 +++++++- WINGs/wview_wl.c | 33 ++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/WINGs/wballoon_x11.c b/WINGs/wballoon_x11.c index e91f181..0c55481 100644 --- a/WINGs/wballoon_x11.c +++ b/WINGs/wballoon_x11.c @@ -204,9 +204,15 @@ void W_BalloonHandleEnterView(WMView * view) if (!bPtr->flags.enabled) return; + /* Clear any previous balloon before showing a new one */ + if (bPtr->view->flags.mapped && bPtr->forWindow != view->window) { + W_UnmapView(bPtr->view); + bPtr->forWindow = WM_NATIVE_NONE; + } + text = WMHashGet(bPtr->table, view); if (!text) { - if (bPtr->view->flags.realized) + if (bPtr->view->flags.realized && bPtr->forWindow == WM_NATIVE_NONE) W_UnmapView(bPtr->view); return; diff --git a/WINGs/wview_wl.c b/WINGs/wview_wl.c index 8d10674..7635f62 100644 --- a/WINGs/wview_wl.c +++ b/WINGs/wview_wl.c @@ -642,9 +642,22 @@ static void wl_balloon_draw(void *vctx, W_View *view, int x, int y, W_Screen *scr = view->screen; WMFont *font = scr->normalFont; - int textWidth = WMWidthOfString(font, text, strlen(text)); - int bw = textWidth + 16; - int bh = WMFontHeight(font) + 8; + int fh = WMFontHeight(font); + + /* Count lines and find widest line for multi-line text */ + int maxWidth = 0, numLines = 1; + const char *p = text; + while (*p) { + const char *nl = strchr(p, '\n'); + int lineLen = nl ? (int)(nl - p) : (int)strlen(p); + int lw = WMWidthOfString(font, p, lineLen); + if (lw > maxWidth) maxWidth = lw; + p = nl ? nl + 1 : p + lineLen; + if (nl) numLines++; + } + + int bw = maxWidth + 16; + int bh = numLines * fh + 8; if (bw < bh) bw = bh; int bx = x + w / 2 - bw / 2; @@ -674,8 +687,18 @@ static void wl_balloon_draw(void *vctx, W_View *view, int x, int y, {bw - 1, 0, 1, bh} }); - WMDrawString(scr, (WMDrawable)view->window, scr->black, font, - 8, (bh - WMFontHeight(font)) / 2, text, strlen(text)); + /* Draw each line */ + p = text; + int line = 0; + while (*p) { + const char *nl = strchr(p, '\n'); + int lineLen = nl ? (int)(nl - p) : (int)strlen(p); + int ty = 4 + line * fh; + WMDrawString(scr, (WMDrawable)view->window, scr->black, font, + 8, ty, p, lineLen); + p = nl ? nl + 1 : p + lineLen; + line++; + } } static void wl_drag_begin(void *vctx, W_View *view, WMEvent *event)