Font per theme
This commit is contained in:
parent
8e8aeb950d
commit
45b6d294be
@ -28,6 +28,8 @@ config_theme(void)
|
|||||||
if(!(n = fetch_section_count(ks)))
|
if(!(n = fetch_section_count(ks)))
|
||||||
++n;
|
++n;
|
||||||
|
|
||||||
|
SLIST_INIT(&W->h.theme);
|
||||||
|
|
||||||
/* [theme]*/
|
/* [theme]*/
|
||||||
for(i = 0; i < n; ++i)
|
for(i = 0; i < n; ++i)
|
||||||
{
|
{
|
||||||
@ -35,6 +37,8 @@ config_theme(void)
|
|||||||
|
|
||||||
t->name = fetch_opt_first(ks[i], "default", "name").str;
|
t->name = fetch_opt_first(ks[i], "default", "name").str;
|
||||||
|
|
||||||
|
wmfs_init_font(fetch_opt_first(ks[i], "fixed", "font").str, t);
|
||||||
|
|
||||||
/* bars */
|
/* bars */
|
||||||
t->bars.fg = color_atoh(fetch_opt_first(ks[i], "#CCCCCC", "bars_fg").str);
|
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);
|
t->bars.bg = color_atoh(fetch_opt_first(ks[i], "#222222", "bars_bg").str);
|
||||||
|
|||||||
@ -12,22 +12,22 @@
|
|||||||
|
|
||||||
#include "wmfs.h"
|
#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)
|
#define PAD (8)
|
||||||
|
|
||||||
static inline void
|
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);
|
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
|
static inline unsigned short
|
||||||
draw_textw(const char *str)
|
draw_textw(Theme *t, const char *str)
|
||||||
{
|
{
|
||||||
XRectangle r;
|
XRectangle r;
|
||||||
|
|
||||||
XmbTextExtents(W->font.fontset, str, strlen(str), NULL, &r);
|
XmbTextExtents(t->font.fontset, str, strlen(str), NULL, &r);
|
||||||
|
|
||||||
return r.width;
|
return r.width;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -228,7 +228,7 @@ event_expose(XEvent *e)
|
|||||||
static void
|
static void
|
||||||
event_dummy(XEvent *e)
|
event_dummy(XEvent *e)
|
||||||
{
|
{
|
||||||
printf("%d\n", e->type);
|
/* printf("%d\n", e->type);*/
|
||||||
(void)e;
|
(void)e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -46,7 +46,7 @@ infobar_elem_tag_init(Element *e)
|
|||||||
|
|
||||||
TAILQ_FOREACH(t, &e->infobar->screen->tags, next)
|
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 */
|
/* Init barwin */
|
||||||
b = barwin_new(e->infobar->bar->win, j, 0, s, e->geo.h, 0, 0, false);
|
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);
|
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);
|
barwin_refresh(b);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -57,13 +57,37 @@ wmfs_error_handler_dummy(Display *d, XErrorEvent *event)
|
|||||||
return 0;
|
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
|
static void
|
||||||
wmfs_xinit(void)
|
wmfs_xinit(void)
|
||||||
{
|
{
|
||||||
char **misschar, **names, *defstring;
|
int i, j;
|
||||||
int d, i, j;
|
|
||||||
XModifierKeymap *mm;
|
XModifierKeymap *mm;
|
||||||
XFontStruct **xfs = NULL;
|
|
||||||
XSetWindowAttributes at;
|
XSetWindowAttributes at;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -90,24 +114,10 @@ wmfs_xinit(void)
|
|||||||
XChangeWindowAttributes(W->dpy, W->root, CWEventMask | CWCursor, &at);
|
XChangeWindowAttributes(W->dpy, W->root, CWEventMask | CWCursor, &at);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Font
|
* Locale (font encode)
|
||||||
*/
|
*/
|
||||||
setlocale(LC_CTYPE, "");
|
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
|
* Keys
|
||||||
*/
|
*/
|
||||||
@ -230,19 +240,30 @@ wmfs_init(void)
|
|||||||
void
|
void
|
||||||
wmfs_quit(void)
|
wmfs_quit(void)
|
||||||
{
|
{
|
||||||
/* X stuffs */
|
Theme *t;
|
||||||
XFreeFontSet(W->dpy, W->font.fontset);
|
|
||||||
|
|
||||||
|
/* Will free:
|
||||||
|
*
|
||||||
|
* Screens -> Tags
|
||||||
|
* -> Infobars -> Elements
|
||||||
|
*/
|
||||||
screen_free();
|
screen_free();
|
||||||
|
|
||||||
XCloseDisplay(W->dpy);
|
XCloseDisplay(W->dpy);
|
||||||
|
|
||||||
free(W->net_atom);
|
|
||||||
free(W);
|
|
||||||
|
|
||||||
/* Conf stuffs */
|
/* Conf stuffs */
|
||||||
FREE_LIST(Keybind, W->h.keybind);
|
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;
|
W->running = false;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -151,6 +151,13 @@ struct Theme
|
|||||||
{
|
{
|
||||||
char *name;
|
char *name;
|
||||||
|
|
||||||
|
/* Font */
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
int as, de, width, height;
|
||||||
|
XFontSet fontset;
|
||||||
|
} font;
|
||||||
|
|
||||||
/* Bars */
|
/* Bars */
|
||||||
struct Colpair bars;
|
struct Colpair bars;
|
||||||
int bars_width;
|
int bars_width;
|
||||||
@ -188,12 +195,6 @@ struct Wmfs
|
|||||||
Atom *net_atom;
|
Atom *net_atom;
|
||||||
bool running;
|
bool running;
|
||||||
|
|
||||||
struct
|
|
||||||
{
|
|
||||||
int as, de, width, height;
|
|
||||||
XFontSet fontset;
|
|
||||||
} font;
|
|
||||||
|
|
||||||
/* Lists heads */
|
/* Lists heads */
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
@ -217,6 +218,7 @@ struct Wmfs
|
|||||||
int wmfs_error_handler(Display *d, XErrorEvent *event);
|
int wmfs_error_handler(Display *d, XErrorEvent *event);
|
||||||
int wmfs_error_handler_dummy(Display *d, XErrorEvent *event);
|
int wmfs_error_handler_dummy(Display *d, XErrorEvent *event);
|
||||||
void wmfs_grab_keys(void);
|
void wmfs_grab_keys(void);
|
||||||
|
void wmfs_init_font(char *font, Theme *t);
|
||||||
void wmfs_quit(void);
|
void wmfs_quit(void);
|
||||||
void uicb_reload(Uicb cmd);
|
void uicb_reload(Uicb cmd);
|
||||||
void uicb_quit(Uicb cmd);
|
void uicb_quit(Uicb cmd);
|
||||||
|
|||||||
@ -7,6 +7,8 @@
|
|||||||
[theme]
|
[theme]
|
||||||
# name = "default"
|
# name = "default"
|
||||||
|
|
||||||
|
font = "fixed"
|
||||||
|
|
||||||
# Bars
|
# Bars
|
||||||
bars_width = 14
|
bars_width = 14
|
||||||
bars_fg = "#CCCCCC"
|
bars_fg = "#CCCCCC"
|
||||||
@ -25,6 +27,8 @@
|
|||||||
[theme]
|
[theme]
|
||||||
name = "perso"
|
name = "perso"
|
||||||
|
|
||||||
|
font = "courier"
|
||||||
|
|
||||||
bars_width = 20
|
bars_width = 20
|
||||||
bars_fg = "#222222"
|
bars_fg = "#222222"
|
||||||
bars_bg = "#CCCCCC"
|
bars_bg = "#CCCCCC"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user