| @@ -20,7 +20,6 @@ |
| 20 | 20 | | #define _WINDOW_CONFIG |
| 21 | 21 | | #include "config.h" |
| 22 | 22 | | #include "icon/data.h" |
| 23 | | − | #include "utf8.h" |
| 24 | 23 | | |
| 25 | 24 | | #include <stdlib.h> |
| 26 | 25 | | #include <string.h> |
| @@ -30,6 +29,12 @@ |
| 30 | 29 | | #include <X11/Xatom.h> |
| 31 | 30 | | #include <X11/Xresource.h> |
| 32 | 31 | | |
| 32 | + | #if HAVE_LIBFONTS |
| 33 | + | #include "utf8.h" |
| 34 | + | static XftFont *font; |
| 35 | + | static double fontsize; |
| 36 | + | #endif |
| 37 | + | |
| 33 | 38 | | #define RES_CLASS "Nsxiv" |
| 34 | 39 | | |
| 35 | 40 | | enum { |
| @@ -47,15 +52,14 @@ static struct { |
| 47 | 52 | | |
| 48 | 53 | | static GC gc; |
| 49 | 54 | | |
| 50 | | − | static XftFont *font; |
| 51 | | − | static int fontheight; |
| 52 | | − | static double fontsize; |
| 53 | 55 | | static int barheight; |
| 54 | 56 | | |
| 55 | 57 | | Atom atoms[ATOM_COUNT]; |
| 56 | 58 | | |
| 59 | + | #if HAVE_LIBFONTS |
| 57 | 60 | | void win_init_font(const win_env_t *e, const char *fontstr) |
| 58 | 61 | | { |
| 62 | + | int fontheight = 0; |
| 59 | 63 | | if ((font = XftFontOpenName(e->dpy, e->scr, fontstr)) == NULL) |
| 60 | 64 | | error(EXIT_FAILURE, 0, "Error loading font '%s'", fontstr); |
| 61 | 65 | | fontheight = font->ascent + font->descent; |
| @@ -64,13 +68,19 @@ void win_init_font(const win_env_t *e, const char *fontstr) |
| 64 | 68 | | XftFontClose(e->dpy, font); |
| 65 | 69 | | } |
| 66 | 70 | | |
| 67 | | − | void win_alloc_color(const win_env_t *e, const char *name, XftColor *col) |
| 71 | + | void xft_alloc_color(const win_env_t *e, const char *name, XftColor *col) |
| 68 | 72 | | { |
| 69 | | − | if (!XftColorAllocName(e->dpy, e->vis, |
| 70 | | − | e->cmap, name, col)) |
| 71 | | − | { |
| 73 | + | if (!XftColorAllocName(e->dpy, e->vis, e->cmap, name, col)) |
| 72 | 74 | | error(EXIT_FAILURE, 0, "Error allocating color '%s'", name); |
| 73 | | − | } |
| 75 | + | } |
| 76 | + | #endif /* HAVE_LIBFONTS */ |
| 77 | + | |
| 78 | + | void win_alloc_color(const win_env_t *e, const char *name, unsigned long *pixel) |
| 79 | + | { |
| 80 | + | XColor screen, exact; |
| 81 | + | if (!XAllocNamedColor(e->dpy, e->cmap, name, &screen, &exact)) |
| 82 | + | error(EXIT_FAILURE, 0, "Error allocating color '%s'", name); |
| 83 | + | *pixel = exact.pixel; |
| 74 | 84 | | } |
| 75 | 85 | | |
| 76 | 86 | | const char* win_res(XrmDatabase db, const char *name, const char *def) |
| @@ -94,7 +104,10 @@ const char* win_res(XrmDatabase db, const char *name, const char *def) |
| 94 | 104 | | void win_init(win_t *win) |
| 95 | 105 | | { |
| 96 | 106 | | win_env_t *e; |
| 97 | | − | const char *win_bg, *win_fg, *bar_bg, *bar_fg, *mrk_fg, *f; |
| 107 | + | const char *win_bg, *win_fg, *mrk_fg; |
| 108 | + | #if HAVE_LIBFONTS |
| 109 | + | const char *bar_fg, *bar_bg, *f; |
| 110 | + | #endif |
| 98 | 111 | | char *res_man; |
| 99 | 112 | | XrmDatabase db; |
| 100 | 113 | | XVisualInfo vis; |
| @@ -131,20 +144,22 @@ void win_init(win_t *win) |
| 131 | 144 | | res_man = XResourceManagerString(e->dpy); |
| 132 | 145 | | db = res_man != NULL ? XrmGetStringDatabase(res_man) : None; |
| 133 | 146 | | |
| 134 | | − | f = win_res(db, RES_CLASS ".bar.font", "monospace-8"); |
| 135 | | − | win_init_font(e, f); |
| 136 | | − | |
| 137 | 147 | | win_bg = win_res(db, RES_CLASS ".window.background", "white"); |
| 138 | 148 | | win_fg = win_res(db, RES_CLASS ".window.foreground", "black"); |
| 139 | | − | bar_bg = win_res(db, RES_CLASS ".bar.background", win_bg); |
| 140 | | − | bar_fg = win_res(db, RES_CLASS ".bar.foreground", win_fg); |
| 141 | 149 | | mrk_fg = win_res(db, RES_CLASS ".mark.foreground", win_fg); |
| 142 | 150 | | win_alloc_color(e, win_bg, &win->win_bg); |
| 143 | 151 | | win_alloc_color(e, win_fg, &win->win_fg); |
| 144 | | − | win_alloc_color(e, bar_bg, &win->bar_bg); |
| 145 | | − | win_alloc_color(e, bar_fg, &win->bar_fg); |
| 146 | 152 | | win_alloc_color(e, mrk_fg, &win->mrk_fg); |
| 147 | 153 | | |
| 154 | + | #if HAVE_LIBFONTS |
| 155 | + | bar_bg = win_res(db, RES_CLASS ".bar.background", win_bg); |
| 156 | + | bar_fg = win_res(db, RES_CLASS ".bar.foreground", win_fg); |
| 157 | + | xft_alloc_color(e, bar_bg, &win->bar_bg); |
| 158 | + | xft_alloc_color(e, bar_fg, &win->bar_fg); |
| 159 | + | |
| 160 | + | f = win_res(db, RES_CLASS ".bar.font", "monospace-8"); |
| 161 | + | win_init_font(e, f); |
| 162 | + | |
| 148 | 163 | | win->bar.l.size = BAR_L_LEN; |
| 149 | 164 | | win->bar.r.size = BAR_R_LEN; |
| 150 | 165 | | /* 3 padding bytes needed by utf8_decode */ |
| @@ -153,6 +168,7 @@ void win_init(win_t *win) |
| 153 | 168 | | win->bar.r.buf = emalloc(win->bar.r.size + 3); |
| 154 | 169 | | win->bar.r.buf[0] = '\0'; |
| 155 | 170 | | win->bar.h = options->hide_bar ? 0 : barheight; |
| 171 | + | #endif /* HAVE_LIBFONTS */ |
| 156 | 172 | | |
| 157 | 173 | | INIT_ATOM_(WM_DELETE_WINDOW); |
| 158 | 174 | | INIT_ATOM_(_NET_WM_NAME); |
| @@ -306,7 +322,7 @@ void win_open(win_t *win) |
| 306 | 322 | | win->buf.h = e->scrh; |
| 307 | 323 | | win->buf.pm = XCreatePixmap(e->dpy, win->xwin, |
| 308 | 324 | | win->buf.w, win->buf.h, e->depth); |
| 309 | | − | XSetForeground(e->dpy, gc, win->win_bg.pixel); |
| 325 | + | XSetForeground(e->dpy, gc, win->win_bg); |
| 310 | 326 | | XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h); |
| 311 | 327 | | XSetWindowBackgroundPixmap(e->dpy, win->xwin, win->buf.pm); |
| 312 | 328 | | |
| @@ -388,10 +404,11 @@ void win_clear(win_t *win) |
| 388 | 404 | | win->buf.pm = XCreatePixmap(e->dpy, win->xwin, |
| 389 | 405 | | win->buf.w, win->buf.h, e->depth); |
| 390 | 406 | | } |
| 391 | | − | XSetForeground(e->dpy, gc, win->win_bg.pixel); |
| 407 | + | XSetForeground(e->dpy, gc, win->win_bg); |
| 392 | 408 | | XFillRectangle(e->dpy, win->buf.pm, gc, 0, 0, win->buf.w, win->buf.h); |
| 393 | 409 | | } |
| 394 | 410 | | |
| 411 | + | #if HAVE_LIBFONTS |
| 395 | 412 | | #define TEXTWIDTH(win, text, len) \ |
| 396 | 413 | | win_draw_text(win, NULL, NULL, 0, 0, text, len, 0) |
| 397 | 414 | | |
| @@ -448,7 +465,7 @@ void win_draw_bar(win_t *win) |
| 448 | 465 | | XSetForeground(e->dpy, gc, win->bar_bg.pixel); |
| 449 | 466 | | XFillRectangle(e->dpy, win->buf.pm, gc, 0, win->h, win->w, win->bar.h); |
| 450 | 467 | | |
| 451 | | − | XSetForeground(e->dpy, gc, win->win_bg.pixel); |
| 468 | + | XSetForeground(e->dpy, gc, win->win_bg); |
| 452 | 469 | | XSetBackground(e->dpy, gc, win->bar_bg.pixel); |
| 453 | 470 | | |
| 454 | 471 | | if ((len = strlen(r->buf)) > 0) { |
| @@ -465,6 +482,9 @@ void win_draw_bar(win_t *win) |
| 465 | 482 | | } |
| 466 | 483 | | XftDrawDestroy(d); |
| 467 | 484 | | } |
| 485 | + | #else |
| 486 | + | void win_draw_bar(win_t *win){} |
| 487 | + | #endif /* HAVE_LIBFONTS */ |
| 468 | 488 | | |
| 469 | 489 | | void win_draw(win_t *win) |
| 470 | 490 | | { |