From eb43ec3adec43b73c5719b97c9ce38c4a41e3192 Mon Sep 17 00:00:00 2001 From: "arg@mig29" Date: Tue, 12 Dec 2006 09:57:42 +0100 Subject: [PATCH] ordered switch branches in kpress alphabetically, applied Sanders patch for PgUp/Dn and Home/End scrolling --- dmenubar/dmenu.1 | 8 ++++- dmenubar/main.c | 89 +++++++++++++++++++++++++++++++----------------- 2 files changed, 64 insertions(+), 33 deletions(-) diff --git a/dmenubar/dmenu.1 b/dmenubar/dmenu.1 index c47044a..ff0c000 100644 --- a/dmenubar/dmenu.1 +++ b/dmenubar/dmenu.1 @@ -40,7 +40,7 @@ defines the seconds to wait for standard input, before exiting (default is 3). prints version information to standard output, then exits. .SH USAGE dmenu reads a list of newline-separated items from standard input and creates a -menu. When the user selects an item or enters any text and presses Return, his +menu. When the user selects an item or enters any text and presses Return, his/her choice is printed to standard output and dmenu terminates. .P dmenu is completely controlled by the keyboard. The following keys are recognized: @@ -52,6 +52,12 @@ only items containing this text will be displayed. .B Left/Right Select the previous/next item. .TP +.B PageUp/PageDown +Select the first item of the previous/next 'page' of items. +.TP +.B Home/End +Select the first/last item. +.TP .B Tab Copy the selected item to the input field. .TP diff --git a/dmenubar/main.c b/dmenubar/main.c index 743967a..0263948 100644 --- a/dmenubar/main.c +++ b/dmenubar/main.c @@ -170,6 +170,42 @@ kpress(XKeyEvent * e) { } } switch(ksym) { + default: + if(num && !iscntrl((int) buf[0])) { + buf[num] = 0; + if(len > 0) + strncat(text, buf, sizeof text); + else + strncpy(text, buf, sizeof text); + match(text); + } + break; + case XK_BackSpace: + if((i = len)) { + prev_nitem = nitem; + do { + text[--i] = 0; + match(text); + } while(i && nitem && prev_nitem == nitem); + match(text); + } + break; + case XK_End: + while(next) { + sel = curr = next; + calcoffsets(); + } + while(sel->right) + sel = sel->right; + break; + case XK_Escape: + ret = 1; + running = False; + break; + case XK_Home: + sel = curr = item; + calcoffsets(); + break; case XK_Left: if(!(sel && sel->left)) return; @@ -179,18 +215,15 @@ kpress(XKeyEvent * e) { calcoffsets(); } break; - case XK_Tab: - if(!sel) - return; - strncpy(text, sel->text, sizeof text); - match(text); + case XK_Next: + if(next) { + sel = curr = next; + calcoffsets(); + } break; - case XK_Right: - if(!(sel && sel->right)) - return; - sel=sel->right; - if(sel == next) { - curr = next; + case XK_Prior: + if(prev) { + sel = curr = prev; calcoffsets(); } break; @@ -204,29 +237,21 @@ kpress(XKeyEvent * e) { fflush(stdout); running = False; break; - case XK_Escape: - ret = 1; - running = False; - break; - case XK_BackSpace: - if((i = len)) { - prev_nitem = nitem; - do { - text[--i] = 0; - match(text); - } while(i && nitem && prev_nitem == nitem); - match(text); + case XK_Right: + if(!(sel && sel->right)) + return; + sel=sel->right; + if(sel == next) { + curr = next; + calcoffsets(); } break; - default: - if(num && !iscntrl((int) buf[0])) { - buf[num] = 0; - if(len > 0) - strncat(text, buf, sizeof text); - else - strncpy(text, buf, sizeof text); - match(text); - } + case XK_Tab: + if(!sel) + return; + strncpy(text, sel->text, sizeof text); + match(text); + break; } drawmenu(); }