summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoranselm@garbe.us <unknown>2010-03-22 07:50:26 +0000
committeranselm@garbe.us <unknown>2010-03-22 07:50:26 +0000
commit8e3e61170bd34d8a8269e376c30cb3afa25343a2 (patch)
tree91ba646e16a6414f85389905f7d2164308d7a90a
parent37236f8840624d5e9d590e7be9ba365bc61913a6 (diff)
applied cls' patch, thanks Connor!
-rw-r--r--dmenu.c24
1 files changed, 13 insertions, 11 deletions
diff --git a/dmenu.c b/dmenu.c
index aef8ae5..5f16894 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -372,7 +372,7 @@ initfont(const char *fontstr) {
void
kpress(XKeyEvent * e) {
- char buf[32];
+ char buf[sizeof text];
int i, num;
unsigned int len;
KeySym ksym;
@@ -457,25 +457,23 @@ kpress(XKeyEvent * e) {
char *c;
if(!(fp = (FILE*)popen("sselp", "r")))
eprint("dmenu: Could not popen sselp\n");
- c = fgets(text + len, sizeof(text) - len, fp);
+ c = fgets(buf, sizeof buf, fp);
pclose(fp);
if(c == NULL)
return;
}
- len = strlen(text);
- if(len && text[len-1] == '\n')
- text[--len] = '\0';
- match(text);
- drawmenu();
- return;
+ num = strlen(buf);
+ if(num && buf[num-1] == '\n')
+ buf[--num] = '\0';
+ break;
}
}
switch(ksym) {
default:
+ num = MIN(num, sizeof text - cursor);
if(num && !iscntrl((int) buf[0])) {
- buf[num] = 0;
- memmove(text + cursor + num, text + cursor, sizeof text - cursor);
- strncpy(text + cursor, buf, sizeof text - cursor);
+ memmove(text + cursor + num, text + cursor, sizeof text - cursor - num);
+ memmove(text + cursor, buf, num);
cursor+=num;
match(text);
}
@@ -487,6 +485,10 @@ kpress(XKeyEvent * e) {
match(text);
}
break;
+ case XK_Delete:
+ memmove(text + cursor, text + cursor + 1, sizeof text - cursor);
+ match(text);
+ break;
case XK_End:
if(!item)
return;