aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dmenu.c7
-rw-r--r--draw.c24
-rw-r--r--draw.h9
3 files changed, 10 insertions, 30 deletions
diff --git a/dmenu.c b/dmenu.c
index b6f1ef2..40b220c 100644
--- a/dmenu.c
+++ b/dmenu.c
@@ -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
384void 383void
385match(void) { 384match(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
425size_t 423size_t
426nextrune(int incr) { 424nextrune(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}
diff --git a/draw.c b/draw.c
index d35d4c2..f9b8957 100644
--- a/draw.c
+++ b/draw.c
@@ -29,10 +29,9 @@ drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsign
29void 29void
30drawtext(DC *dc, const char *text, unsigned long col[ColLast]) { 30drawtext(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
47void 46void
48drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]) { 47drawtextn(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
64eprintf(const char *fmt, ...) { 61eprintf(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
119initfont(DC *dc, const char *fontstr) { 115initfont(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
184textw(DC *dc, const char *text) { 180textw(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
188void
189weprintf(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}
diff --git a/draw.h b/draw.h
index ac3943f..247c0b3 100644
--- a/draw.h
+++ b/draw.h
@@ -20,18 +20,15 @@ typedef struct {
20 } font; 20 } font;
21} DC; /* draw context */ 21} DC; /* draw context */
22 22
23unsigned long getcolor(DC *dc, const char *colstr);
24void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color); 23void drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color);
25void drawtext(DC *dc, const char *text, unsigned long col[ColLast]); 24void drawtext(DC *dc, const char *text, unsigned long col[ColLast]);
26void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]); 25void drawtextn(DC *dc, const char *text, size_t n, unsigned long col[ColLast]);
27void initfont(DC *dc, const char *fontstr); 26void eprintf(const char *fmt, ...);
28void freedc(DC *dc); 27void freedc(DC *dc);
28unsigned long getcolor(DC *dc, const char *colstr);
29DC *initdc(void); 29DC *initdc(void);
30void initfont(DC *dc, const char *fontstr);
30void mapdc(DC *dc, Window win, unsigned int w, unsigned int h); 31void mapdc(DC *dc, Window win, unsigned int w, unsigned int h);
31void resizedc(DC *dc, unsigned int w, unsigned int h); 32void resizedc(DC *dc, unsigned int w, unsigned int h);
32int textnw(DC *dc, const char *text, size_t len); 33int textnw(DC *dc, const char *text, size_t len);
33int textw(DC *dc, const char *text); 34int textw(DC *dc, const char *text);
34void eprintf(const char *fmt, ...);
35void weprintf(const char *fmt, ...);
36
37const char *progname;