Browse Source

commited Connor's sanity patch

master
Anselm R Garbe 14 years ago
parent
commit
3472085f59
1 changed files with 32 additions and 51 deletions
  1. +32
    -51
      dmenu.c

+ 32
- 51
dmenu.c View File

@ -118,18 +118,14 @@ calcoffsetsh(void) {
return; return;
w = promptw + cmdw + 2 * spaceitem; w = promptw + cmdw + 2 * spaceitem;
for(next = curr; next; next=next->right) { for(next = curr; next; next=next->right) {
tw = textw(next->text);
if(tw > mw / 3)
tw = mw / 3;
tw = MIN(textw(next->text), mw / 3);
w += tw; w += tw;
if(w > mw) if(w > mw)
break; break;
} }
w = promptw + cmdw + 2 * spaceitem; w = promptw + cmdw + 2 * spaceitem;
for(prev = curr; prev && prev->left; prev=prev->left) { for(prev = curr; prev && prev->left; prev=prev->left) {
tw = textw(prev->left->text);
if(tw > mw / 3)
tw = mw / 3;
tw = MIN(textw(prev->left->text), mw / 3);
w += tw; w += tw;
if(w > mw) if(w > mw)
break; break;
@ -138,20 +134,20 @@ calcoffsetsh(void) {
void void
calcoffsetsv(void) { calcoffsetsv(void) {
static unsigned int w;
static unsigned int h;
if(!curr) if(!curr)
return; return;
w = (dc.font.height + 2) * (lines + 1);
h = (dc.font.height + 2) * (lines + 1);
for(next = curr; next; next=next->right) { for(next = curr; next; next=next->right) {
w -= dc.font.height + 2;
if(w <= 0)
h -= dc.font.height + 2;
if(h <= 0)
break; break;
} }
w = (dc.font.height + 2) * (lines + 1);
h = (dc.font.height + 2) * (lines + 1);
for(prev = curr; prev && prev->left; prev=prev->left) { for(prev = curr; prev && prev->left; prev=prev->left) {
w -= dc.font.height + 2;
if(w <= 0)
h -= dc.font.height + 2;
if(h <= 0)
break; break;
} }
} }
@ -352,10 +348,8 @@ initfont(const char *fontstr) {
font_extents = XExtentsOfFontSet(dc.font.set); font_extents = XExtentsOfFontSet(dc.font.set);
n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names); n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) { for(i = 0, dc.font.ascent = 0, dc.font.descent = 0; i < n; i++) {
if(dc.font.ascent < (*xfonts)->ascent)
dc.font.ascent = (*xfonts)->ascent;
if(dc.font.descent < (*xfonts)->descent)
dc.font.descent = (*xfonts)->descent;
dc.font.ascent = MAX(dc.font.ascent, (*xfonts)->ascent);
dc.font.descent = MAX(dc.font.descent, (*xfonts)->descent);
xfonts++; xfonts++;
} }
} }
@ -396,16 +390,16 @@ kpress(XKeyEvent * e) {
return; return;
case XK_a: case XK_a:
case XK_A: case XK_A:
cursor = 0;
break;
case XK_e:
case XK_E:
cursor = strlen(text);
ksym = XK_Home;
break; break;
case XK_c: case XK_c:
case XK_C: case XK_C:
ksym = XK_Escape; ksym = XK_Escape;
break; break;
case XK_e:
case XK_E:
ksym = XK_End;
break;
case XK_h: case XK_h:
case XK_H: case XK_H:
ksym = XK_BackSpace; ksym = XK_BackSpace;
@ -429,7 +423,7 @@ kpress(XKeyEvent * e) {
i = cursor; i = cursor;
while(i-- > 0 && text[i] == ' '); while(i-- > 0 && text[i] == ' ');
while(i-- > 0 && text[i] != ' '); while(i-- > 0 && text[i] != ' ');
memmove(text + i + 1, text + cursor, sizeof text - cursor);
memmove(text + i + 1, text + cursor, sizeof text - cursor + 1);
cursor = i + 1; cursor = i + 1;
match(text); match(text);
} }
@ -460,12 +454,12 @@ kpress(XKeyEvent * e) {
case XK_p: case XK_p:
{ {
FILE *fp; FILE *fp;
char *c;
char *s;
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(buf, sizeof buf, fp);
s = fgets(buf, sizeof buf, fp);
pclose(fp); pclose(fp);
if(c == NULL)
if(s == NULL)
return; return;
} }
num = strlen(buf); num = strlen(buf);
@ -621,32 +615,25 @@ match(char *pattern) {
void void
readstdin(void) { readstdin(void) {
char *p, buf[1024];
unsigned int len = 0, blen = 0, max = 0;
char *p, buf[sizeof text];
unsigned int len = 0, max = 0;
Item *i, *new; Item *i, *new;
i = 0, p = NULL;
i = NULL;
while(fgets(buf, sizeof buf, stdin)) { while(fgets(buf, sizeof buf, stdin)) {
len += (blen = strlen(buf));
if(!(p = realloc(p, len))) {
eprint("fatal: could not realloc() %u bytes\n", len);
return;
}
memcpy (p + len - blen, buf, blen);
if (p[len - 1] == '\n')
p[len - 1] = 0;
else if (!feof(stdin))
continue;
len = strlen(buf);
if(buf[len-1] == '\n')
buf[--len] = '\0';
if(!(p = strdup(buf)))
eprint("fatal: could not strdup() %u bytes\n", len);
if(max < len) { if(max < len) {
maxname = p; maxname = p;
max = len; max = len;
} }
len = 0;
if(!(new = (Item *)malloc(sizeof(Item)))) if(!(new = (Item *)malloc(sizeof(Item))))
eprint("fatal: could not malloc() %u bytes\n", sizeof(Item)); eprint("fatal: could not malloc() %u bytes\n", sizeof(Item));
new->next = new->left = new->right = NULL; new->next = new->left = new->right = NULL;
new->text = p; new->text = p;
p = NULL;
if(!i) if(!i)
allitems = new; allitems = new;
else else
@ -812,8 +799,8 @@ main(int argc, char *argv[]) {
else if(!strcmp(argv[i], "-v")) else if(!strcmp(argv[i], "-v"))
eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n"); eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n");
else else
eprint("usage: dmenu [-i] [-b] [-l <lines>] [-fn <font>] [-nb <color>] [-nf <color>]\n"
" [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
eprint("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-nb <color>]\n"
" [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
fprintf(stderr, "warning: no locale support\n"); fprintf(stderr, "warning: no locale support\n");
if(!(dpy = XOpenDisplay(NULL))) if(!(dpy = XOpenDisplay(NULL)))
@ -822,14 +809,8 @@ main(int argc, char *argv[]) {
if(!root) if(!root)
root = RootWindow(dpy, screen); root = RootWindow(dpy, screen);
if(isatty(STDIN_FILENO)) {
readstdin();
running = grabkeyboard();
}
else { /* prevent keypress loss */
running = grabkeyboard();
readstdin();
}
readstdin();
running = grabkeyboard();
setup(topbar); setup(topbar);
drawmenu(); drawmenu();


Loading…
Cancel
Save