Using pixmaps rather than drawing directly on windows.
struct Item *selected;
int x, y, w, h;
unsigned level;
struct Item *selected;
int x, y, w, h;
unsigned level;
static void setupgrab(void);
static struct Item *allocitem(const char *label, const char *output);
static struct Menu *allocmenu(struct Menu *parent, struct Item *list, unsigned level);
static void setupgrab(void);
static struct Item *allocitem(const char *label, const char *output);
static struct Menu *allocmenu(struct Menu *parent, struct Item *list, unsigned level);
-static void getmenuitem(Window win, int y,
- struct Menu **menu_ret, struct Item **item_ret);
+static void getmenuitem(Window win, int y, struct Menu **menu_ret, struct Item **item_ret);
static void drawmenu(void);
static void calcscreengeom(void);
static void calcmenu(struct Menu *menu);
static void setcurrmenu(struct Menu *currmenu_new);
static void parsestdin(void);
static void run(void);
static void drawmenu(void);
static void calcscreengeom(void);
static void calcmenu(struct Menu *menu);
static void setcurrmenu(struct Menu *currmenu_new);
static void parsestdin(void);
static void run(void);
+static void freewindow(struct Menu *menu);
static void cleanupexit(void);
static void usage(void);
static void cleanupexit(void);
static void usage(void);
swa.background_pixel = dc.decoration[ColorBG];
swa.border_pixel = dc.decoration[ColorFG];
swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask
swa.background_pixel = dc.decoration[ColorBG];
swa.border_pixel = dc.decoration[ColorFG];
swa.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | ButtonReleaseMask
+ | PointerMotionMask | LeaveWindowMask;
menu->win = XCreateWindow(dpy, rootwin, 0, 0, geom.itemw, geom.itemh, geom.border,
CopyFromParent, CopyFromParent, CopyFromParent,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask,
menu->win = XCreateWindow(dpy, rootwin, 0, 0, geom.itemw, geom.itemh, geom.border,
CopyFromParent, CopyFromParent, CopyFromParent,
CWOverrideRedirect | CWBackPixel | CWBorderPixel | CWEventMask,
sizeh.min_height = sizeh.max_height = menu->h;
XSetWMNormalHints(dpy, menu->win, &sizeh);
sizeh.min_height = sizeh.max_height = menu->h;
XSetWMNormalHints(dpy, menu->win, &sizeh);
+ /* create pixmap */
+ menu->pixmap = XCreatePixmap(dpy, menu->win, menu->w, menu->h,
+ DefaultDepth(dpy, screen));
+
/* calculate positions of submenus */
for (item = menu->list; item != NULL; item = item->next) {
if (item->submenu != NULL)
/* calculate positions of submenus */
for (item = menu->list; item != NULL; item = item->next) {
if (item->submenu != NULL)
/* draw item box */
XSetForeground(dpy, dc.gc, color[ColorBG]);
/* draw item box */
XSetForeground(dpy, dc.gc, color[ColorBG]);
- XFillRectangle(dpy, menu->win, dc.gc, 0, item->y,
+ XFillRectangle(dpy, menu->pixmap, dc.gc, 0, item->y,
geom.itemw, item->h);
/* continue if item is a separator */
geom.itemw, item->h);
/* continue if item is a separator */
labelx = 0 + dc.fonth;
labely = item->y + dc.fonth + geom.itemb;
XSetForeground(dpy, dc.gc, color[ColorFG]);
labelx = 0 + dc.fonth;
labely = item->y + dc.fonth + geom.itemb;
XSetForeground(dpy, dc.gc, color[ColorFG]);
- XDrawString(dpy, menu->win, dc.gc, labelx, labely, item->label, labellen);
+ XDrawString(dpy, menu->pixmap, dc.gc, labelx, labely, item->label, labellen);
/* draw triangle, if item contains a submenu */
if (item->submenu != NULL) {
/* draw triangle, if item contains a submenu */
if (item->submenu != NULL) {
{trianglex, triangley}
};
{trianglex, triangley}
};
- XFillPolygon(dpy, menu->win, dc.gc, triangle, LEN(triangle),
+ XFillPolygon(dpy, menu->pixmap, dc.gc, triangle, LEN(triangle),
Convex, CoordModeOrigin);
}
Convex, CoordModeOrigin);
}
+
+ XCopyArea(dpy, menu->pixmap, menu->win, dc.gc, 0, item->y,
+ menu->w, item->h, 0, item->y);
previtem = item;
} else if (menu->selected != item)
menu->selected = item;
previtem = item;
} else if (menu->selected != item)
menu->selected = item;
break;
case ButtonRelease:
getmenuitem(ev.xbutton.window, ev.xbutton.y, &menu, &item);
break;
case ButtonRelease:
getmenuitem(ev.xbutton.window, ev.xbutton.y, &menu, &item);
+ case LeaveNotify:
+ currmenu->selected = NULL;
+ drawmenu();
+ break;
+/* recursivelly free a pixmap */
+static void
+freewindow(struct Menu *menu)
+{
+ struct Item *item;
+
+ for (item = menu->list; item != NULL; item = item->next)
+ if (item->submenu != NULL)
+ freewindow(item->submenu);
+
+ XFreePixmap(dpy, menu->pixmap);
+ XDestroyWindow(dpy, menu->win);
+}
+
/* cleanup and exit */
static void
cleanupexit(void)
{
/* cleanup and exit */
static void
cleanupexit(void)
{
+ freewindow(rootmenu);
+ XFreeFont(dpy, dc.font);
+ XFreeGC(dpy, dc.gc);
XCloseDisplay(dpy);
exit(0);
}
XCloseDisplay(dpy);
exit(0);
}