Add support for text shadow, add new text_shadow_offset option.

This commit is contained in:
Julien Danjou 2008-03-07 17:40:40 +01:00
parent ddd4f1c43b
commit 4451e9099e
11 changed files with 48 additions and 13 deletions

View File

@ -74,6 +74,8 @@ typedef struct
DrawCtx *ctx;
/** Font to use */
XftFont *font;
/** Draw shadow_offset under text */
Bool shadow_offset;
/** Foreground color */
XColor fg;
/** Background color */
@ -159,6 +161,7 @@ config_parse(const char *confpatharg)
/* font */
globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display),
cfg_getstr(cfg_general, "font"));
globalconf.shadow_offset = cfg_getint(cfg_general, "text_shadow_offset");
p_delete(&confpath);
@ -219,10 +222,12 @@ draw_item(item_t *item, Area geometry)
if(item == globalconf.item_selected)
draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN / 2, globalconf.font, item->data,
globalconf.shadow_offset,
globalconf.fg_focus, globalconf.bg_focus);
else
draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN / 2, globalconf.font, item->data,
globalconf.shadow_offset,
globalconf.fg, globalconf.bg);
}
@ -239,14 +244,18 @@ redraw(void)
geometry.height = globalconf.sw->geometry.height;
draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN, globalconf.font, globalconf.prompt, globalconf.fg_focus, globalconf.bg_focus);
MARGIN, globalconf.font, globalconf.prompt,
globalconf.shadow_offset,
globalconf.fg_focus, globalconf.bg_focus);
len = MARGIN * 2 + draw_textwidth(globalconf.display, globalconf.font, globalconf.prompt);
geometry.x += len;
geometry.width -= len;
draw_text(globalconf.ctx, geometry, AlignLeft,
MARGIN, globalconf.font, globalconf.text, globalconf.fg, globalconf.bg);
MARGIN, globalconf.font, globalconf.text,
globalconf.shadow_offset,
globalconf.fg, globalconf.bg);
len = MARGIN * 2 + MAX(draw_textwidth(globalconf.display, globalconf.font, globalconf.text),
geometry.width / 20);

View File

@ -53,6 +53,8 @@ typedef struct
XColor fg;
/** Background color */
XColor bg;
/** Draw shadow_offset under text */
Bool shadow_offset;
} AwesomeMsgConf;
static AwesomeMsgConf globalconf;
@ -111,6 +113,8 @@ config_parse(const char *confpatharg)
cfg_getstr(cfg_colors, "normal_bg"),
&globalconf.bg);
globalconf.shadow_offset = cfg_getint(cfg_general, "text_shadow_offset");
/* font */
globalconf.font = XftFontOpenName(globalconf.display, DefaultScreen(globalconf.display),
cfg_getstr(cfg_general, "font"));
@ -203,7 +207,8 @@ main(int argc, char **argv)
geometry.x = geometry.y = 0;
draw_text(ctx, geometry, AlignRight,
0, globalconf.font, argv[optind], globalconf.fg, globalconf.bg);
0, globalconf.font, argv[optind],
globalconf.shadow_offset, globalconf.fg, globalconf.bg);
if(icon_geometry.width > 0 && icon_geometry.height > 0)
draw_image(ctx, 0, (geometry.height / 2) - (globalconf.font->height / 2),

View File

@ -391,6 +391,8 @@ This widget shows a list of running windows.
Set mouse bindings.
*font*::
Font to use.
*text_shadow_offset*::
Draw a shadow under the text, with that number of pixel as offset.
*bg*::
Background color.
*fg*::

View File

@ -77,6 +77,7 @@ cfg_opt_t general_opts[] =
CFG_BOOL((char *) "new_become_master", cfg_true, CFGF_NONE),
CFG_BOOL((char *) "new_get_focus", cfg_true, CFGF_NONE),
CFG_STR((char *) "font", (char *) "vera-10", CFGF_NONE),
CFG_INT((char *) "text_shadow_offset", 1, CFGF_NONE),
CFG_INT((char *) "opacity_unfocused", -1, CFGF_NONE),
CFG_STR((char *) "floating_placement", (char *) "smart", CFGF_NONE),
CFG_AWESOME_END()

View File

@ -121,6 +121,7 @@ draw_context_delete(DrawCtx *ctx)
* \param padding padding to add before drawing the text
* \param font font to use
* \param text text to draw
* \param enable shadow
* \param fg foreground color
* \param bg background color
*/
@ -130,9 +131,10 @@ draw_text(DrawCtx *ctx,
Alignment align,
int padding,
XftFont *font, char *text,
int shadow_offset,
XColor fg, XColor bg)
{
int nw = 0;
int nw = 0, x, y;
ssize_t len, olen;
char *buf = NULL, *utf8 = NULL;
cairo_font_face_t *font_face;
@ -177,23 +179,31 @@ draw_text(DrawCtx *ctx,
font_face = cairo_ft_font_face_create_for_pattern(font->pattern);
cairo_set_font_face(ctx->cr, font_face);
cairo_set_font_size(ctx->cr, font->height);
cairo_set_source_rgb(ctx->cr, fg.red / 65535.0, fg.green / 65535.0, fg.blue / 65535.0);
x = area.x + padding;
y = area.y + font->ascent + (ctx->height - font->height) / 2;
switch(align)
{
case AlignLeft:
cairo_move_to(ctx->cr, area.x + padding, area.y + font->ascent + (ctx->height - font->height) / 2);
case AlignCenter:
x += (area.width - nw) / 2;
break;
case AlignRight:
cairo_move_to(ctx->cr, area.x + (area.width - nw) + padding,
area.y + font->ascent + (ctx->height - font->height) / 2);
x += area.width - nw;
break;
default:
cairo_move_to(ctx->cr, area.x + ((area.width - nw) / 2) + padding,
area.y + font->ascent + (ctx->height - font->height) / 2);
break;
}
if(shadow_offset > 0)
{
cairo_set_source_rgb(ctx->cr, 0.0, 0.0, 0.0);
cairo_move_to(ctx->cr, x + shadow_offset, y + shadow_offset);
cairo_show_text(ctx->cr, buf);
}
cairo_set_source_rgb(ctx->cr, fg.red / 65535.0, fg.green / 65535.0, fg.blue / 65535.0);
cairo_move_to(ctx->cr, x, y);
cairo_show_text(ctx->cr, buf);
cairo_font_face_destroy(font_face);

View File

@ -94,7 +94,7 @@ typedef struct
DrawCtx *draw_context_new(Display *, int, int, int, Drawable);
void draw_context_delete(DrawCtx *);
void draw_text(DrawCtx *, Area, Alignment, int, XftFont *, char *, XColor fg, XColor bg);
void draw_text(DrawCtx *, Area, Alignment, int, XftFont *, char *, int, XColor fg, XColor bg);
void draw_rectangle(DrawCtx *, Area, Bool, XColor);
void draw_rectangle_gradient(DrawCtx *, Area, int, Bool, XColor, XColor *, XColor *);

View File

@ -318,6 +318,7 @@ config_parse_screen(cfg_t *cfg, int screen)
virtscreen->font = XftFontOpenName(globalconf.display,
phys_screen,
cfg_getstr(cfg_general, "font"));
virtscreen->shadow_offset = cfg_getint(cfg_general, "text_shadow_offset");
virtscreen->floating_placement =
name_func_lookup(cfg_getstr(cfg_general, "floating_placement"),
FloatingPlacementList);

View File

@ -285,6 +285,8 @@ typedef struct
Padding padding;
/** Font */
XftFont *font;
/** Draw shadow under text */
int shadow_offset;
} VirtScreen;
/** Main configuration structure */

View File

@ -107,6 +107,7 @@ taglist_draw(Widget *widget,
vscreen.font->height / 2,
vscreen.font,
tag->name,
vscreen.shadow_offset,
colors[ColFG],
colors[ColBG]);
if(isoccupied(tag))

View File

@ -165,10 +165,12 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
if(sel == c)
draw_text(ctx, area, d->align,
widget->font->height / 2, widget->font, c->name,
globalconf.screens[widget->statusbar->screen].shadow_offset,
d->fg_sel, d->bg_sel);
else
draw_text(ctx, area, d->align,
widget->font->height / 2, widget->font, c->name,
globalconf.screens[widget->statusbar->screen].shadow_offset,
d->fg, d->bg);
if(c == globalconf.scratch.client)

View File

@ -57,7 +57,9 @@ textbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used)
if(!widget->user_supplied_y)
widget->area.y = 0;
draw_text(ctx, widget->area, d->align, 0, widget->font, d->text, d->fg, d->bg);
draw_text(ctx, widget->area, d->align, 0, widget->font, d->text,
globalconf.screens[widget->statusbar->screen].shadow_offset,
d->fg, d->bg);
return widget->area.width;
}