diff options
-rw-r--r-- | drw.c | 19 | ||||
-rw-r--r-- | util.c | 10 | ||||
-rw-r--r-- | util.h | 1 |
3 files changed, 18 insertions, 12 deletions
@@ -65,8 +65,7 @@ drw_create(Display *dpy, int screen, Window root, unsigned int w, unsigned int h | |||
65 | { | 65 | { |
66 | Drw *drw; | 66 | Drw *drw; |
67 | 67 | ||
68 | if (!(drw = calloc(1, sizeof(Drw)))) | 68 | drw = ecalloc(1, sizeof(Drw)); |
69 | return NULL; | ||
70 | drw->dpy = dpy; | 69 | drw->dpy = dpy; |
71 | drw->screen = screen; | 70 | drw->screen = screen; |
72 | drw->root = root; | 71 | drw->root = root; |
@@ -189,16 +188,13 @@ Clr * | |||
189 | drw_clr_create(Drw *drw, const char *clrname) | 188 | drw_clr_create(Drw *drw, const char *clrname) |
190 | { | 189 | { |
191 | Clr *clr; | 190 | Clr *clr; |
192 | Colormap cmap; | ||
193 | Visual *vis; | ||
194 | |||
195 | if (!drw) | 191 | if (!drw) |
196 | return NULL; | 192 | return NULL; |
197 | if (!(clr = calloc(1, sizeof(Clr)))) | 193 | |
198 | return NULL; | 194 | clr = ecalloc(1, sizeof(Clr)); |
199 | cmap = DefaultColormap(drw->dpy, drw->screen); | 195 | if (!XftColorAllocName(drw->dpy, DefaultVisual(drw->dpy, drw->screen), |
200 | vis = DefaultVisual(drw->dpy, drw->screen); | 196 | DefaultColormap(drw->dpy, drw->screen), |
201 | if (!XftColorAllocName(drw->dpy, vis, cmap, clrname, &clr->rgb)) | 197 | clrname, &clr->rgb)) |
202 | die("error, cannot allocate color '%s'\n", clrname); | 198 | die("error, cannot allocate color '%s'\n", clrname); |
203 | clr->pix = clr->rgb.pixel; | 199 | clr->pix = clr->rgb.pixel; |
204 | 200 | ||
@@ -409,8 +405,7 @@ drw_cur_create(Drw *drw, int shape) | |||
409 | 405 | ||
410 | if (!drw) | 406 | if (!drw) |
411 | return NULL; | 407 | return NULL; |
412 | if (!(cur = calloc(1, sizeof(Cur)))) | 408 | cur = ecalloc(1, sizeof(Cur)); |
413 | return NULL; | ||
414 | cur->cursor = XCreateFontCursor(drw->dpy, shape); | 409 | cur->cursor = XCreateFontCursor(drw->dpy, shape); |
415 | 410 | ||
416 | return cur; | 411 | return cur; |
@@ -6,6 +6,16 @@ | |||
6 | 6 | ||
7 | #include "util.h" | 7 | #include "util.h" |
8 | 8 | ||
9 | void * | ||
10 | ecalloc(size_t nmemb, size_t size) | ||
11 | { | ||
12 | void *p; | ||
13 | |||
14 | if (!(p = calloc(nmemb, size))) | ||
15 | perror(NULL); | ||
16 | return p; | ||
17 | } | ||
18 | |||
9 | void | 19 | void |
10 | die(const char *fmt, ...) { | 20 | die(const char *fmt, ...) { |
11 | va_list ap; | 21 | va_list ap; |
@@ -5,3 +5,4 @@ | |||
5 | #define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B)) | 5 | #define BETWEEN(X, A, B) ((A) <= (X) && (X) <= (B)) |
6 | 6 | ||
7 | void die(const char *errstr, ...); | 7 | void die(const char *errstr, ...); |
8 | void *ecalloc(size_t, size_t); | ||