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;
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);
}
}

View File

@ -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 };