move actions to end of main loop

This commit is contained in:
phillbush 2020-12-29 19:40:17 -03:00
parent f472bfacd9
commit 6bbc0e45ea
2 changed files with 18 additions and 9 deletions

22
xmenu.c
View File

@ -1150,13 +1150,15 @@ run(struct Menu *currmenu)
struct Item *lastitem; struct Item *lastitem;
KeySym ksym; KeySym ksym;
XEvent ev; XEvent ev;
int action;
mapmenu(currmenu); mapmenu(currmenu);
while (!XNextEvent(dpy, &ev)) { while (!XNextEvent(dpy, &ev)) {
action = ACTION_NOP;
switch(ev.type) { switch(ev.type) {
case Expose: case Expose:
if (ev.xexpose.count == 0) if (ev.xexpose.count == 0)
drawmenus(currmenu); action = ACTION_DRAW;
break; break;
case MotionNotify: case MotionNotify:
menu = getmenu(currmenu, ev.xbutton.window); menu = getmenu(currmenu, ev.xbutton.window);
@ -1171,8 +1173,7 @@ run(struct Menu *currmenu)
} else { } else {
currmenu = menu; currmenu = menu;
} }
mapmenu(currmenu); action = ACTION_MAP | ACTION_DRAW;
drawmenus(currmenu);
break; break;
case ButtonRelease: case ButtonRelease:
if (!isclickbutton(ev.xbutton.button)) if (!isclickbutton(ev.xbutton.button))
@ -1190,9 +1191,8 @@ selectitem:
printf("%s\n", item->output); printf("%s\n", item->output);
return; return;
} }
mapmenu(currmenu);
currmenu->selected = currmenu->list; currmenu->selected = currmenu->list;
drawmenus(currmenu); action = ACTION_MAP | ACTION_DRAW;
break; break;
case ButtonPress: case ButtonPress:
menu = getmenu(currmenu, ev.xbutton.window); menu = getmenu(currmenu, ev.xbutton.window);
@ -1235,16 +1235,16 @@ selectitem:
currmenu->parent != NULL) { currmenu->parent != NULL) {
item = currmenu->parent->selected; item = currmenu->parent->selected;
currmenu = currmenu->parent; currmenu = currmenu->parent;
mapmenu(currmenu); action = ACTION_MAP;
} else } else
break; break;
currmenu->selected = item; currmenu->selected = item;
drawmenus(currmenu); action |= ACTION_DRAW;
break; break;
case LeaveNotify: case LeaveNotify:
previtem = NULL; previtem = NULL;
currmenu->selected = NULL; currmenu->selected = NULL;
drawmenus(currmenu); action = ACTION_DRAW;
break; break;
case ConfigureNotify: case ConfigureNotify:
menu = getmenu(currmenu, ev.xconfigure.window); menu = getmenu(currmenu, ev.xconfigure.window);
@ -1261,9 +1261,13 @@ selectitem:
if (menu->parent == NULL) if (menu->parent == NULL)
return; /* closing the root menu closes the program */ return; /* closing the root menu closes the program */
currmenu = menu->parent; currmenu = menu->parent;
mapmenu(currmenu); action = ACTION_MAP;
break; break;
} }
if (action & ACTION_MAP)
mapmenu(currmenu);
if (action & ACTION_DRAW)
drawmenus(currmenu);
} }
} }

View File

@ -1,5 +1,10 @@
#define PROGNAME "xmenu" #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 for keyboard menu navigation */
enum { ITEMPREV, ITEMNEXT, ITEMFIRST, ITEMLAST }; enum { ITEMPREV, ITEMNEXT, ITEMFIRST, ITEMLAST };