Font per theme

This commit is contained in:
Martin Duquesnoy 2011-09-01 19:07:54 +02:00
parent 8e8aeb950d
commit 45b6d294be
7 changed files with 70 additions and 38 deletions

View File

@ -28,6 +28,8 @@ config_theme(void)
if(!(n = fetch_section_count(ks)))
++n;
SLIST_INIT(&W->h.theme);
/* [theme]*/
for(i = 0; i < n; ++i)
{
@ -35,6 +37,8 @@ config_theme(void)
t->name = fetch_opt_first(ks[i], "default", "name").str;
wmfs_init_font(fetch_opt_first(ks[i], "fixed", "font").str, t);
/* bars */
t->bars.fg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "bars_fg").str);
t->bars.bg = color_atoh(fetch_opt_first(ks[i], "#222222", "bars_bg").str);

View File

@ -12,22 +12,22 @@
#include "wmfs.h"
#define TEXTY(w) ((W->font.height - W->font.de) + ((w - W->font.height) >> 1))
#define TEXTY(t, w) ((t->font.height - t->font.de) + ((w - t->font.height) >> 1))
#define PAD (8)
static inline void
draw_text(Drawable d, int x, int y, Color fg, const char *str)
draw_text(Drawable d, Theme *t, int x, int y, Color fg, const char *str)
{
XSetForeground(W->dpy, W->gc, fg);
XmbDrawString(W->dpy, d, W->font.fontset, W->gc, x, y, str, strlen(str));
XmbDrawString(W->dpy, d, t->font.fontset, W->gc, x, y, str, strlen(str));
}
static inline unsigned short
draw_textw(const char *str)
draw_textw(Theme *t, const char *str)
{
XRectangle r;
XmbTextExtents(W->font.fontset, str, strlen(str), NULL, &r);
XmbTextExtents(t->font.fontset, str, strlen(str), NULL, &r);
return r.width;
}

View File

@ -228,7 +228,7 @@ event_expose(XEvent *e)
static void
event_dummy(XEvent *e)
{
printf("%d\n", e->type);
/* printf("%d\n", e->type);*/
(void)e;
}

View File

@ -46,7 +46,7 @@ infobar_elem_tag_init(Element *e)
TAILQ_FOREACH(t, &e->infobar->screen->tags, next)
{
s = draw_textw(t->name) + PAD;
s = draw_textw(e->infobar->theme, t->name) + PAD;
/* Init barwin */
b = barwin_new(e->infobar->bar->win, j, 0, s, e->geo.h, 0, 0, false);
@ -106,7 +106,8 @@ infobar_elem_tag_update(Element *e)
barwin_refresh_color(b);
draw_text(b->dr, (PAD >> 1), TEXTY(e->geo.h), b->fg, t->name);
draw_text(b->dr, e->infobar->theme, (PAD >> 1),
TEXTY(e->infobar->theme, e->geo.h), b->fg, t->name);
barwin_refresh(b);
}

View File

@ -57,13 +57,37 @@ wmfs_error_handler_dummy(Display *d, XErrorEvent *event)
return 0;
}
void
wmfs_init_font(char *font, Theme *t)
{
XFontStruct **xfs = NULL;
char **misschar, **names, *defstring;
int d;
if(!(t->font.fontset = XCreateFontSet(W->dpy, font, &misschar, &d, &defstring)))
{
warnx("Can't load font '%s'", font);
t->font.fontset = XCreateFontSet(W->dpy, "fixed", &misschar, &d, &defstring);
}
XExtentsOfFontSet(t->font.fontset);
XFontsOfFontSet(t->font.fontset, &xfs, &names);
t->font.as = xfs[0]->max_bounds.ascent;
t->font.de = xfs[0]->max_bounds.descent;
t->font.width = xfs[0]->max_bounds.width;
t->font.height = t->font.as + t->font.de;
if(misschar)
XFreeStringList(misschar);
}
static void
wmfs_xinit(void)
{
char **misschar, **names, *defstring;
int d, i, j;
int i, j;
XModifierKeymap *mm;
XFontStruct **xfs = NULL;
XSetWindowAttributes at;
/*
@ -90,24 +114,10 @@ wmfs_xinit(void)
XChangeWindowAttributes(W->dpy, W->root, CWEventMask | CWCursor, &at);
/*
* Font
* Locale (font encode)
*/
setlocale(LC_CTYPE, "");
W->font.fontset = XCreateFontSet(W->dpy, "fixed", &misschar, &d, &defstring);
XExtentsOfFontSet(W->font.fontset);
XFontsOfFontSet(W->font.fontset, &xfs, &names);
W->font.as = xfs[0]->max_bounds.ascent;
W->font.de = xfs[0]->max_bounds.descent;
W->font.width = xfs[0]->max_bounds.width;
W->font.height = W->font.as + W->font.de;
if(misschar)
XFreeStringList(misschar);
/*
* Keys
*/
@ -230,19 +240,30 @@ wmfs_init(void)
void
wmfs_quit(void)
{
/* X stuffs */
XFreeFontSet(W->dpy, W->font.fontset);
Theme *t;
/* Will free:
*
* Screens -> Tags
* -> Infobars -> Elements
*/
screen_free();
XCloseDisplay(W->dpy);
free(W->net_atom);
free(W);
/* Conf stuffs */
FREE_LIST(Keybind, W->h.keybind);
FREE_LIST(Theme, W->h.theme);
while(!SLIST_EMPTY(&W->h.theme))
{
t = SLIST_FIRST(&W->h.theme);
SLIST_REMOVE_HEAD(&W->h.theme, next);
XFreeFontSet(W->dpy, t->font.fontset);
free(t);
}
free(W->net_atom);
free(W);
W->running = false;
}

View File

@ -151,6 +151,13 @@ struct Theme
{
char *name;
/* Font */
struct
{
int as, de, width, height;
XFontSet fontset;
} font;
/* Bars */
struct Colpair bars;
int bars_width;
@ -188,12 +195,6 @@ struct Wmfs
Atom *net_atom;
bool running;
struct
{
int as, de, width, height;
XFontSet fontset;
} font;
/* Lists heads */
struct
{
@ -217,6 +218,7 @@ struct Wmfs
int wmfs_error_handler(Display *d, XErrorEvent *event);
int wmfs_error_handler_dummy(Display *d, XErrorEvent *event);
void wmfs_grab_keys(void);
void wmfs_init_font(char *font, Theme *t);
void wmfs_quit(void);
void uicb_reload(Uicb cmd);
void uicb_quit(Uicb cmd);

View File

@ -7,6 +7,8 @@
[theme]
# name = "default"
font = "fixed"
# Bars
bars_width = 14
bars_fg = "#CCCCCC"
@ -25,6 +27,8 @@
[theme]
name = "perso"
font = "courier"
bars_width = 20
bars_fg = "#222222"
bars_bg = "#CCCCCC"