From 3f3748d4bd40126e1253593dc05f2c99ef15bd84 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 22 Dec 2007 15:37:43 +0100 Subject: [PATCH] new widget to draw icons from PNG image --- config.c | 6 ++++++ config.mk | 2 +- draw.c | 31 +++++++++++++++++++++++++++++++ draw.h | 2 ++ widget.c | 4 +++- widget.h | 1 + 6 files changed, 44 insertions(+), 2 deletions(-) diff --git a/config.c b/config.c index 3fc6ce1db..0a3499aba 100644 --- a/config.c +++ b/config.c @@ -332,6 +332,11 @@ config_parse(const char *confpatharg) { CFG_END() }; + static cfg_opt_t widget_iconbox_opts[] = + { + CFG_STR((char *) "image", (char *) NULL, CFGF_NONE), + CFG_END() + }; static cfg_opt_t widget_textbox_opts[] = { CFG_STR((char *) "default", (char *) NULL, CFGF_NONE), @@ -346,6 +351,7 @@ config_parse(const char *confpatharg) CFG_SEC((char *) "taglist", widget_opts, CFGF_TITLE | CFGF_MULTI), CFG_SEC((char *) "focustitle", widget_opts, CFGF_TITLE | CFGF_MULTI), CFG_SEC((char *) "layoutinfo", widget_opts, CFGF_TITLE | CFGF_MULTI), + CFG_SEC((char *) "iconbox", widget_iconbox_opts, CFGF_TITLE | CFGF_MULTI), CFG_END() }; static cfg_opt_t tag_opts[] = diff --git a/config.mk b/config.mk index 2d93f486c..22257cfae 100644 --- a/config.mk +++ b/config.mk @@ -7,7 +7,7 @@ RELEASE = "Productivity Breaker" # additional layouts LAYOUTS = layouts/tile.c layouts/floating.c layouts/max.c layouts/fibonacci.c -WIDGETS = widgets/taglist.c widgets/layoutinfo.c widgets/textbox.c widgets/focustitle.c +WIDGETS = widgets/taglist.c widgets/layoutinfo.c widgets/textbox.c widgets/focustitle.c widgets/iconbox.c # paths PREFIX = /usr/local diff --git a/draw.c b/draw.c index d035a1ed0..33946a54b 100644 --- a/draw.c +++ b/draw.c @@ -149,6 +149,37 @@ drawcircle(DrawCtx *ctx, int x, int y, int r, Bool filled, XColor color) cairo_surface_destroy(surface); } +void +drawimage(DrawCtx *ctx, int x, int y, const char *filename) +{ + cairo_surface_t *surface, *source; + cairo_t *cr; + + source = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height); + surface = cairo_image_surface_create_from_png(filename); + cr = cairo_create (source); + cairo_set_source_surface(cr, surface, x, y); + cairo_paint(cr); + + cairo_destroy(cr); + cairo_surface_destroy(source); + cairo_surface_destroy(surface); +} + +int draw_get_image_width(const char *filename) +{ + int width; + cairo_surface_t *surface; + + surface = cairo_image_surface_create_from_png(filename); + cairo_image_surface_get_width(surface); + width = cairo_image_surface_get_width(surface); + cairo_surface_destroy(surface); + + return width; +} + + Drawable draw_rotate(DrawCtx *ctx, int screen, double angle, int tx, int ty) { diff --git a/draw.h b/draw.h index f8396305d..3136074a1 100644 --- a/draw.h +++ b/draw.h @@ -41,6 +41,8 @@ void draw_free_context(DrawCtx*); void drawtext(DrawCtx *, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg); void drawrectangle(DrawCtx *, int, int, int, int, Bool, XColor); void drawcircle(DrawCtx *, int, int, int, Bool, XColor); +void drawimage(DrawCtx *, int, int, const char *); +int draw_get_image_width(const char *filename); Drawable draw_rotate(DrawCtx *, int, double, int, int); unsigned short textwidth(DrawCtx *, XftFont *, char *); unsigned short textwidth_primitive(Display*, XftFont*, char*); diff --git a/widget.c b/widget.c index 98d996f10..8bb96fe54 100644 --- a/widget.c +++ b/widget.c @@ -11,6 +11,7 @@ const NameFuncLink WidgetList[] = {"layoutinfo", layoutinfo_new}, {"focustitle", focustitle_new}, {"textbox", textbox_new}, + {"iconbox", iconbox_new}, {NULL, NULL} }; @@ -28,7 +29,8 @@ calculate_alignments(Widget *widget) } if(widget) - for(; widget; widget = widget->next){ + for(; widget; widget = widget->next) + { if (widget->alignment == AlignFlex) warn("Multiple flex widgets in panel -" " ignoring flex for all but the first."); diff --git a/widget.h b/widget.h index 691a10405..492d76f4b 100644 --- a/widget.h +++ b/widget.h @@ -18,6 +18,7 @@ WidgetConstructor layoutinfo_new; WidgetConstructor taglist_new; WidgetConstructor textbox_new; WidgetConstructor focustitle_new; +WidgetConstructor iconbox_new; UICB_PROTO(uicb_widget_tell);