applied cls' patch, thanks Connor!

This commit is contained in:
anselm@garbe.us 2010-03-22 07:50:26 +00:00
parent 37236f8840
commit 8e3e61170b
1 changed files with 13 additions and 11 deletions

24
dmenu.c
View File

@ -372,7 +372,7 @@ initfont(const char *fontstr) {
void void
kpress(XKeyEvent * e) { kpress(XKeyEvent * e) {
char buf[32]; char buf[sizeof text];
int i, num; int i, num;
unsigned int len; unsigned int len;
KeySym ksym; KeySym ksym;
@ -457,25 +457,23 @@ kpress(XKeyEvent * e) {
char *c; char *c;
if(!(fp = (FILE*)popen("sselp", "r"))) if(!(fp = (FILE*)popen("sselp", "r")))
eprint("dmenu: Could not popen sselp\n"); eprint("dmenu: Could not popen sselp\n");
c = fgets(text + len, sizeof(text) - len, fp); c = fgets(buf, sizeof buf, fp);
pclose(fp); pclose(fp);
if(c == NULL) if(c == NULL)
return; return;
} }
len = strlen(text); num = strlen(buf);
if(len && text[len-1] == '\n') if(num && buf[num-1] == '\n')
text[--len] = '\0'; buf[--num] = '\0';
match(text); break;
drawmenu();
return;
} }
} }
switch(ksym) { switch(ksym) {
default: default:
num = MIN(num, sizeof text - cursor);
if(num && !iscntrl((int) buf[0])) { if(num && !iscntrl((int) buf[0])) {
buf[num] = 0; memmove(text + cursor + num, text + cursor, sizeof text - cursor - num);
memmove(text + cursor + num, text + cursor, sizeof text - cursor); memmove(text + cursor, buf, num);
strncpy(text + cursor, buf, sizeof text - cursor);
cursor+=num; cursor+=num;
match(text); match(text);
} }
@ -487,6 +485,10 @@ kpress(XKeyEvent * e) {
match(text); match(text);
} }
break; break;
case XK_Delete:
memmove(text + cursor, text + cursor + 1, sizeof text - cursor);
match(text);
break;
case XK_End: case XK_End:
if(!item) if(!item)
return; return;