aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorConnor Lane Smith <cls@lubutu.com>2010-06-24 14:22:34 +0100
committerConnor Lane Smith <cls@lubutu.com>2010-06-24 14:22:34 +0100
commit6c1d0e4d60b239e9533def6feaf8eb2138858c3e (patch)
tree710f1366ba2cbb4bce0cf2cc0ac7d6bdd0ddfdf0
parent6efe1932be9425896c34f54501a6194286dd0503 (diff)
fixed offsets, updated eprint, cleaned up
-rw-r--r--dinput.c5
-rw-r--r--dmenu.c56
-rw-r--r--draw.c12
-rw-r--r--draw.h2
4 files changed, 42 insertions, 33 deletions
diff --git a/dinput.c b/dinput.c
index d8f2515..15f5e26 100644
--- a/dinput.c
+++ b/dinput.c
@@ -164,7 +164,7 @@ kpress(XKeyEvent * e) {
164 FILE *fp; 164 FILE *fp;
165 char *s; 165 char *s;
166 if(!(fp = popen("sselp", "r"))) 166 if(!(fp = popen("sselp", "r")))
167 eprint("dinput: cannot popen sselp\n"); 167 eprint("cannot popen sselp\n");
168 s = fgets(buf, sizeof buf, fp); 168 s = fgets(buf, sizeof buf, fp);
169 pclose(fp); 169 pclose(fp);
170 if(s == NULL) 170 if(s == NULL)
@@ -322,6 +322,7 @@ main(int argc, char *argv[]) {
322 Bool topbar = True; 322 Bool topbar = True;
323 323
324 /* command line args */ 324 /* command line args */
325 progname = argv[0];
325 for(i = 1; i < argc; i++) 326 for(i = 1; i < argc; i++)
326 if(!strcmp(argv[i], "-b")) 327 if(!strcmp(argv[i], "-b"))
327 topbar = False; 328 topbar = False;
@@ -356,7 +357,7 @@ main(int argc, char *argv[]) {
356 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) 357 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
357 fprintf(stderr, "dinput: warning: no locale support\n"); 358 fprintf(stderr, "dinput: warning: no locale support\n");
358 if(!(dpy = XOpenDisplay(NULL))) 359 if(!(dpy = XOpenDisplay(NULL)))
359 eprint("dinput: cannot open display\n"); 360 eprint("cannot open display\n");
360 screen = DefaultScreen(dpy); 361 screen = DefaultScreen(dpy);
361 if(!parent) 362 if(!parent)
362 parent = RootWindow(dpy, screen); 363 parent = RootWindow(dpy, screen);
diff --git a/dmenu.c b/dmenu.c
index 8b40aa7..878bc95 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -34,6 +34,7 @@ static void calcoffsetsh(void);
34static void calcoffsetsv(void); 34static void calcoffsetsv(void);
35static char *cistrstr(const char *s, const char *sub); 35static char *cistrstr(const char *s, const char *sub);
36static void cleanup(void); 36static void cleanup(void);
37static void dinput(void);
37static void drawmenu(void); 38static void drawmenu(void);
38static void drawmenuh(void); 39static void drawmenuh(void);
39static void drawmenuv(void); 40static void drawmenuv(void);
@@ -89,28 +90,25 @@ void
89calcoffsetsh(void) { 90calcoffsetsh(void) {
90 unsigned int w; 91 unsigned int w;
91 92
92 if(!curr) 93 w = promptw + cmdw + (2 * spaceitem);
93 return; 94 for(next = curr; next; next = next->right)
94 w = promptw + cmdw + 2 * spaceitem; 95 if((w += MIN(textw(next->text), mw / 3)) > mw)
95 for(next = curr; next && w < mw; next=next->right) 96 break;
96 w += MIN(textw(next->text), mw / 3); 97 w = promptw + cmdw + (2 * spaceitem);
97 w = promptw + cmdw + 2 * spaceitem; 98 for(prev = curr; prev && prev->left; prev = prev->left)
98 for(prev = curr; prev && prev->left && w < mw; prev=prev->left) 99 if((w += MIN(textw(prev->left->text), mw / 3)) > mw)
99 w += MIN(textw(prev->left->text), mw / 3); 100 break;
100} 101}
101 102
102void 103void
103calcoffsetsv(void) { 104calcoffsetsv(void) {
104 unsigned int h; 105 unsigned int i;
105 106
106 if(!curr) 107 next = prev = curr;
107 return; 108 for(i = 0; i < lines && next; i++)
108 h = (dc.font.height + 2) * lines; 109 next = next->right;
109 for(next = curr; next && h > 0; next = next->right) 110 for(i = 0; i < lines && prev && prev->left; i++)
110 h -= dc.font.height + 2; 111 prev = prev->left;
111 h = (dc.font.height + 2) * lines;
112 for(prev = curr; prev && prev->left && h > 0; prev = prev->left)
113 h -= dc.font.height + 2;
114} 112}
115 113
116char * 114char *
@@ -151,6 +149,13 @@ cleanup(void) {
151} 149}
152 150
153void 151void
152dinput(void) {
153 cleanup();
154 execlp("dinput", "dinput", text, NULL); /* todo: argv */
155 eprint("cannot exec dinput\n");
156}
157
158void
154drawmenu(void) { 159drawmenu(void) {
155 dc.x = 0; 160 dc.x = 0;
156 dc.y = 0; 161 dc.y = 0;
@@ -290,8 +295,7 @@ kpress(XKeyEvent * e) {
290 match(text); 295 match(text);
291 break; 296 break;
292 case XK_x: 297 case XK_x:
293 execlp("dinput", "dinput", text, NULL); /* todo: argv */ 298 dinput();
294 eprint("dmenu: cannot exec dinput:");
295 break; 299 break;
296 } 300 }
297 } 301 }
@@ -369,10 +373,9 @@ kpress(XKeyEvent * e) {
369 } 373 }
370 break; 374 break;
371 case XK_Tab: 375 case XK_Tab:
372 if(!sel) 376 if(sel)
373 return; 377 strncpy(text, sel->text, sizeof text);
374 strncpy(text, sel->text, sizeof text); 378 dinput();
375 match(text);
376 break; 379 break;
377 } 380 }
378 drawmenu(); 381 drawmenu();
@@ -431,11 +434,11 @@ readstdin(void) {
431 if(buf[len-1] == '\n') 434 if(buf[len-1] == '\n')
432 buf[--len] = '\0'; 435 buf[--len] = '\0';
433 if(!(p = strdup(buf))) 436 if(!(p = strdup(buf)))
434 eprint("dmenu: cannot strdup %u bytes\n", len); 437 eprint("cannot strdup %u bytes\n", len);
435 if((max = MAX(max, len)) == len) 438 if((max = MAX(max, len)) == len)
436 maxname = p; 439 maxname = p;
437 if(!(new = malloc(sizeof *new))) 440 if(!(new = malloc(sizeof *new)))
438 eprint("dmenu: cannot malloc %u bytes\n", sizeof *new); 441 eprint("cannot malloc %u bytes\n", sizeof *new);
439 new->next = new->left = new->right = NULL; 442 new->next = new->left = new->right = NULL;
440 new->text = p; 443 new->text = p;
441 if(!i) 444 if(!i)
@@ -544,6 +547,7 @@ main(int argc, char *argv[]) {
544 Bool topbar = True; 547 Bool topbar = True;
545 548
546 /* command line args */ 549 /* command line args */
550 progname = argv[0];
547 for(i = 1; i < argc; i++) 551 for(i = 1; i < argc; i++)
548 if(!strcmp(argv[i], "-i")) { 552 if(!strcmp(argv[i], "-i")) {
549 fstrncmp = strncasecmp; 553 fstrncmp = strncasecmp;
@@ -585,7 +589,7 @@ main(int argc, char *argv[]) {
585 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) 589 if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
586 fprintf(stderr, "dmenu: warning: no locale support\n"); 590 fprintf(stderr, "dmenu: warning: no locale support\n");
587 if(!(dpy = XOpenDisplay(NULL))) 591 if(!(dpy = XOpenDisplay(NULL)))
588 eprint("dmenu: cannot open display\n"); 592 eprint("cannot open display\n");
589 screen = DefaultScreen(dpy); 593 screen = DefaultScreen(dpy);
590 if(!parent) 594 if(!parent)
591 parent = RootWindow(dpy, screen); 595 parent = RootWindow(dpy, screen);
diff --git a/draw.c b/draw.c
index 688bd69..6791b97 100644
--- a/draw.c
+++ b/draw.c
@@ -13,6 +13,9 @@
13#define MIN(a, b) ((a) < (b) ? (a) : (b)) 13#define MIN(a, b) ((a) < (b) ? (a) : (b))
14#define MAX(a, b) ((a) > (b) ? (a) : (b)) 14#define MAX(a, b) ((a) > (b) ? (a) : (b))
15 15
16/* variables */
17char *progname;
18
16void 19void
17drawcleanup(void) { 20drawcleanup(void) {
18 if(dc.font.set) 21 if(dc.font.set)
@@ -71,6 +74,7 @@ void
71eprint(const char *errstr, ...) { 74eprint(const char *errstr, ...) {
72 va_list ap; 75 va_list ap;
73 76
77 fprintf(stderr, "%s: ", progname);
74 va_start(ap, errstr); 78 va_start(ap, errstr);
75 vfprintf(stderr, errstr, ap); 79 vfprintf(stderr, errstr, ap);
76 va_end(ap); 80 va_end(ap);
@@ -83,7 +87,7 @@ getcolor(const char *colstr) {
83 XColor color; 87 XColor color;
84 88
85 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color)) 89 if(!XAllocNamedColor(dpy, cmap, colstr, &color, &color))
86 eprint("drawtext: cannot allocate color '%s'\n", colstr); 90 eprint("cannot allocate color '%s'\n", colstr);
87 return color.pixel; 91 return color.pixel;
88} 92}
89 93
@@ -92,8 +96,8 @@ initfont(const char *fontstr) {
92 char *def, **missing = NULL; 96 char *def, **missing = NULL;
93 int i, n; 97 int i, n;
94 98
95 if(!fontstr || fontstr[0] == '\0') 99 if(!fontstr || !*fontstr)
96 eprint("drawtext: cannot load font: '%s'\n", fontstr); 100 eprint("cannot load null font\n");
97 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def); 101 dc.font.set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
98 if(missing) 102 if(missing)
99 XFreeStringList(missing); 103 XFreeStringList(missing);
@@ -111,7 +115,7 @@ initfont(const char *fontstr) {
111 else { 115 else {
112 if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr)) 116 if(!(dc.font.xfont = XLoadQueryFont(dpy, fontstr))
113 && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed"))) 117 && !(dc.font.xfont = XLoadQueryFont(dpy, "fixed")))
114 eprint("drawtext: cannot load font: '%s'\n", fontstr); 118 eprint("cannot load font '%s'\n", fontstr);
115 dc.font.ascent = dc.font.xfont->ascent; 119 dc.font.ascent = dc.font.xfont->ascent;
116 dc.font.descent = dc.font.xfont->descent; 120 dc.font.descent = dc.font.xfont->descent;
117 } 121 }
diff --git a/draw.h b/draw.h
index b6615ab..d1f1a7c 100644
--- a/draw.h
+++ b/draw.h
@@ -30,13 +30,13 @@ int textnw(const char *text, unsigned int len);
30int textw(const char *text); 30int textw(const char *text);
31 31
32/* variables */ 32/* variables */
33extern char *progname;
33extern Display *dpy; 34extern Display *dpy;
34extern DC dc; 35extern DC dc;
35extern int screen; 36extern int screen;
36extern unsigned int mw, mh; 37extern unsigned int mw, mh;
37extern Window parent; 38extern Window parent;
38 39
39/* style */
40extern const char *font; 40extern const char *font;
41extern const char *normbgcolor; 41extern const char *normbgcolor;
42extern const char *normfgcolor; 42extern const char *normfgcolor;