static void calcoffsetsv(void);
static char *cistrstr(const char *s, const char *sub);
static void cleanup(void);
+static void drawcursor(void);
static void drawmenu(void);
static void drawmenuh(void);
static void drawmenuv(void);
dc.x += dc.w;
/* determine maximum items */
for(i = curr; i != next; i=i->right) {
- dc.w = textw(i->text);
- if(dc.w > mw / 3)
- dc.w = mw / 3;
+ dc.w = MIN(textw(i->text), mw / 3);
drawtext(i->text, (sel == i) ? dc.sel : dc.norm);
dc.x += dc.w;
}
void
kpress(XKeyEvent * e) {
- char buf[32];
+ char buf[sizeof text];
int i, num;
unsigned int len;
KeySym ksym;
switch (ksym) {
default: /* ignore other control sequences */
return;
- case XK_bracketleft:
+ case XK_c:
+ case XK_C:
ksym = XK_Escape;
break;
case XK_h:
case XK_U:
text[0] = 0;
match(text);
- drawmenu();
break;
case XK_w:
case XK_W:
- if(len) {
- i = len - 1;
- while(i >= 0 && text[i] == ' ')
- text[i--] = 0;
- while(i >= 0 && text[i] != ' ')
- text[i--] = 0;
+ if(cursor > 0) {
+ i = cursor;
+ while(i-- > 0 && text[i] == ' ');
+ while(i-- > 0 && text[i] != ' ');
+ memmove(text + i + 1, text + cursor, sizeof text - cursor);
+ cursor = i + 1;
match(text);
- drawmenu();
}
break;
}
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);
+ memcpy(text + cursor, buf, num);
cursor+=num;
match(text);
}
break;
case XK_BackSpace:
if(cursor > 0) {
- memmove(text + cursor + -1, text + cursor, sizeof text - cursor);
+ memmove(text + cursor - 1, text + cursor, sizeof text - cursor + 1);
cursor--;
match(text);
}
break;
+ case XK_Delete:
+ memmove(text + cursor, text + cursor + 1, sizeof text - cursor);
+ match(text);
+ break;
case XK_End:
- if(!item)
- return;
+ if(cursor < len) {
+ cursor = len;
+ break;
+ }
while(next) {
sel = curr = next;
calcoffsets();
running = False;
break;
case XK_Home:
- if(!item)
- return;
+ if(sel == item) {
+ cursor = 0;
+ break;
+ }
sel = curr = item;
calcoffsets();
break;
calcoffsets();
break;
case XK_Return:
- if((e->state & ShiftMask) && *text)
+ if((e->state & ShiftMask) || !sel)
fprintf(stdout, "%s", text);
- else if(sel)
+ else
fprintf(stdout, "%s", sel->text);
- else if(*text)
- fprintf(stdout, "%s", text);
fflush(stdout);
running = False;
break;
match(text);
break;
}
- len = strlen(text);
- cursor = MIN(cursor, len);
- cursor = MAX(cursor, 0);
drawmenu();
}
unsigned int len = 0, max = 0;
Item *i, *new;
- i = 0;
+ i = NULL;
while(fgets(buf, sizeof buf, stdin)) {
len = strlen(buf);
- if (buf[len - 1] == '\n')
- buf[len - 1] = 0;
+ if(buf[len-1] == '\n')
+ buf[--len] = '\0';
if(!(p = strdup(buf)))
- eprint("fatal: could not strdup() %u bytes\n", strlen(buf));
+ eprint("fatal: could not strdup() %u bytes\n", len);
if(max < len) {
maxname = p;
max = len;
if(!dc.font.set)
XSetFont(dpy, dc.gc, dc.font.xfont->fid);
if(maxname)
- cmdw = textw(maxname);
- if(cmdw > mw / 3)
- cmdw = mw / 3;
+ cmdw = MIN(textw(maxname), mw / 3);
if(prompt)
- promptw = textw(prompt);
- if(promptw > mw / 5)
- promptw = mw / 5;
+ promptw = MIN(textw(prompt), mw / 5);
text[0] = 0;
match(text);
XMapRaised(dpy, win);
if(++i < argc) selfgcolor = argv[i];
}
else if(!strcmp(argv[i], "-v"))
- eprint("dmenu-"VERSION", © 2006-2009 dmenu engineers, see LICENSE for details\n");
+ eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n");
else
eprint("usage: dmenu [-i] [-b] [-l <lines>] [-fn <font>] [-nb <color>] [-nf <color>]\n"
" [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");