start fixing screen_ctx usage, for it is utterly broken. bring font

into screen_ctx and start passing screen_ctx around to in order get rid
of Curscreen; fixup per-screen config colors the same way.

diff mostly from oga@, with a bit harsher reaction to the state of screen_ctx.

"please commit" oga@
This commit is contained in:
okan 2009-12-08 16:52:17 +00:00
parent aa88d5848e
commit ee7df6a95f
6 changed files with 43 additions and 47 deletions

View File

@ -156,10 +156,10 @@ x_setupscreen(struct screen_ctx *sc, u_int which)
sc->xmax = DisplayWidth(X_Dpy, sc->which);
sc->ymax = DisplayHeight(X_Dpy, sc->which);
conf_color(&Conf);
conf_color(&Conf, sc);
font_init(sc);
conf_font(&Conf);
conf_font(&Conf, sc);
TAILQ_INIT(&sc->mruq);

View File

@ -79,6 +79,8 @@ struct screen_ctx {
XftDraw *xftdraw;
XftColor xftcolor;
XftFont *font;
u_int fontheight;
int xinerama_no;
XineramaScreenInfo *xinerama;
@ -284,8 +286,6 @@ struct conf {
#define DEFAULTFONTNAME "sans-serif:pixelsize=14:bold"
char *DefaultFontName;
XftFont *DefaultFont;
u_int FontHeight;
int gap_top, gap_bottom, gap_left, gap_right;
};
@ -410,8 +410,8 @@ void conf_bindname(struct conf *, char *, char *);
void conf_mousebind(struct conf *, char *, char *);
void conf_grab_mouse(struct client_ctx *);
void conf_reload(struct conf *);
void conf_font(struct conf *);
void conf_color(struct conf *);
void conf_font(struct conf *, struct screen_ctx *);
void conf_color(struct conf *, struct screen_ctx *);
void conf_init(struct conf *);
void conf_clear(struct conf *);
void conf_cmd_add(struct conf *, char *, char *, int);
@ -485,14 +485,14 @@ void group_autogroup(struct client_ctx *);
void group_movetogroup(struct client_ctx *, int);
void font_init(struct screen_ctx *);
int font_width(const char *, int);
int font_width(struct screen_ctx *, const char *, int);
void font_draw(struct screen_ctx *, const char *, int,
Drawable, int, int);
XftFont *font_make(struct screen_ctx *, const char *);
#define font_ascent() Conf.DefaultFont->ascent
#define font_descent() Conf.DefaultFont->descent
#define font_height() Conf.FontHeight
#define font_ascent(sc) sc->font->ascent
#define font_descent(sc) sc->font->descent
#define font_height(sc) sc->fontheight
/* Externs */

24
conf.c
View File

@ -51,23 +51,16 @@ conf_cmd_add(struct conf *c, char *image, char *label, int flags)
}
void
conf_font(struct conf *c)
conf_font(struct conf *c, struct screen_ctx *sc)
{
struct screen_ctx *sc;
sc = screen_current();
c->DefaultFont = font_make(sc, c->DefaultFontName);
c->FontHeight = font_ascent() + font_descent() + 1;
sc->font = font_make(sc, c->DefaultFontName);
sc->fontheight = font_ascent(sc) + font_descent(sc) + 1;
}
void
conf_color(struct conf *c)
conf_color(struct conf *c, struct screen_ctx *sc)
{
struct screen_ctx *sc;
int i;
sc = screen_current();
int i;
for (i = 0; i < CWM_COLOR_MAX; i++) {
xu_freecolor(sc, sc->color[i].pixel);
@ -78,6 +71,7 @@ conf_color(struct conf *c)
void
conf_reload(struct conf *c)
{
struct screen_ctx *sc;
struct client_ctx *cc;
if (parse_config(c->conf_path, c) == -1) {
@ -85,10 +79,12 @@ conf_reload(struct conf *c)
return;
}
conf_color(c);
TAILQ_FOREACH(cc, &Clientq, entry)
client_draw_border(cc);
conf_font(c);
TAILQ_FOREACH(sc, &Screenq, entry) {
conf_color(c, sc);
conf_font(c, sc);
}
}
static struct {

6
font.c
View File

@ -33,11 +33,11 @@ font_init(struct screen_ctx *sc)
}
int
font_width(const char *text, int len)
font_width(struct screen_ctx *sc, const char *text, int len)
{
XGlyphInfo extents;
XftTextExtents8(X_Dpy, Conf.DefaultFont, (const XftChar8*)text,
XftTextExtents8(X_Dpy, sc->font, (const XftChar8*)text,
len, &extents);
return (extents.xOff);
@ -49,7 +49,7 @@ font_draw(struct screen_ctx *sc, const char *text, int len,
{
XftDrawChange(sc->xftdraw, d);
/* Really needs to be UTF8'd. */
XftDrawString8(sc->xftdraw, &sc->xftcolor, Conf.DefaultFont, x, y,
XftDrawString8(sc->xftdraw, &sc->xftcolor, sc->font, x, y,
(const FcChar8*)text, len);
}

30
menu.c
View File

@ -99,7 +99,7 @@ menu_filter(struct menu_q *menuq, char *prompt, char *initial, int dummy,
PROMPT_SCHAR);
snprintf(mc.dispstr, sizeof(mc.dispstr), "%s%s%c", mc.promptstr,
mc.searchstr, PROMPT_ECHAR);
mc.width = font_width(mc.dispstr, strlen(mc.dispstr));
mc.width = font_width(sc, mc.dispstr, strlen(mc.dispstr));
mc.hasprompt = 1;
}
@ -113,7 +113,7 @@ menu_filter(struct menu_q *menuq, char *prompt, char *initial, int dummy,
mc.entry = mc.prev = -1;
XMoveResizeWindow(X_Dpy, sc->menuwin, mc.x, mc.y, mc.width,
font_height());
font_height(sc));
XSelectInput(X_Dpy, sc->menuwin, evmask);
XMapRaised(X_Dpy, sc->menuwin);
@ -283,8 +283,8 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
if (mc->hasprompt) {
snprintf(mc->dispstr, sizeof(mc->dispstr), "%s%s%c",
mc->promptstr, mc->searchstr, PROMPT_ECHAR);
mc->width = font_width(mc->dispstr, strlen(mc->dispstr));
dy = font_height();
mc->width = font_width(sc, mc->dispstr, strlen(mc->dispstr));
dy = font_height(sc);
mc->num = 1;
}
@ -299,9 +299,9 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
text = mi->text;
}
mc->width = MAX(mc->width, font_width(text,
mc->width = MAX(mc->width, font_width(sc, text,
MIN(strlen(text), MENU_MAXENTRY)));
dy += font_height();
dy += font_height(sc);
mc->num++;
}
@ -326,7 +326,7 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
if (mc->hasprompt) {
font_draw(sc, mc->dispstr, strlen(mc->dispstr), sc->menuwin,
0, font_ascent() + 1);
0, font_ascent(sc) + 1);
n = 1;
} else
n = 0;
@ -336,17 +336,17 @@ menu_draw(struct screen_ctx *sc, struct menu_ctx *mc, struct menu_q *menuq,
mi->print : mi->text;
font_draw(sc, text, MIN(strlen(text), MENU_MAXENTRY),
sc->menuwin, 0, n * font_height() + font_ascent() + 1);
sc->menuwin, 0, n * font_height(sc) + font_ascent(sc) + 1);
n++;
}
if (mc->hasprompt && n > 1)
XFillRectangle(X_Dpy, sc->menuwin, sc->gc,
0, font_height(), mc->width, font_height());
0, font_height(sc), mc->width, font_height(sc));
if (mc->noresult)
XFillRectangle(X_Dpy, sc->menuwin, sc->gc,
0, 0, mc->width, font_height());
0, 0, mc->width, font_height(sc));
}
static void
@ -357,11 +357,11 @@ menu_handle_move(XEvent *e, struct menu_ctx *mc, struct screen_ctx *sc)
if (mc->prev != -1)
XFillRectangle(X_Dpy, sc->menuwin, sc->gc, 0,
font_height() * mc->prev, mc->width, font_height());
font_height(sc) * mc->prev, mc->width, font_height(sc));
if (mc->entry != -1) {
xu_ptr_regrab(MenuGrabMask, Cursor_select);
XFillRectangle(X_Dpy, sc->menuwin, sc->gc, 0,
font_height() * mc->entry, mc->width, font_height());
font_height(sc) * mc->entry, mc->width, font_height(sc));
} else
xu_ptr_regrab(MenuGrabMask, Cursor_default);
}
@ -395,11 +395,11 @@ menu_calc_entry(struct screen_ctx *sc, struct menu_ctx *mc, int x, int y)
{
int entry;
entry = y / font_height();
entry = y / font_height(sc);
/* in bounds? */
if (x <= 0 || x > mc->width || y <= 0 || y > font_height() * mc->num ||
entry < 0 || entry >= mc->num)
if (x <= 0 || x > mc->width || y <= 0 ||
y > font_height(sc) * mc->num || entry < 0 || entry >= mc->num)
entry = -1;
if (mc->hasprompt && entry == 0)

View File

@ -51,10 +51,10 @@ mousefunc_sweep_draw(struct client_ctx *cc)
snprintf(asize, sizeof(asize), "%dx%d",
(cc->geom.width - cc->geom.basew) / cc->geom.incw,
(cc->geom.height - cc->geom.baseh) / cc->geom.inch);
width_size = font_width(asize, strlen(asize)) + 4;
width_name = font_width(cc->name, strlen(cc->name)) + 4;
width_size = font_width(sc, asize, strlen(asize)) + 4;
width_name = font_width(sc, cc->name, strlen(cc->name)) + 4;
width = MAX(width_size, width_name);
height = font_ascent() + font_descent() + 1;
height = font_ascent(sc) + font_descent(sc) + 1;
XMoveResizeWindow(X_Dpy, sc->menuwin, cc->geom.x, cc->geom.y,
width, height * 2);
@ -62,9 +62,9 @@ mousefunc_sweep_draw(struct client_ctx *cc)
XReparentWindow(X_Dpy, sc->menuwin, cc->win, 0, 0);
XClearWindow(X_Dpy, sc->menuwin);
font_draw(sc, cc->name, strlen(cc->name), sc->menuwin,
2, font_ascent() + 1);
2, font_ascent(sc) + 1);
font_draw(sc, asize, strlen(asize), sc->menuwin,
width / 2 - width_size / 2, height + font_ascent() + 1);
width / 2 - width_size / 2, height + font_ascent(sc) + 1);
}
void