diff --git a/draw.c b/draw.c index 831890f4..216765b0 100644 --- a/draw.c +++ b/draw.c @@ -149,15 +149,24 @@ drawcircle(DrawCtx *ctx, int x, int y, int r, Bool filled, XColor color) cairo_surface_destroy(surface); } -void draw_image_from_argb_data(DrawCtx *ctx, int x, int y, int w, int h, unsigned char *data) +void draw_image_from_argb_data(DrawCtx *ctx, int x, int y, int w, int h, + int wanted_w, unsigned char *data) { + double ratio; 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_for_data(data, CAIRO_FORMAT_ARGB32, w, h, 0); - cr = cairo_create (source); - cairo_set_source_surface(cr, surface, x, y); + surface = cairo_xlib_surface_create(ctx->display, ctx->drawable, ctx->visual, ctx->width, ctx->height); + source = cairo_image_surface_create_for_data(data, CAIRO_FORMAT_ARGB32, w, h, 0); + cr = cairo_create (surface); + if(wanted_w > 0 && w > 0) + { + ratio = (double) wanted_w / (double) w; + cairo_scale(cr, ratio, ratio); + cairo_set_source_surface(cr, source, x / ratio, y / ratio); + } + else + cairo_set_source_surface(cr, source, x, y); cairo_paint(cr); cairo_destroy(cr); diff --git a/draw.h b/draw.h index bd0df42c..e0787510 100644 --- a/draw.h +++ b/draw.h @@ -42,7 +42,7 @@ void drawtext(DrawCtx *, int, int, int, int, XftFont *, const char *, XColor fg, void drawrectangle(DrawCtx *, int, int, int, int, Bool, XColor); void drawcircle(DrawCtx *, int, int, int, Bool, XColor); void drawimage(DrawCtx *, int, int, const char *); -void draw_image_from_argb_data(DrawCtx *, int, int, int, int, unsigned char *); +void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char *); int draw_get_image_width(const char *filename); Drawable draw_rotate(DrawCtx *, int, double, int, int); unsigned short textwidth(DrawCtx *, XftFont *, char *); diff --git a/widgets/netwmicon.c b/widgets/netwmicon.c index 54e2ee56..7b1d0eb0 100644 --- a/widgets/netwmicon.c +++ b/widgets/netwmicon.c @@ -83,12 +83,12 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, offset, widget->alignment); - draw_image_from_argb_data(ctx, location, 0, width, height, image); + draw_image_from_argb_data(ctx, location, 0, width, height, vscreen.statusbar->height, image); p_delete(&image); XFree(data); - return width; + return vscreen.statusbar->height; } Widget *