No more needed to use -i to disable icon padding
authorphillbush <phillbush@cock.li>
Thu, 30 Jul 2020 20:04:04 +0000 (17:04 -0300)
committerphillbush <phillbush@cock.li>
Thu, 30 Jul 2020 20:04:04 +0000 (17:04 -0300)
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
xmenu.h

diff --git a/xmenu.c b/xmenu.c
index 0d964e0..abbf240 100644 (file)
--- 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->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;
 
        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;
        }
 
                curritem->prev = NULL;
        }
 
+       if (curritem->file)
+               prevmenu->hasicon = 1;
+
        return rootmenu;
 }
 
        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;
                 * 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);
        }
 }
                menu->w = MAX(menu->w, itemwidth);
        }
 }
@@ -902,7 +906,7 @@ drawitems(struct Menu *menu)
 
                        /* draw text */
                        x = config.horzpadding;
 
                        /* 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);
                        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 (file)
--- 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 */
        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 */
        int drawn;              /* whether the menu was already drawn */
        unsigned level;         /* menu level relative to root */
        Window win;             /* menu window to map on the screen */