From 4451e9099e7a81c881d3d958054aeb2fe3994347 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 7 Mar 2008 17:40:40 +0100 Subject: [PATCH] Add support for text shadow, add new text_shadow_offset option. --- awesome-menu.c | 13 +++++++++++-- awesome-message.c | 7 ++++++- awesomerc.5.txt | 2 ++ common/configopts.c | 1 + common/draw.c | 26 ++++++++++++++++++-------- common/draw.h | 2 +- config.c | 1 + structs.h | 2 ++ widgets/taglist.c | 1 + widgets/tasklist.c | 2 ++ widgets/textbox.c | 4 +++- 11 files changed, 48 insertions(+), 13 deletions(-) diff --git a/awesome-menu.c b/awesome-menu.c index 1fa5f66b..2df9da8f 100644 --- a/awesome-menu.c +++ b/awesome-menu.c @@ -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); diff --git a/awesome-message.c b/awesome-message.c index 043ee8ef..3e97ca64 100644 --- a/awesome-message.c +++ b/awesome-message.c @@ -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), diff --git a/awesomerc.5.txt b/awesomerc.5.txt index 6835ca4b..855de3a5 100644 --- a/awesomerc.5.txt +++ b/awesomerc.5.txt @@ -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*:: diff --git a/common/configopts.c b/common/configopts.c index 918b8095..f1abaddc 100644 --- a/common/configopts.c +++ b/common/configopts.c @@ -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() diff --git a/common/draw.c b/common/draw.c index 3ff03726..c5e749c7 100644 --- a/common/draw.c +++ b/common/draw.c @@ -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); diff --git a/common/draw.h b/common/draw.h index 0a18a23b..6d27b145 100644 --- a/common/draw.h +++ b/common/draw.h @@ -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 *); diff --git a/config.c b/config.c index 26c4ee2f..590a3595 100644 --- a/config.c +++ b/config.c @@ -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); diff --git a/structs.h b/structs.h index edbd75d9..1b79300c 100644 --- a/structs.h +++ b/structs.h @@ -285,6 +285,8 @@ typedef struct Padding padding; /** Font */ XftFont *font; + /** Draw shadow under text */ + int shadow_offset; } VirtScreen; /** Main configuration structure */ diff --git a/widgets/taglist.c b/widgets/taglist.c index bd398d8f..0cce7799 100644 --- a/widgets/taglist.c +++ b/widgets/taglist.c @@ -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)) diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 3121b6e2..45dc82ed 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -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) diff --git a/widgets/textbox.c b/widgets/textbox.c index 1f7c4df5..689a0881 100644 --- a/widgets/textbox.c +++ b/widgets/textbox.c @@ -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; }