Initial port of xft support to a recent bar version

This commit is contained in:
krypt-n 2014-10-08 21:47:26 +02:00
parent e9cdee9701
commit dc5edd2863
2 changed files with 441 additions and 232 deletions

View File

@ -1,8 +1,8 @@
CC ?= gcc
STRIP ?= strip
CFLAGS = -std=c99 -Os
LDFLAGS = -lxcb -lxcb-xinerama -lxcb-randr
CFDEBUG = -g3 -pedantic -Wall -Wunused-parameter -Wlong-long\
CFLAGS = -std=c99 -I/usr/include/freetype2
LDFLAGS = -lxcb -lxcb-xinerama -lxcb-randr -lX11 -lX11-xcb -lXft -lfreetype -lz -lfontconfig
CFDEBUG = -g3 -pedantic -Wall -Wextra -Wunused-parameter -Wlong-long\
-Wsign-conversion -Wconversion -Wimplicit-function-declaration
EXEC = bar
@ -22,7 +22,6 @@ doc: README.pod
${EXEC}: ${OBJS}
${CC} -o ${EXEC} ${OBJS} ${LDFLAGS}
${STRIP} -s ${EXEC}
debug: ${EXEC}
debug: CC += ${CFDEBUG}

444
bar.c
View File

@ -12,7 +12,10 @@
#include <xcb/xinerama.h>
#include <xcb/randr.h>
// Here be dragons
#include <X11/Xft/Xft.h>
#include <X11/Xlib-xcb.h>
// Here bet dragons
#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) < (b) ? (a) : (b))
@ -20,10 +23,15 @@
typedef struct font_t {
xcb_font_t ptr;
xcb_charinfo_t *width_lut;
XftFont *xft_ft;
int ascent;
int descent, height;
uint16_t char_max;
uint16_t char_min;
xcb_charinfo_t *width_lut;
} font_t;
typedef struct monitor_t {
@ -51,11 +59,10 @@ enum {
ATTR_UNDERL = (1<<1),
};
enum {
ALIGN_L = 0,
enum { ALIGN_L = 0,
ALIGN_C,
ALIGN_R
};
};
enum {
GC_DRAW = 0,
@ -68,11 +75,15 @@ enum {
/* 0 <= FONT_CACHE_SIZE <= 65536 */
#define FONT_CACHE_SIZE 256
static Display *dpy;
static xcb_connection_t *c;
static xcb_screen_t *scr;
static xcb_gcontext_t gc[GC_MAX];
static xcb_visualid_t visual;
static xcb_colormap_t colormap;
static monitor_t *monhead, *montail;
static font_t *font_list[MAX_FONT_COUNT];
static char *font_names[MAX_FONT_COUNT];
@ -86,24 +97,85 @@ static uint32_t fgc, bgc, ugc;
static uint32_t dfgc, dbgc;
static area_stack_t astack;
static XftColor sel_fg;
static XftDraw *xft_draw;
#define MAX_WIDTHS (1 << 16)
static wchar_t xft_char[MAX_WIDTHS];
static char xft_width[MAX_WIDTHS];
void
update_gc (void)
{
xcb_change_gc(c, gc[GC_DRAW], XCB_GC_BACKGROUND | XCB_GC_FOREGROUND, (const uint32_t []){ fgc, bgc });
xcb_change_gc(c, gc[GC_CLEAR], XCB_GC_FOREGROUND, (const uint32_t []){ bgc });
xcb_change_gc(c, gc[GC_ATTR], XCB_GC_FOREGROUND, (const uint32_t []){ ugc });
xcb_change_gc(c, gc[GC_DRAW], XCB_GC_BACKGROUND | XCB_GC_FOREGROUND, (const uint32_t []) {
fgc, bgc
});
xcb_change_gc(c, gc[GC_CLEAR], XCB_GC_FOREGROUND, (const uint32_t []) {
bgc
});
xcb_change_gc(c, gc[GC_ATTR], XCB_GC_FOREGROUND, (const uint32_t []) {
ugc
});
XftColorFree(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), DefaultColormap(dpy, DefaultScreen(dpy)), &sel_fg);
char color[8] = "#ffffff";
snprintf(color, sizeof(color), "#%06X", fgc);
if (!XftColorAllocName (dpy, DefaultVisual(dpy, DefaultScreen(dpy)), DefaultColormap(dpy, DefaultScreen(dpy)), color, &sel_fg)) {
fprintf(stderr, "Couldn't allocate xft font color '%s'\n", color);
}
}
void
fill_rect (xcb_drawable_t d, xcb_gcontext_t gc, int x, int y, int width, int height)
{
xcb_poly_fill_rectangle(c, d, gc, 1, (const xcb_rectangle_t []){ { x, y, width, height } });
xcb_poly_fill_rectangle(c, d, gc, 1, (const xcb_rectangle_t []) {
{
x, y, width, height
}
});
}
int
xft_char_width_slot (wchar_t ch)
{
int slot = ch % MAX_WIDTHS;
while (xft_char[slot] != 0 && xft_char[slot] != ch)
{
slot = (slot + 1) % MAX_WIDTHS;
}
return slot;
}
int xft_char_width (wchar_t ch, font_t *cur_font)
{
int slot = xft_char_width_slot(ch);
if (!xft_char[slot]) {
XGlyphInfo gi;
FT_UInt glyph = XftCharIndex (dpy, cur_font->xft_ft, ch);
XftFontLoadGlyphs (dpy, cur_font->xft_ft, FcFalse, &glyph, 1);
XftGlyphExtents (dpy, cur_font->xft_ft, &glyph, 1, &gi);
XftFontUnloadGlyphs (dpy, cur_font->xft_ft, &glyph, 1);
xft_char[slot] = ch;
xft_width[slot] = gi.xOff;
return gi.xOff;
} else if (xft_char[slot] == ch)
return xft_width[slot];
else
return 0;
}
int
draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
draw_char (monitor_t *mon, font_t *cur_font, int x, int align, wchar_t ch)
{
int ch_width = cur_font->width_lut[ch - cur_font->char_min].character_width;
int ch_width;
if (cur_font->xft_ft) {
ch_width = xft_char_width(ch, cur_font);
} else {
ch_width = cur_font->width_lut[ch - cur_font->char_min].character_width;
}
switch (align) {
case ALIGN_C:
@ -121,11 +193,16 @@ draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
/* Draw the background first */
fill_rect(mon->pixmap, gc[GC_CLEAR], x, by, ch_width, bh);
int y = bh / 2 + cur_font->height / 2- cur_font->descent;
if (cur_font->xft_ft) {
XftDrawString32 (xft_draw, &sel_fg, cur_font->xft_ft, x,y, &ch, 1);
} else {
char c_ = ch > 127 ? ' ' : ch;
/* xcb accepts string in UCS-2 BE, so swap */
ch = (ch >> 8) | (ch << 8);
/* String baseline coordinates */
xcb_image_text_16(c, 1, mon->pixmap, gc[GC_DRAW], x, bh / 2 + cur_font->height / 2 - cur_font->descent, (xcb_char2b_t *)&ch);
xcb_image_text_8(c, 1, mon->pixmap, gc[GC_DRAW], x,y, &c_);
}
/* We can render both at the same time */
if (attrs & ATTR_OVERL)
@ -136,10 +213,50 @@ draw_char (monitor_t *mon, font_t *cur_font, int x, int align, uint16_t ch)
return ch_width;
}
int
utf8decode(char *s, wchar_t *u) {
unsigned char c;
int i, n, rtn;
rtn = 1;
c = *s;
if(~c & 0x80) { /* 0xxxxxxx */
*u = c;
return rtn;
} else if((c & 0xE0) == 0xC0) { /* 110xxxxx */
*u = c & 0x1F;
n = 1;
} else if((c & 0xF0) == 0xE0) { /* 1110xxxx */
*u = c & 0x0F;
n = 2;
} else if((c & 0xF8) == 0xF0) { /* 11110xxx */
*u = c & 0x07;
n = 3;
} else {
goto invalid;
}
for(i = n, ++s; i > 0; --i, ++rtn, ++s) {
c = *s;
if((c & 0xC0) != 0x80) /* 10xxxxxx */
goto invalid;
*u <<= 6;
*u |= c & 0x3F;
}
if((n == 1 && *u < 0x80) ||
(n == 2 && *u < 0x800) ||
(n == 3 && *u < 0x10000) ||
(*u >= 0xD800 && *u <= 0xDFFF)) {
goto invalid;
}
return rtn;
invalid:
*u = 0xFFFD;
return rtn;
}
uint32_t
parse_color (const char *str, char **end, const uint32_t def)
{
xcb_alloc_named_color_reply_t *nc_reply;
xcb_alloc_named_color_reply_t *nc_reply = 0;
int str_len;
uint32_t ret;
@ -177,8 +294,9 @@ parse_color (const char *str, char **end, const uint32_t def)
if (r > 255) r = 255;
if (g > 255) g = 255;
if (b > 255) b = 255;
} else
r = g = b = 0;
} else {
}
return a << 24 | r << 16 | g << 8 | b;
}
@ -213,9 +331,15 @@ set_attribute (const char modifier, const char attribute)
}
switch (modifier) {
case '+': attrs |= (1<<pos); break;
case '-': attrs &=~(1<<pos); break;
case '!': attrs ^= (1<<pos); break;
case '+':
attrs |= (1<<pos);
break;
case '-':
attrs &=~(1<<pos);
break;
case '!':
attrs ^= (1<<pos);
break;
}
}
@ -310,15 +434,16 @@ area_add (char *str, const char *optend, char **end, monitor_t *mon, const int x
/* returns NULL if character cannot be printed */
font_t *
select_drawable_font (const uint16_t c)
select_drawable_font (const wchar_t c)
{
/* if the end is reached without finding an apropriate font, return NULL.
* If the font can draw the character, return it.
*/
for (int i = 0; font_list[i] != NULL; i++) {
font_t *font = font_list[i];
if (c > font->char_min && c < font->char_max &&
font->width_lut[c - font->char_min].character_width != 0)
if ((c > font->char_min && c < font->char_max &&
font->width_lut[c - font->char_min].character_width != 0)||
(font->xft_ft && XftCharExists(dpy, font->xft_ft, c)))
return font;
}
return NULL;
@ -326,7 +451,7 @@ select_drawable_font (const uint16_t c)
/* returns NULL if character cannot be printed */
font_t *
select_drawable_font_cache (uint16_t c)
select_drawable_font_cache (wchar_t c)
{
if (c < FONT_CACHE_SIZE)
return font_cache[c];
@ -352,6 +477,13 @@ parse (char *text)
for (monitor_t *m = monhead; m != NULL; m = m->next)
fill_rect(m->pixmap, gc[GC_CLEAR], 0, 0, m->width, bh);
/* Create xft drawable */
int s = DefaultScreen (dpy);
if (!(xft_draw = XftDrawCreate (dpy, cur_mon->pixmap, DefaultVisual(dpy, s), DefaultColormap(dpy, s)))) {
//if (!(xft_draw = XftDrawCreate (dpy, cur_mon->pixmap, visual_ptr, colormap))) {
fprintf(stderr, "Couldn't create xft drawable\n");
}
for (;;) {
if (*p == '\0' || *p == '\n')
return;
@ -362,9 +494,15 @@ parse (char *text)
p++;
switch (*p++) {
case '+': set_attribute('+', *p++); break;
case '-': set_attribute('-', *p++); break;
case '!': set_attribute('!', *p++); break;
case '+':
set_attribute('+', *p++);
break;
case '-':
set_attribute('-', *p++);
break;
case '!':
set_attribute('!', *p++);
break;
case 'R':
tmp = fgc;
@ -373,9 +511,18 @@ parse (char *text)
update_gc();
break;
case 'l': pos_x = 0; align = ALIGN_L; break;
case 'c': pos_x = 0; align = ALIGN_C; break;
case 'r': pos_x = 0; align = ALIGN_R; break;
case 'l':
pos_x = 0;
align = ALIGN_L;
break;
case 'c':
pos_x = 0;
align = ALIGN_C;
break;
case 'r':
pos_x = 0;
align = ALIGN_R;
break;
case 'A':
button = XCB_BUTTON_INDEX_1;
@ -385,26 +532,46 @@ parse (char *text)
area_add(p, end, &p, cur_mon, pos_x, align, button);
break;
case 'B': bgc = parse_color(p, &p, dbgc); update_gc(); break;
case 'F': fgc = parse_color(p, &p, dfgc); update_gc(); break;
case 'U': ugc = parse_color(p, &p, dbgc); update_gc(); break;
case 'B':
bgc = parse_color(p, &p, dbgc);
update_gc();
break;
case 'F':
fgc = parse_color(p, &p, dfgc);
update_gc();
break;
case 'U':
ugc = parse_color(p, &p, dbgc);
update_gc();
break;
case 'S':
if (*p == '+' && cur_mon->next)
{ cur_mon = cur_mon->next; }
{
cur_mon = cur_mon->next;
}
else if (*p == '-' && cur_mon->prev)
{ cur_mon = cur_mon->prev; }
{
cur_mon = cur_mon->prev;
}
else if (*p == 'f')
{ cur_mon = monhead; }
{
cur_mon = monhead;
}
else if (*p == 'l')
{ cur_mon = montail ? montail : monhead; }
{
cur_mon = montail ? montail : monhead;
}
else if (isdigit(*p))
{ cur_mon = monhead;
for (int i = 0; i != *p-'0' && cur_mon->next; i++)
cur_mon = cur_mon->next;
}
else
{ p++; continue; }
{
p++;
continue;
}
p++;
pos_x = 0;
@ -418,38 +585,26 @@ parse (char *text)
/* Eat the trailing } */
p++;
} else { /* utf-8 -> ucs-2 */
uint8_t *utf = (uint8_t *)p;
uint16_t ucs;
if (utf[0] < 0x80) {
ucs = utf[0];
p += 1;
}
else if ((utf[0] & 0xe0) == 0xc0) {
ucs = (utf[0] & 0x1f) << 6 | (utf[1] & 0x3f);
p += 2;
}
else if ((utf[0] & 0xf0) == 0xe0) {
ucs = (utf[0] & 0xf) << 12 | (utf[1] & 0x3f) << 6 | (utf[2] & 0x3f);
p += 3;
}
else { /* Handle ascii > 0x80 */
ucs = utf[0];
p += 1;
}
cur_font = select_drawable_font(ucs);
wchar_t t;
p += utf8decode(p, &t);
cur_font = select_drawable_font(t);
if (!cur_font)
continue;
xcb_change_gc(c, gc[GC_DRAW] , XCB_GC_FONT, (const uint32_t []){ cur_font->ptr });
int w = draw_char(cur_mon, cur_font, pos_x, align, ucs);
if(cur_font->ptr)
xcb_change_gc(c, gc[GC_DRAW] , XCB_GC_FONT, (const uint32_t []) {
cur_font->ptr
});
int w = draw_char(cur_mon, cur_font, pos_x, align, t);
pos_x += w;
area_shift(cur_mon->window, align, w);
}
}
XftDrawDestroy (xft_draw);
}
font_t *
@ -462,17 +617,13 @@ font_load (const char *str)
font = xcb_generate_id(c);
cookie = xcb_open_font_checked(c, font, strlen(str), str);
if (xcb_request_check (c, cookie)) {
fprintf(stderr, "Could not load font %s\n", str);
return NULL;
}
font_t *ret = calloc(1, sizeof(font_t));
if (!ret)
return NULL;
cookie = xcb_open_font_checked(c, font, strlen(str), str);
if (!xcb_request_check (c, cookie)) {
queryreq = xcb_query_font(c, font);
font_info = xcb_query_font_reply(c, queryreq, NULL);
@ -482,6 +633,14 @@ font_load (const char *str)
ret->char_max = font_info->max_byte1 << 8 | font_info->max_char_or_byte2;
ret->char_min = font_info->min_byte1 << 8 | font_info->min_char_or_byte2;
ret->width_lut = xcb_query_font_char_infos(font_info);
} else if (ret->xft_ft = XftFontOpenName (dpy, DefaultScreen(dpy), str)) {
ret->ascent = ret->xft_ft->ascent;
ret->descent = ret->xft_ft->descent;
ret->height = ret->ascent + ret->descent;
} else {
fprintf(stderr, "Could not load font %s\n", str);
return NULL;
}
return ret;
}
@ -544,7 +703,9 @@ set_ewmh_atoms (void)
xcb_change_property(c, XCB_PROP_MODE_REPLACE, mon->window, atom_list[NET_WM_WINDOW_TYPE], XCB_ATOM_ATOM, 32, 1, &atom_list[NET_WM_WINDOW_TYPE_DOCK]);
xcb_change_property(c, XCB_PROP_MODE_APPEND, mon->window, atom_list[NET_WM_STATE], XCB_ATOM_ATOM, 32, 2, &atom_list[NET_WM_STATE_STICKY]);
xcb_change_property(c, XCB_PROP_MODE_REPLACE, mon->window, atom_list[NET_WM_DESKTOP], XCB_ATOM_CARDINAL, 32, 1, (const uint32_t []){ -1 } );
xcb_change_property(c, XCB_PROP_MODE_REPLACE, mon->window, atom_list[NET_WM_DESKTOP], XCB_ATOM_CARDINAL, 32, 1, (const uint32_t []) {
-1
} );
xcb_change_property(c, XCB_PROP_MODE_REPLACE, mon->window, atom_list[NET_WM_STRUT_PARTIAL], XCB_ATOM_CARDINAL, 32, 12, strut);
xcb_change_property(c, XCB_PROP_MODE_REPLACE, mon->window, atom_list[NET_WM_STRUT], XCB_ATOM_CARDINAL, 32, 4, strut);
}
@ -569,14 +730,16 @@ monitor_new (int x, int y, int width, int height)
ret->window = xcb_generate_id(c);
int depth = (visual == scr->root_visual) ? XCB_COPY_FROM_PARENT : 32;
xcb_create_window(c, depth, ret->window, scr->root,
xcb_create_window(c, XCB_COPY_FROM_PARENT, ret->window, scr->root,
x, win_y, width, bh, 0,
XCB_WINDOW_CLASS_INPUT_OUTPUT, visual,
XCB_CW_BACK_PIXEL | XCB_CW_BORDER_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK | XCB_CW_COLORMAP,
(const uint32_t []){ bgc, bgc, dock, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS, colormap });
XCB_WINDOW_CLASS_INPUT_OUTPUT, scr->root_visual,
XCB_CW_BACK_PIXEL | XCB_CW_EVENT_MASK ,
(const uint32_t []) {
bgc, XCB_EVENT_MASK_EXPOSURE | XCB_EVENT_MASK_BUTTON_PRESS
});
ret->pixmap = xcb_generate_id(c);
xcb_create_pixmap(c, depth, ret->pixmap, ret->window, width, bh);
xcb_create_pixmap(c, scr->root_depth, ret->pixmap, ret->window, width, bh);
return ret;
}
@ -722,7 +885,9 @@ get_randr_monitors (void)
}
/* There's no need to handle rotated screens here (see #69) */
rects[i] = (xcb_rectangle_t){ ci_reply->x, ci_reply->y, ci_reply->width, ci_reply->height };
rects[i] = (xcb_rectangle_t) {
ci_reply->x, ci_reply->y, ci_reply->width, ci_reply->height
};
free(ci_reply);
@ -795,20 +960,26 @@ get_xinerama_monitors (void)
xcb_visualid_t
get_visual (void)
{
visual = scr->root_visual;
return visual;
/*
xcb_depth_iterator_t iter;
iter = xcb_screen_allowed_depths_iterator(scr);
*/
/* Try to find a RGBA visual */
while (iter.rem) {
/* while (iter.rem) {
xcb_visualtype_t *vis = xcb_depth_visuals(iter.data);
if (iter.data->depth == 32)
if (iter.data->depth == 32) {
visual_ptr = vis;
return vis->visual_id;
}
xcb_depth_next(&iter);
}
*/
/* Fallback to the default one */
return scr->root_visual;
}
@ -816,21 +987,24 @@ get_visual (void)
void
xconn (void)
{
/* Connect to X */
c = xcb_connect (NULL, NULL);
if (xcb_connection_has_error(c)) {
fprintf(stderr, "Couldn't connect to X\n");
exit(EXIT_FAILURE);
if ((dpy = XOpenDisplay(0)) == NULL) {
fprintf (stderr, "Couldnt open display\n");
}
if ((c = XGetXCBConnection(dpy)) == NULL) {
fprintf (stderr, "Couldnt connect to X\n");
exit (EXIT_FAILURE);
}
/* Grab infos from the first screen */
scr = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
colormap = scr->default_colormap;
/* Try to get a RGBA visual and build the colormap for that */
visual = get_visual();
// visual = get_visual();
// colormap = xcb_generate_id(c);
// xcb_create_colormap(c, XCB_COLORMAP_ALLOC_NONE, colormap, scr->root, visual);
colormap = xcb_generate_id(c);
xcb_create_colormap(c, XCB_COLORMAP_ALLOC_NONE, colormap, scr->root, visual);
}
void
@ -867,25 +1041,25 @@ init (void)
/* Initialiaze monitor list head and tail */
monhead = montail = NULL;
/* Check if RandR is present */
qe_reply = xcb_get_extension_data(c, &xcb_randr_id);
// /* Check if RandR is present */
//qe_reply = xcb_get_extension_data(c, &xcb_randr_id);
if (qe_reply && qe_reply->present) {
get_randr_monitors();
} else {
qe_reply = xcb_get_extension_data(c, &xcb_xinerama_id);
/* Check if Xinerama extension is present and active */
if (qe_reply && qe_reply->present) {
xcb_xinerama_is_active_reply_t *xia_reply;
xia_reply = xcb_xinerama_is_active_reply(c, xcb_xinerama_is_active(c), NULL);
if (xia_reply && xia_reply->state)
get_xinerama_monitors();
free(xia_reply);
}
}
//if (qe_reply && qe_reply->present) {
//get_randr_monitors();
//} else {
//qe_reply = xcb_get_extension_data(c, &xcb_xinerama_id);
//
///* Check if Xinerama extension is present and active */
//if (qe_reply && qe_reply->present) {
//xcb_xinerama_is_active_reply_t *xia_reply;
//xia_reply = xcb_xinerama_is_active_reply(c, xcb_xinerama_is_active(c), NULL);
//
//if (xia_reply && xia_reply->state)
//get_xinerama_monitors();
//
//free(xia_reply);
//}
//}
if (!monhead) {
/* If I fits I sits */
@ -914,13 +1088,19 @@ init (void)
/* Create the gc for drawing */
gc[GC_DRAW] = xcb_generate_id(c);
xcb_create_gc(c, gc[GC_DRAW], monhead->pixmap, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, (const uint32_t []){ fgc, bgc });
xcb_create_gc(c, gc[GC_DRAW], monhead->pixmap, XCB_GC_FOREGROUND | XCB_GC_BACKGROUND, (const uint32_t []) {
fgc, bgc
});
gc[GC_CLEAR] = xcb_generate_id(c);
xcb_create_gc(c, gc[GC_CLEAR], monhead->pixmap, XCB_GC_FOREGROUND, (const uint32_t []){ bgc });
xcb_create_gc(c, gc[GC_CLEAR], monhead->pixmap, XCB_GC_FOREGROUND, (const uint32_t []) {
bgc
});
gc[GC_ATTR] = xcb_generate_id(c);
xcb_create_gc(c, gc[GC_ATTR], monhead->pixmap, XCB_GC_FOREGROUND, (const uint32_t []){ ugc });
xcb_create_gc(c, gc[GC_ATTR], monhead->pixmap, XCB_GC_FOREGROUND, (const uint32_t []) {
ugc
});
/* Make the bar visible and clear the pixmap */
for (monitor_t *mon = monhead; mon; mon = mon->next) {
@ -928,6 +1108,12 @@ init (void)
xcb_map_window(c, mon->window);
}
char color[8] = "#ffffff";
snprintf(color, sizeof(color), "#%06X", fgc);
if (!XftColorAllocName (dpy, DefaultVisual(dpy, DefaultScreen(dpy)), DefaultColormap(dpy, DefaultScreen(dpy)), color, &sel_fg)) {
fprintf(stderr, "Couldn't allocate xft font color '%s'\n", color);
}
xcb_flush(c);
}
@ -935,7 +1121,12 @@ void
cleanup (void)
{
for (int i = 0; font_list[i]; i++) {
if (font_list[i]->xft_ft) {
XftFontClose (dpy, font_list[i]->xft_ft);
}
else {
xcb_close_font(c, font_list[i]->ptr);
}
free(font_list[i]);
font_list[i] = NULL;
}
@ -948,7 +1139,8 @@ cleanup (void)
monhead = next;
}
xcb_free_colormap(c, colormap);
XftColorFree(dpy, DefaultVisual(dpy, DefaultScreen(dpy)), DefaultColormap(dpy, DefaultScreen(dpy)), &sel_fg);
//xcb_free_colormap(c, colormap);
if (gc[GC_DRAW])
xcb_free_gc(c, gc[GC_DRAW]);
@ -991,14 +1183,17 @@ parse_geometry_string (char *str, int *tmp)
if (*p == 'x') {
if (i > 0) /* The 'x' must precede '+' */
break;
i++; p++; continue;
i++;
p++;
continue;
}
if (*p == '+') {
if (i < 1) /* Stray '+', skip the first two fields */
i = 2;
else
i++;
p++; continue;
p++;
continue;
}
/* A digit must follow */
if (!isdigit(*p)) {
@ -1038,7 +1233,6 @@ parse_font_list (char *str)
tok = strtok(NULL, ",");
}
}
int
main (int argc, char **argv)
{
@ -1082,14 +1276,30 @@ main (int argc, char **argv)
"\t-B Set background color in #AARRGGBB\n"
"\t-F Set foreground color in #AARRGGBB\n", argv[0]);
exit (EXIT_SUCCESS);
case 'g': (void)parse_geometry_string(optarg, geom_v); break;
case 'p': permanent = true; break;
case 'b': topbar = false; break;
case 'd': dock = true; break;
case 'f': parse_font_list(optarg); break;
case 'u': bu = strtoul(optarg, NULL, 10); break;
case 'B': dbgc = bgc = parse_color(optarg, NULL, scr->black_pixel); break;
case 'F': dfgc = fgc = parse_color(optarg, NULL, scr->white_pixel); break;
case 'g':
(void)parse_geometry_string(optarg, geom_v);
break;
case 'p':
permanent = true;
break;
case 'b':
topbar = false;
break;
case 'd':
dock = true;
break;
case 'f':
parse_font_list(optarg);
break;
case 'u':
bu = strtoul(optarg, NULL, 10);
break;
case 'B':
dbgc = bgc = parse_color(optarg, NULL, scr->black_pixel);
break;
case 'F':
dfgc = fgc = parse_color(optarg, NULL, scr->white_pixel);
break;
}
}