diff options
author | okan <okan> | 2009-12-08 16:52:17 +0000 |
---|---|---|
committer | okan <okan> | 2009-12-08 16:52:17 +0000 |
commit | ee7df6a95f80bebc9ec2d8571c1ff8ff2f53cfd0 (patch) | |
tree | 72d45dd2b4f7a08e9fa71bd138354cd9741f33b5 | |
parent | aa88d5848e0b3ee3ea7c64c7582eddd963dcecb2 (diff) | |
download | cwm-ee7df6a95f80bebc9ec2d8571c1ff8ff2f53cfd0.tar.gz cwm-ee7df6a95f80bebc9ec2d8571c1ff8ff2f53cfd0.tar.xz cwm-ee7df6a95f80bebc9ec2d8571c1ff8ff2f53cfd0.zip |
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@
-rw-r--r-- | calmwm.c | 4 | ||||
-rw-r--r-- | calmwm.h | 16 | ||||
-rw-r--r-- | conf.c | 24 | ||||
-rw-r--r-- | font.c | 6 | ||||
-rw-r--r-- | menu.c | 30 | ||||
-rw-r--r-- | mousefunc.c | 10 |
6 files changed, 43 insertions, 47 deletions
diff --git a/calmwm.c b/calmwm.c index 37fa473..8cc62d5 100644 --- a/calmwm.c +++ b/calmwm.c @@ -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); diff --git a/calmwm.h b/calmwm.h index 4201968..0dc1ffe 100644 --- a/calmwm.h +++ b/calmwm.h @@ -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 */ diff --git a/conf.c b/conf.c index b7bf52b..7e34ced 100644 --- a/conf.c +++ b/conf.c @@ -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 { diff --git a/font.c b/font.c index 0322d50..0f58c82 100644 --- a/font.c +++ b/font.c @@ -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); } diff --git a/menu.c b/menu.c index 2d02a64..2ac0d13 100644 --- a/menu.c +++ b/menu.c @@ -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) diff --git a/mousefunc.c b/mousefunc.c index 479454d..c0b3b1a 100644 --- a/mousefunc.c +++ b/mousefunc.c @@ -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 |