From 35f79eb8349f0e7b9ba07deeb0752846726e8e5e Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Wed, 18 Mar 2026 00:56:00 -0500 Subject: [PATCH] Menu bar items now depress when clicked. --- dvx/dvxApp.c | 18 ++++++++++++++++++ dvx/dvxTypes.h | 1 + dvx/dvxWm.c | 19 +++++++++++++++---- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/dvx/dvxApp.c b/dvx/dvxApp.c index ea07058..3ec18e9 100644 --- a/dvx/dvxApp.c +++ b/dvx/dvxApp.c @@ -335,6 +335,13 @@ static void closeAllPopups(AppContextT *ctx) { dirtyListAdd(&ctx->dirty, pl->popupX, pl->popupY, pl->popupW, pl->popupH); } + // Clear the depressed menu bar item + WindowT *popupWin = findWindowById(ctx, ctx->popup.windowId); + if (popupWin && popupWin->menuBar && popupWin->menuBar->activeIdx >= 0) { + popupWin->menuBar->activeIdx = -1; + dirtyListAdd(&ctx->dirty, popupWin->x, popupWin->y, popupWin->w, CHROME_BORDER_WIDTH + CHROME_TITLE_HEIGHT + CHROME_MENU_HEIGHT); + } + ctx->popup.active = false; ctx->popup.depth = 0; } @@ -371,6 +378,13 @@ static void closePopupLevel(AppContextT *ctx) { ctx->popup.popupH = pl->popupH; ctx->popup.hoverItem = pl->hoverItem; } else { + // Clear the depressed menu bar item + WindowT *popupWin = findWindowById(ctx, ctx->popup.windowId); + if (popupWin && popupWin->menuBar && popupWin->menuBar->activeIdx >= 0) { + popupWin->menuBar->activeIdx = -1; + dirtyListAdd(&ctx->dirty, popupWin->x, popupWin->y, popupWin->w, CHROME_BORDER_WIDTH + CHROME_TITLE_HEIGHT + CHROME_MENU_HEIGHT); + } + ctx->popup.active = false; } } @@ -2416,6 +2430,10 @@ static void openPopupAtMenu(AppContextT *ctx, WindowT *win, int32_t menuIdx) { ctx->popup.menu = menu; ctx->popup.popupX = win->x + menu->barX; ctx->popup.popupY = win->y + CHROME_BORDER_WIDTH + CHROME_TITLE_HEIGHT + CHROME_MENU_HEIGHT; + + // Mark the menu bar item as active (depressed look) + win->menuBar->activeIdx = menuIdx; + dirtyListAdd(&ctx->dirty, win->x, win->y, win->w, CHROME_BORDER_WIDTH + CHROME_TITLE_HEIGHT + CHROME_MENU_HEIGHT); ctx->popup.hoverItem = -1; ctx->popup.depth = 0; diff --git a/dvx/dvxTypes.h b/dvx/dvxTypes.h index f75c2ae..3503447 100644 --- a/dvx/dvxTypes.h +++ b/dvx/dvxTypes.h @@ -304,6 +304,7 @@ struct MenuT { typedef struct { MenuT menus[MAX_MENUS]; int32_t menuCount; + int32_t activeIdx; // menu bar item with open popup (-1 = none) bool positionsDirty; // true = barX/barW need recomputation } MenuBarT; diff --git a/dvx/dvxWm.c b/dvx/dvxWm.c index 32398c6..107d1e5 100644 --- a/dvx/dvxWm.c +++ b/dvx/dvxWm.c @@ -301,12 +301,22 @@ static void drawMenuBar(DisplayT *d, const BlitOpsT *ops, const BitmapFontT *fon win->w - CHROME_BORDER_WIDTH * 2, barH); for (int32_t i = 0; i < win->menuBar->menuCount; i++) { - MenuT *menu = &win->menuBar->menus[i]; - int32_t textX = win->x + menu->barX + CHROME_TITLE_PAD; + MenuT *menu = &win->menuBar->menus[i]; + int32_t itemX = win->x + menu->barX; + int32_t itemW = menu->barW; + int32_t textX = itemX + CHROME_TITLE_PAD; int32_t textY = barY + (barH - font->charHeight) / 2; - drawTextAccel(d, ops, font, textX, textY, menu->label, - colors->menuFg, colors->menuBg, true); + if (i == win->menuBar->activeIdx) { + // Depressed look for the open menu item + BevelStyleT sunken = BEVEL_SUNKEN(colors, colors->menuBg, 1); + drawBevel(d, ops, itemX, barY, itemW, barH - 1, &sunken); + drawTextAccel(d, ops, font, textX + 1, textY + 1, menu->label, + colors->menuFg, colors->menuBg, true); + } else { + drawTextAccel(d, ops, font, textX, textY, menu->label, + colors->menuFg, colors->menuBg, true); + } } setClipRect(d, savedClipX, savedClipY, savedClipW, savedClipH); @@ -852,6 +862,7 @@ MenuBarT *wmAddMenuBar(WindowT *win) { } memset(win->menuBar, 0, sizeof(MenuBarT)); + win->menuBar->activeIdx = -1; wmUpdateContentRect(win); return win->menuBar;