From c2959cf43954975a2b5913009799b8308463d6c1 Mon Sep 17 00:00:00 2001 From: phillbush Date: Tue, 22 Sep 2020 19:18:15 -0300 Subject: [PATCH] add lastitem and adapt code to general code style --- xmenu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/xmenu.c b/xmenu.c index c29c31d..76761cc 100644 --- a/xmenu.c +++ b/xmenu.c @@ -1209,6 +1209,7 @@ run(struct Menu *currmenu) struct Menu *menu; struct Item *item; struct Item *previtem = NULL; + struct Item *lastitem; KeySym ksym; XEvent ev; @@ -1282,11 +1283,10 @@ selectitem: item = itemcycle(currmenu, ITEMNEXT); } else if (ksym >= XK_1 && ksym <= XK_9){ item = itemcycle(currmenu, ITEMFIRST); - for(int i = ksym-XK_1; i > 0; i-=1){ + lastitem = itemcycle(currmenu, ITEMLAST); + for (int i = ksym - XK_1; i > 0 && item != lastitem; i--) { currmenu->selected = item; item = itemcycle(currmenu, ITEMNEXT); - if (item == itemcycle(currmenu, ITEMLAST)) - break; } } else if ((ksym == XK_Return || ksym == XK_Right || ksym == KSYMRIGHT) && currmenu->selected != NULL) {