From a2ff706d6f56d45b2a55cf77d2943b2954ce4934 Mon Sep 17 00:00:00 2001 From: phillbush Date: Thu, 30 Jul 2020 17:04:04 -0300 Subject: [PATCH] No more needed to use -i to disable icon padding Now xmenu detects if a menu has an icon, and if it doesn't have, the menu will not have the gaps fgor icons, making the -i flag unecessary to disable the padding. The -i option is still necessary, however, to speed up xmenu loading, since it disables imlib2 initialization routines. --- xmenu.c | 8 ++++++-- xmenu.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/xmenu.c b/xmenu.c index 0d964e0..abbf240 100644 --- a/xmenu.c +++ b/xmenu.c @@ -467,6 +467,7 @@ allocmenu(struct Menu *parent, struct Item *list, unsigned level) menu->y = 0; /* calculated by setupmenu() */ menu->level = level; menu->drawn = 0; + menu->hasicon = 0; swa.override_redirect = (wflag) ? False : True; swa.background_pixel = dc.normal[ColorBG].pixel; @@ -541,6 +542,9 @@ buildmenutree(unsigned level, const char *label, const char *output, char *file) curritem->prev = NULL; } + if (curritem->file) + prevmenu->hasicon = 1; + return rootmenu; } @@ -718,7 +722,7 @@ setupitems(struct Menu *menu) * padding appears 3 times: before the label and around the triangle. */ itemwidth = textwidth + config.triangle_width + config.horzpadding * 3; - itemwidth += (iflag) ? 0 : config.iconsize + config.horzpadding; + itemwidth += (iflag || !menu->hasicon) ? 0 : config.iconsize + config.horzpadding; menu->w = MAX(menu->w, itemwidth); } } @@ -902,7 +906,7 @@ drawitems(struct Menu *menu) /* draw text */ x = config.horzpadding; - x += (iflag) ? 0 : config.horzpadding + config.iconsize; + x += (iflag || !menu->hasicon) ? 0 : config.horzpadding + config.iconsize; dsel = XftDrawCreate(dpy, item->sel, visual, colormap); dunsel = XftDrawCreate(dpy, item->unsel, visual, colormap); XSetForeground(dpy, dc.gc, dc.selected[ColorFG].pixel); diff --git a/xmenu.h b/xmenu.h index bf5cb80..909b091 100644 --- a/xmenu.h +++ b/xmenu.h @@ -84,6 +84,7 @@ struct Menu { struct Item *list; /* list of items contained by the menu */ struct Item *selected; /* item currently selected in the menu */ int x, y, w, h; /* menu geometry */ + int hasicon; /* whether the menu has item with icons */ int drawn; /* whether the menu was already drawn */ unsigned level; /* menu level relative to root */ Window win; /* menu window to map on the screen */