diff options
-rw-r--r-- | dmenu.c | 7 | ||||
-rw-r--r-- | draw.c | 24 | ||||
-rw-r--r-- | draw.h | 9 |
3 files changed, 10 insertions, 30 deletions
@@ -66,7 +66,6 @@ main(int argc, char *argv[]) { | |||
66 | Bool fast = False; | 66 | Bool fast = False; |
67 | int i; | 67 | int i; |
68 | 68 | ||
69 | progname = "dmenu"; | ||
70 | for(i = 1; i < argc; i++) | 69 | for(i = 1; i < argc; i++) |
71 | /* single flags */ | 70 | /* single flags */ |
72 | if(!strcmp(argv[i], "-v")) { | 71 | if(!strcmp(argv[i], "-v")) { |
@@ -383,10 +382,9 @@ keypress(XKeyEvent *ev) { | |||
383 | 382 | ||
384 | void | 383 | void |
385 | match(void) { | 384 | match(void) { |
386 | size_t len; | 385 | size_t len = strlen(text); |
387 | Item *item, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend; | 386 | Item *item, *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend; |
388 | 387 | ||
389 | len = strlen(text); | ||
390 | matches = lexact = lprefix = lsubstr = matchend = exactend = prefixend = substrend = NULL; | 388 | matches = lexact = lprefix = lsubstr = matchend = exactend = prefixend = substrend = NULL; |
391 | for(item = items; item && item->text; item++) | 389 | for(item = items; item && item->text; item++) |
392 | if(!fstrncmp(text, item->text, len + 1)) | 390 | if(!fstrncmp(text, item->text, len + 1)) |
@@ -424,9 +422,8 @@ match(void) { | |||
424 | 422 | ||
425 | size_t | 423 | size_t |
426 | nextrune(int incr) { | 424 | nextrune(int incr) { |
427 | size_t n, len; | 425 | size_t n, len = strlen(text); |
428 | 426 | ||
429 | len = strlen(text); | ||
430 | for(n = cursor + incr; n >= 0 && n < len && (text[n] & 0xc0) == 0x80; n += incr); | 427 | for(n = cursor + incr; n >= 0 && n < len && (text[n] & 0xc0) == 0x80; n += incr); |
431 | return n; | 428 | return n; |
432 | } | 429 | } |
@@ -29,10 +29,9 @@ drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsign | |||
29 | void | 29 | void |
30 | drawtext(DC *dc, const char *text, unsigned long col[ColLast]) { | 30 | drawtext(DC *dc, const char *text, unsigned long col[ColLast]) { |
31 | char buf[256]; | 31 | char buf[256]; |
32 | size_t n, mn; | 32 | size_t mn, n = strlen(text); |
33 | 33 | ||
34 | /* shorten text if necessary */ | 34 | /* shorten text if necessary */ |
35 | n = strlen(text); | ||
36 | for(mn = MIN(n, sizeof buf); textnw(dc, text, mn) > dc->w - dc->font.height/2; mn--) | 35 | for(mn = MIN(n, sizeof buf); textnw(dc, text, mn) > dc->w - dc->font.height/2; mn--) |
37 | if(mn == 0) | 36 | if(mn == 0) |
38 | return; | 37 | return; |
@@ -46,10 +45,8 @@ drawtext(DC *dc, const char *text, unsigned long col[ColLast]) { | |||
46 | 45 | ||
47 | void | 46 | void |
48 | drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]) { | 47 | drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]) { |
49 | int x, y; | 48 | int x = dc->x + dc->font.height/2; |
50 | 49 | int y = dc->y + dc->font.ascent+1; | |
51 | x = dc->x + dc->font.height/2; | ||
52 | y = dc->y + dc->font.ascent+1; | ||
53 | 50 | ||
54 | XSetForeground(dc->dpy, dc->gc, FG(dc, col)); | 51 | XSetForeground(dc->dpy, dc->gc, FG(dc, col)); |
55 | if(dc->font.set) | 52 | if(dc->font.set) |
@@ -64,7 +61,6 @@ void | |||
64 | eprintf(const char *fmt, ...) { | 61 | eprintf(const char *fmt, ...) { |
65 | va_list ap; | 62 | va_list ap; |
66 | 63 | ||
67 | fprintf(stderr, "%s: ", progname); | ||
68 | va_start(ap, fmt); | 64 | va_start(ap, fmt); |
69 | vfprintf(stderr, fmt, ap); | 65 | vfprintf(stderr, fmt, ap); |
70 | va_end(ap); | 66 | va_end(ap); |
@@ -104,7 +100,7 @@ initdc(void) { | |||
104 | DC *dc; | 100 | DC *dc; |
105 | 101 | ||
106 | if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) | 102 | if(!setlocale(LC_CTYPE, "") || !XSupportsLocale()) |
107 | weprintf("no locale support\n"); | 103 | fprintf(stderr, "no locale support\n"); |
108 | if(!(dc = calloc(1, sizeof *dc))) | 104 | if(!(dc = calloc(1, sizeof *dc))) |
109 | eprintf("cannot malloc %u bytes:", sizeof *dc); | 105 | eprintf("cannot malloc %u bytes:", sizeof *dc); |
110 | if(!(dc->dpy = XOpenDisplay(NULL))) | 106 | if(!(dc->dpy = XOpenDisplay(NULL))) |
@@ -119,7 +115,7 @@ void | |||
119 | initfont(DC *dc, const char *fontstr) { | 115 | initfont(DC *dc, const char *fontstr) { |
120 | if(!loadfont(dc, fontstr ? fontstr : DEFFONT)) { | 116 | if(!loadfont(dc, fontstr ? fontstr : DEFFONT)) { |
121 | if(fontstr != NULL) | 117 | if(fontstr != NULL) |
122 | weprintf("cannot load font '%s'\n", fontstr); | 118 | fprintf(stderr, "cannot load font '%s'\n", fontstr); |
123 | if(fontstr == NULL || !loadfont(dc, DEFFONT)) | 119 | if(fontstr == NULL || !loadfont(dc, DEFFONT)) |
124 | eprintf("cannot load font '%s'\n", DEFFONT); | 120 | eprintf("cannot load font '%s'\n", DEFFONT); |
125 | } | 121 | } |
@@ -184,13 +180,3 @@ int | |||
184 | textw(DC *dc, const char *text) { | 180 | textw(DC *dc, const char *text) { |
185 | return textnw(dc, text, strlen(text)) + dc->font.height; | 181 | return textnw(dc, text, strlen(text)) + dc->font.height; |
186 | } | 182 | } |
187 | |||
188 | void | ||
189 | weprintf(const char *fmt, ...) { | ||
190 | va_list ap; | ||
191 | |||
192 | fprintf(stderr, "%s: ", progname); | ||
193 | va_start(ap, fmt); | ||
194 | vfprintf(stderr, fmt, ap); | ||
195 | va_end(ap); | ||
196 | } | ||
@@ -20,18 +20,15 @@ typedef struct { | |||
20 | } font; | 20 | } font; |
21 | } DC; /* draw context */ | 21 | } DC; /* draw context */ |
22 | 22 | ||
23 | unsigned long getcolor(DC *dc, const char *colstr); | ||
24 | void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color); | 23 | void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color); |
25 | void drawtext(DC *dc, const char *text, unsigned long col[ColLast]); | 24 | void drawtext(DC *dc, const char *text, unsigned long col[ColLast]); |
26 | void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]); | 25 | void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]); |
27 | void initfont(DC *dc, const char *fontstr); | 26 | void eprintf(const char *fmt, ...); |
28 | void freedc(DC *dc); | 27 | void freedc(DC *dc); |
28 | unsigned long getcolor(DC *dc, const char *colstr); | ||
29 | DC *initdc(void); | 29 | DC *initdc(void); |
30 | void initfont(DC *dc, const char *fontstr); | ||
30 | void mapdc(DC *dc, Window win, unsigned int w, unsigned int h); | 31 | void mapdc(DC *dc, Window win, unsigned int w, unsigned int h); |
31 | void resizedc(DC *dc, unsigned int w, unsigned int h); | 32 | void resizedc(DC *dc, unsigned int w, unsigned int h); |
32 | int textnw(DC *dc, const char *text, size_t len); | 33 | int textnw(DC *dc, const char *text, size_t len); |
33 | int textw(DC *dc, const char *text); | 34 | int textw(DC *dc, const char *text); |
34 | void eprintf(const char *fmt, ...); | ||
35 | void weprintf(const char *fmt, ...); | ||
36 | |||
37 | const char *progname; | ||