+ imlib_context_set_image(icon);
+
+ width = imlib_image_get_width();
+ height = imlib_image_get_height();
+ imgsize = MIN(width, height);
+
+ icon = imlib_create_cropped_scaled_image(0, 0, imgsize, imgsize,
+ config.iconsize,
+ config.iconsize);
+
+ return icon;
+}
+
+/* draw pixmap for the selected and unselected version of each item on menu */
+static void
+drawitems(struct Menu *menu)
+{
+ XftDraw *dsel, *dunsel;
+ struct Item *item;
+ int textx;
+ int x, y;
+
+ for (item = menu->list; item != NULL; item = item->next) {
+ item->unsel = XCreatePixmap(dpy, menu->win, menu->w, item->h,
+ DefaultDepth(dpy, screen));
+
+ XSetForeground(dpy, dc.gc, dc.normal[ColorBG].pixel);
+ XFillRectangle(dpy, item->unsel, dc.gc, 0, 0, menu->w, item->h);
+
+ if (item->label == NULL) { /* item is separator */
+ y = item->h/2;
+ XSetForeground(dpy, dc.gc, dc.separator.pixel);
+ XDrawLine(dpy, item->unsel, dc.gc, config.horzpadding, y,
+ menu->w - config.horzpadding, y);
+
+ item->sel = item->unsel;
+ } else {
+ item->sel = XCreatePixmap(dpy, menu->win, menu->w, item->h,
+ DefaultDepth(dpy, screen));
+ XSetForeground(dpy, dc.gc, dc.selected[ColorBG].pixel);
+ XFillRectangle(dpy, item->sel, dc.gc, 0, 0, menu->w, item->h);
+
+ /* draw text */
+ textx = config.horzpadding;
+ textx += (iflag || !menu->hasicon) ? 0 : config.horzpadding + config.iconsize;
+ switch (config.alignment) {
+ case CenterAlignment:
+ textx += (menu->maxtextw - item->textw) / 2;
+ break;
+ case RightAlignment:
+ textx += menu->maxtextw - item->textw;
+ break;
+ default:
+ break;
+ }
+ dsel = XftDrawCreate(dpy, item->sel, visual, colormap);
+ dunsel = XftDrawCreate(dpy, item->unsel, visual, colormap);
+ XSetForeground(dpy, dc.gc, dc.selected[ColorFG].pixel);
+ drawtext(dsel, &dc.selected[ColorFG], textx, 0, item->h, item->label);
+ XSetForeground(dpy, dc.gc, dc.normal[ColorFG].pixel);
+ drawtext(dunsel, &dc.normal[ColorFG], textx, 0, item->h, item->label);
+ XftDrawDestroy(dsel);
+ XftDrawDestroy(dunsel);
+
+ /* draw triangle */
+ if (item->submenu != NULL) {
+ x = menu->w - config.triangle_width - config.horzpadding;
+ y = (item->h - config.triangle_height + 1) / 2;
+
+ XPoint triangle[] = {
+ {x, y},
+ {x + config.triangle_width, y + config.triangle_height/2},
+ {x, y + config.triangle_height},
+ {x, y}
+ };
+
+ XSetForeground(dpy, dc.gc, dc.selected[ColorFG].pixel);
+ XFillPolygon(dpy, item->sel, dc.gc, triangle, LEN(triangle),
+ Convex, CoordModeOrigin);
+ XSetForeground(dpy, dc.gc, dc.normal[ColorFG].pixel);
+ XFillPolygon(dpy, item->unsel, dc.gc, triangle, LEN(triangle),
+ Convex, CoordModeOrigin);
+ }
+
+ /* try to load icon */
+ if (item->file && !iflag) {
+ item->icon = loadicon(item->file);
+ free(item->file);
+ }