From 2b0484b11ccb71b9bed2593706938928a32a4e11 Mon Sep 17 00:00:00 2001 From: RisingThumb Date: Tue, 22 Sep 2020 22:31:12 +0100 Subject: [PATCH 1/2] Support for 1-9 numbers to select specific item --- xmenu.1 | 2 +- xmenu.c | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/xmenu.1 b/xmenu.1 index 9a0f6a7..30ea36b 100644 --- a/xmenu.1 +++ b/xmenu.1 @@ -96,7 +96,7 @@ but can also be controlled by the keyboard. Items can be selected using the arrow keys, Tab (with and without Shift), Home, End, -Enter and Esc. +Enter and Esc, and 1-9 keys. .TP .BR Home Select the first item in the menu. diff --git a/xmenu.c b/xmenu.c index 0cc56ac..e74c3c7 100644 --- a/xmenu.c +++ b/xmenu.c @@ -1280,7 +1280,14 @@ selectitem: item = itemcycle(currmenu, ITEMPREV); } else if (ksym == XK_Tab || ksym == XK_Down || ksym == KSYMDOWN) { item = itemcycle(currmenu, ITEMNEXT); - } else if ((ksym == XK_Return || ksym == XK_Right || ksym == KSYMRIGHT) && + } else if (ksym >= XK_1 && ksym <= XK_9){ + item = itemcycle(currmenu, ITEMFIRST); + currmenu->selected = item; + for(int i = ksym-XK_1; i > 0; i-=1){ + item = itemcycle(currmenu, ITEMNEXT); + currmenu->selected = item; + } + } else if ((ksym == XK_Return || ksym == XK_Right || ksym == KSYMRIGHT) && currmenu->selected != NULL) { item = currmenu->selected; goto selectitem; From 02511d092bbf97f19beac22fa5731ff29b818d73 Mon Sep 17 00:00:00 2001 From: RisingThumb Date: Tue, 22 Sep 2020 22:41:16 +0100 Subject: [PATCH 2/2] Fix loop around for number keys --- xmenu.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/xmenu.c b/xmenu.c index e74c3c7..c29c31d 100644 --- a/xmenu.c +++ b/xmenu.c @@ -1281,14 +1281,15 @@ selectitem: } else if (ksym == XK_Tab || ksym == XK_Down || ksym == KSYMDOWN) { item = itemcycle(currmenu, ITEMNEXT); } else if (ksym >= XK_1 && ksym <= XK_9){ - item = itemcycle(currmenu, ITEMFIRST); - currmenu->selected = item; - for(int i = ksym-XK_1; i > 0; i-=1){ - item = itemcycle(currmenu, ITEMNEXT); - currmenu->selected = item; - } - } else if ((ksym == XK_Return || ksym == XK_Right || ksym == KSYMRIGHT) && - currmenu->selected != NULL) { + item = itemcycle(currmenu, ITEMFIRST); + for(int i = ksym-XK_1; i > 0; i-=1){ + 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) { item = currmenu->selected; goto selectitem; } else if ((ksym == XK_Escape || ksym == XK_Left || ksym == KSYMLEFT) &&