diff --git a/xmenu.c b/xmenu.c index 7ae7162..1515165 100644 --- a/xmenu.c +++ b/xmenu.c @@ -1150,13 +1150,15 @@ run(struct Menu *currmenu) struct Item *lastitem; KeySym ksym; XEvent ev; + int action; mapmenu(currmenu); while (!XNextEvent(dpy, &ev)) { + action = ACTION_NOP; switch(ev.type) { case Expose: if (ev.xexpose.count == 0) - drawmenus(currmenu); + action = ACTION_DRAW; break; case MotionNotify: menu = getmenu(currmenu, ev.xbutton.window); @@ -1171,8 +1173,7 @@ run(struct Menu *currmenu) } else { currmenu = menu; } - mapmenu(currmenu); - drawmenus(currmenu); + action = ACTION_MAP | ACTION_DRAW; break; case ButtonRelease: if (!isclickbutton(ev.xbutton.button)) @@ -1190,9 +1191,8 @@ selectitem: printf("%s\n", item->output); return; } - mapmenu(currmenu); currmenu->selected = currmenu->list; - drawmenus(currmenu); + action = ACTION_MAP | ACTION_DRAW; break; case ButtonPress: menu = getmenu(currmenu, ev.xbutton.window); @@ -1235,16 +1235,16 @@ selectitem: currmenu->parent != NULL) { item = currmenu->parent->selected; currmenu = currmenu->parent; - mapmenu(currmenu); + action = ACTION_MAP; } else break; currmenu->selected = item; - drawmenus(currmenu); + action |= ACTION_DRAW; break; case LeaveNotify: previtem = NULL; currmenu->selected = NULL; - drawmenus(currmenu); + action = ACTION_DRAW; break; case ConfigureNotify: menu = getmenu(currmenu, ev.xconfigure.window); @@ -1261,9 +1261,13 @@ selectitem: if (menu->parent == NULL) return; /* closing the root menu closes the program */ currmenu = menu->parent; - mapmenu(currmenu); + action = ACTION_MAP; break; } + if (action & ACTION_MAP) + mapmenu(currmenu); + if (action & ACTION_DRAW) + drawmenus(currmenu); } } diff --git a/xmenu.h b/xmenu.h index 340ce24..ee420da 100644 --- a/xmenu.h +++ b/xmenu.h @@ -1,5 +1,10 @@ #define PROGNAME "xmenu" +/* Actions for the main loop */ +#define ACTION_NOP 0 +#define ACTION_MAP 1<<0 +#define ACTION_DRAW 1<<1 + /* enum for keyboard menu navigation */ enum { ITEMPREV, ITEMNEXT, ITEMFIRST, ITEMLAST };