Wmfs: Make Xft font optional #1
This commit is contained in:
parent
9bda577718
commit
5d208730cd
@ -166,13 +166,19 @@ mouse_section(MouseBinding mb[], struct conf_sec **sec)
|
||||
static void
|
||||
conf_misc_section(void)
|
||||
{
|
||||
bool xft = False;
|
||||
int pad = 12;
|
||||
uint opacity = 255;
|
||||
struct conf_sec *sec;
|
||||
|
||||
sec = fetch_section_first(NULL, "misc");
|
||||
|
||||
#ifdef HAVE_XFT
|
||||
xft = True;
|
||||
#endif /* HAVE_XFT */
|
||||
|
||||
conf.font = fetch_opt_first(sec, "sans-9", "font").str;
|
||||
conf.use_xft = fetch_opt_first(sec, (xft ? "true" : "false"), "use_xft").boolean;
|
||||
conf.raisefocus = fetch_opt_first(sec, "false", "raisefocus").boolean;
|
||||
conf.focus_fmouse = fetch_opt_first(sec, "true", "focus_follow_mouse").boolean;
|
||||
conf.focus_fmov = fetch_opt_first(sec, "false", "focus_follow_movement").boolean;
|
||||
@ -192,7 +198,6 @@ conf_misc_section(void)
|
||||
if(pad > 24 || pad < 1)
|
||||
{
|
||||
warnx("configuration : pad value (%d) incorrect.", pad);
|
||||
|
||||
pad = 12;
|
||||
}
|
||||
|
||||
|
||||
59
src/draw.c
59
src/draw.c
@ -90,8 +90,6 @@ draw_text(Drawable d, int x, int y, char* fg, char *str)
|
||||
void
|
||||
draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image_ofset, int y_image_ofset)
|
||||
{
|
||||
XftColor xftcolor;
|
||||
XftDraw *xftd;
|
||||
#ifdef HAVE_IMLIB
|
||||
char *ostr = NULL;
|
||||
int i, ni, sw = 0;
|
||||
@ -107,7 +105,6 @@ draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image
|
||||
|
||||
/* To draw image everywhere we can draw text */
|
||||
#ifdef HAVE_IMLIB
|
||||
|
||||
ostr = xstrdup(str);
|
||||
textlen = strlen(ostr);
|
||||
|
||||
@ -123,19 +120,34 @@ draw_image_ofset_text(Drawable d, int x, int y, char* fg, char *str, int x_image
|
||||
}
|
||||
#endif /* HAVE_IMLIB */
|
||||
|
||||
/* Transform X Drawable -> Xft Drawable */
|
||||
xftd = XftDrawCreate(dpy, d, DefaultVisual(dpy, SCREEN), DefaultColormap(dpy, SCREEN));
|
||||
#ifdef HAVE_XFT
|
||||
if(conf.use_xft)
|
||||
{
|
||||
XftColor xftcolor;
|
||||
XftDraw *xftd;
|
||||
|
||||
/* Alloc text color */
|
||||
XftColorAllocName(dpy, DefaultVisual(dpy, SCREEN),
|
||||
DefaultColormap(dpy, SCREEN), fg, &xftcolor);
|
||||
/* Transform X Drawable -> Xft Drawable */
|
||||
xftd = XftDrawCreate(dpy, d, DefaultVisual(dpy, SCREEN), DefaultColormap(dpy, SCREEN));
|
||||
|
||||
XftDrawStringUtf8(xftd, &xftcolor, font, x, y, (FcChar8 *)str, strlen(str));
|
||||
/* Alloc text color */
|
||||
XftColorAllocName(dpy, DefaultVisual(dpy, SCREEN),
|
||||
DefaultColormap(dpy, SCREEN), fg, &xftcolor);
|
||||
|
||||
/* Free the text color and XftDraw */
|
||||
XftColorFree(dpy, DefaultVisual(dpy, SCREEN), DefaultColormap(dpy, SCREEN), &xftcolor);
|
||||
XftDrawStringUtf8(xftd, &xftcolor, font.font, x, y, (FcChar8 *)str, strlen(str));
|
||||
|
||||
/* Free the text color and XftDraw */
|
||||
XftColorFree(dpy, DefaultVisual(dpy, SCREEN), DefaultColormap(dpy, SCREEN), &xftcolor);
|
||||
|
||||
XftDrawDestroy(xftd);
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_XFT */
|
||||
{
|
||||
/* Use font set */
|
||||
XSetForeground(dpy, gc, getcolor(fg));
|
||||
XmbDrawString(dpy, d, font.fontset, gc, x, y, str, strlen(str));
|
||||
}
|
||||
|
||||
XftDrawDestroy(xftd);
|
||||
|
||||
#ifdef HAVE_IMLIB
|
||||
if(strstr(ostr, "i["))
|
||||
@ -199,7 +211,7 @@ draw_graph(Drawable dr, int x, int y, int w, int h, uint color, char *data)
|
||||
ushort
|
||||
textw(char *text)
|
||||
{
|
||||
XGlyphInfo gl;
|
||||
ushort ret = 0;
|
||||
#ifdef HAVE_IMLIB
|
||||
char *ostr = NULL;
|
||||
ImageAttr im[128];
|
||||
@ -209,9 +221,7 @@ textw(char *text)
|
||||
if(!text)
|
||||
return 0;
|
||||
|
||||
|
||||
#ifdef HAVE_IMLIB
|
||||
|
||||
ostr = xstrdup(text);
|
||||
textlen = strlen(ostr);
|
||||
|
||||
@ -219,7 +229,22 @@ textw(char *text)
|
||||
parse_image_block(im, text);
|
||||
#endif /* HAVE_IMLIB */
|
||||
|
||||
XftTextExtentsUtf8(dpy, font, (FcChar8 *)text, strlen(text), &gl);
|
||||
#ifdef HAVE_XFT
|
||||
if(conf.use_xft)
|
||||
{
|
||||
XGlyphInfo gl;
|
||||
|
||||
XftTextExtentsUtf8(dpy, font.font, (FcChar8 *)text, strlen(text), &gl);
|
||||
ret = gl.width + font.de;
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_XFT */
|
||||
{
|
||||
XRectangle r;
|
||||
|
||||
XmbTextExtents(font.fontset, text, strlen(text), NULL, &r);
|
||||
ret = r.width;
|
||||
}
|
||||
|
||||
#ifdef HAVE_IMLIB
|
||||
if(strstr(ostr, "i["))
|
||||
@ -228,5 +253,5 @@ textw(char *text)
|
||||
free(ostr);
|
||||
#endif /* HAVE_IMLIB */
|
||||
|
||||
return gl.width + font->descent;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -313,7 +313,7 @@ frame_update(Client *c)
|
||||
if(TBARH - BORDH)
|
||||
barwin_draw_text(c->titlebar,
|
||||
(c->frame_geo.width >> 1) - (textw(c->title) >> 1),
|
||||
((font->height - font->descent) + ((TBARH - font->height) >> 1)),
|
||||
((font.height - font.de) + ((TBARH - font.height) >> 1)),
|
||||
c->title);
|
||||
|
||||
return;
|
||||
|
||||
44
src/init.c
44
src/init.c
@ -60,12 +60,46 @@ const func_name_list_t layout_list[] =
|
||||
static void
|
||||
init_font(void)
|
||||
{
|
||||
font = XftFontOpenName(dpy, SCREEN, conf.font);
|
||||
|
||||
if(!font)
|
||||
#ifdef HAVE_XFT
|
||||
if(conf.use_xft)
|
||||
{
|
||||
warnx("WMFS Error: Cannot initialize font");
|
||||
font = XftFontOpenName(dpy, SCREEN, "sans-10");
|
||||
if(!(font.font = XftFontOpenName(dpy, SCREEN, conf.font)))
|
||||
{
|
||||
warnx("WMFS Error: Cannot initialize Xft font");
|
||||
font.font = XftFontOpenName(dpy, SCREEN, "sans-10");
|
||||
}
|
||||
|
||||
font.de = font.font->descent;
|
||||
font.as = font.font->ascent;
|
||||
font.height = font.font->height;
|
||||
}
|
||||
else
|
||||
#endif /* HAVE_XFT */
|
||||
{
|
||||
char **misschar, **names, *defstring;
|
||||
int d;
|
||||
XFontStruct **xfs = NULL;
|
||||
|
||||
if(!conf.font)
|
||||
conf.font = xstrdup("fixed");
|
||||
|
||||
/* Using Font Set */
|
||||
if(!(font.fontset = XCreateFontSet(dpy, conf.font, &misschar, &d, &defstring)))
|
||||
{
|
||||
warnx("Can't load font '%s'", conf.font);
|
||||
font.fontset = XCreateFontSet(dpy, "fixed", &misschar, &d, &defstring);
|
||||
}
|
||||
|
||||
XFontsOfFontSet(font.fontset, &xfs, &names);
|
||||
|
||||
font.as = xfs[0]->max_bounds.ascent;
|
||||
font.de = xfs[0]->max_bounds.descent;
|
||||
font.width = xfs[0]->max_bounds.width;
|
||||
|
||||
font.height = font.as + font.de;
|
||||
|
||||
if(misschar)
|
||||
XFreeStringList(misschar);
|
||||
}
|
||||
|
||||
/* Set font in _WMFS_FONT for eventual status tools */
|
||||
|
||||
@ -402,6 +402,7 @@ typedef struct
|
||||
|
||||
/* Misc option */
|
||||
char *font;
|
||||
bool use_xft;
|
||||
uint opacity;
|
||||
bool raisefocus;
|
||||
bool focus_fmouse;
|
||||
@ -533,6 +534,12 @@ typedef struct
|
||||
int nrule;
|
||||
} Conf;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int as, de, width, height;
|
||||
XftFont *font;
|
||||
XFontSet fontset;
|
||||
} FontStruct;
|
||||
typedef struct
|
||||
{
|
||||
int x, y, w, h;
|
||||
|
||||
@ -98,7 +98,13 @@ quit(void)
|
||||
|
||||
systray_freeicons();
|
||||
|
||||
XftFontClose(dpy, font);
|
||||
#ifdef HAVE_XFT
|
||||
if(conf.use_xft)
|
||||
XftFontClose(dpy, font.font);
|
||||
else
|
||||
#endif /* HAVE_XFT */
|
||||
XFreeFontSet(dpy, font.fontset);
|
||||
|
||||
for(i = 0; i < CurLast; ++i)
|
||||
XFreeCursor(dpy, cursor[i]);
|
||||
XFreeGC(dpy, gc_stipple);
|
||||
|
||||
@ -84,8 +84,8 @@
|
||||
#define ROOT RootWindow(dpy, SCREEN)
|
||||
#define MAXH DisplayHeight(dpy, DefaultScreen(dpy))
|
||||
#define MAXW DisplayWidth(dpy, DefaultScreen(dpy))
|
||||
#define INFOBARH ((conf.bars.height > 0) ? conf.bars.height : (font->height * 1.5))
|
||||
#define FHINFOBAR ((font->height - font->descent) + (((int)INFOBARH - font->height) >> 1))
|
||||
#define INFOBARH ((conf.bars.height > 0) ? conf.bars.height : (font.height * 1.5))
|
||||
#define FHINFOBAR ((font.height - font.de) + (((int)INFOBARH - font.height) >> 1))
|
||||
#define SHADH (1)
|
||||
#define BORDH conf.client.borderheight
|
||||
#define TBARH ((conf.titlebar.height < BORDH) ? BORDH : conf.titlebar.height)
|
||||
@ -457,7 +457,7 @@ int xrandr_event;
|
||||
uint timing;
|
||||
|
||||
/* Fonts */
|
||||
XftFont *font;
|
||||
FontStruct font;
|
||||
|
||||
/* Atoms list */
|
||||
Atom *net_atom;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user