Merge pull request #14 from Malod219/master
authorphillbush <63266536+phillbush@users.noreply.github.com>
Tue, 22 Sep 2020 22:12:51 +0000 (22:12 +0000)
committerGitHub <noreply@github.com>
Tue, 22 Sep 2020 22:12:51 +0000 (22:12 +0000)
Number key support

xmenu.1
xmenu.c

diff --git a/xmenu.1 b/xmenu.1
index 9a0f6a7..30ea36b 100644 (file)
--- 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,
 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.
 .TP
 .BR Home
 Select the first item in the menu.
diff --git a/xmenu.c b/xmenu.c
index 0cc56ac..c29c31d 100644 (file)
--- a/xmenu.c
+++ b/xmenu.c
@@ -1280,8 +1280,16 @@ selectitem:
                                item = itemcycle(currmenu, ITEMPREV);
                        } else if (ksym == XK_Tab || ksym == XK_Down || ksym == KSYMDOWN) {
                                item = itemcycle(currmenu, ITEMNEXT);
                                item = itemcycle(currmenu, ITEMPREV);
                        } 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);
+                               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) &&
                        } else if ((ksym == XK_Return || ksym == XK_Right || ksym == KSYMRIGHT) &&
-                                  currmenu->selected != NULL) {
+                                   currmenu->selected != NULL) {
                                item = currmenu->selected;
                                goto selectitem;
                        } else if ((ksym == XK_Escape || ksym == XK_Left || ksym == KSYMLEFT) &&
                                item = currmenu->selected;
                                goto selectitem;
                        } else if ((ksym == XK_Escape || ksym == XK_Left || ksym == KSYMLEFT) &&