1
0

ordered switch branches in kpress alphabetically, applied Sanders patch for PgUp/Dn and Home/End scrolling

This commit is contained in:
arg@mig29 2006-12-12 09:57:42 +01:00
parent e19e42adbb
commit 4bd3466215
2 changed files with 64 additions and 33 deletions

View File

@ -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. prints version information to standard output, then exits.
.SH USAGE .SH USAGE
dmenu reads a list of newline-separated items from standard input and creates a 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. choice is printed to standard output and dmenu terminates.
.P .P
dmenu is completely controlled by the keyboard. The following keys are recognized: 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 .B Left/Right
Select the previous/next item. Select the previous/next item.
.TP .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 .B Tab
Copy the selected item to the input field. Copy the selected item to the input field.
.TP .TP

89
main.c
View File

@ -170,6 +170,42 @@ kpress(XKeyEvent * e) {
} }
} }
switch(ksym) { 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: case XK_Left:
if(!(sel && sel->left)) if(!(sel && sel->left))
return; return;
@ -179,18 +215,15 @@ kpress(XKeyEvent * e) {
calcoffsets(); calcoffsets();
} }
break; break;
case XK_Tab: case XK_Next:
if(!sel) if(next) {
return; sel = curr = next;
strncpy(text, sel->text, sizeof text); calcoffsets();
match(text); }
break; break;
case XK_Right: case XK_Prior:
if(!(sel && sel->right)) if(prev) {
return; sel = curr = prev;
sel=sel->right;
if(sel == next) {
curr = next;
calcoffsets(); calcoffsets();
} }
break; break;
@ -204,29 +237,21 @@ kpress(XKeyEvent * e) {
fflush(stdout); fflush(stdout);
running = False; running = False;
break; break;
case XK_Escape: case XK_Right:
ret = 1; if(!(sel && sel->right))
running = False; return;
break; sel=sel->right;
case XK_BackSpace: if(sel == next) {
if((i = len)) { curr = next;
prev_nitem = nitem; calcoffsets();
do {
text[--i] = 0;
match(text);
} while(i && nitem && prev_nitem == nitem);
match(text);
} }
break; break;
default: case XK_Tab:
if(num && !iscntrl((int) buf[0])) { if(!sel)
buf[num] = 0; return;
if(len > 0) strncpy(text, sel->text, sizeof text);
strncat(text, buf, sizeof text); match(text);
else break;
strncpy(text, buf, sizeof text);
match(text);
}
} }
drawmenu(); drawmenu();
} }