diff --git a/config.mk b/config.mk index 7b26a48..68b29f2 100644 --- a/config.mk +++ b/config.mk @@ -17,7 +17,7 @@ LDFLAGS_DEBUG := pkg_config_packs := dbus-1 \ gio-2.0 \ - gdk-3.0 \ + gdk-pixbuf-2.0 \ "glib-2.0 >= 2.36" \ pangocairo \ x11 \ diff --git a/src/x11/x.c b/src/x11/x.c index dcfef35..0cef023 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include @@ -288,21 +287,29 @@ static dimension_t calculate_dimensions(GSList *layouts) return dim; } -static cairo_surface_t *gdk_pixbuf_to_cairo_surface(const GdkPixbuf *pixbuf) +struct buffer { + char *buf; + gsize bufsize; +}; + +static cairo_status_t read_from_buf(void *closure, unsigned char *data, unsigned int size) +{ + struct buffer *buf = (struct buffer *)closure; + unsigned int cpy = MIN(size, buf->bufsize); + memcpy(data, buf->buf, cpy); + buf->buf += cpy; + buf->bufsize -= cpy; + return CAIRO_STATUS_SUCCESS; +} + +static cairo_surface_t *gdk_pixbuf_to_cairo_surface(GdkPixbuf *pixbuf) { cairo_surface_t *icon_surface = NULL; - cairo_t *cr; - cairo_format_t format; - double width, height; + struct buffer buffer; + + gdk_pixbuf_save_to_buffer(pixbuf, &buffer.buf, &buffer.bufsize, "png", NULL, NULL); + icon_surface = cairo_image_surface_create_from_png_stream(read_from_buf, &buffer); - format = gdk_pixbuf_get_has_alpha(pixbuf) ? CAIRO_FORMAT_ARGB32 : CAIRO_FORMAT_RGB24; - width = gdk_pixbuf_get_width(pixbuf); - height = gdk_pixbuf_get_height(pixbuf); - icon_surface = cairo_image_surface_create(format, width, height); - cr = cairo_create(icon_surface); - gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); - cairo_paint(cr); - cairo_destroy(cr); return icon_surface; }