Drop dependency on gtk3

As per discussion in #334 drop dependency on gtk3 and instead depend
only on gdk-pixbuf2 for icon loading.

The only gtk3 function used was gdk_cairo_set_source_pixbuf in order to
convert the loaded pixbufs into cairo surfaces for us to render. In
order to drop the dependency this step was bypassed by using pixbufs
export to png capability and importing it into cairo via a pngstream.
This commit is contained in:
Nikos Tsipinakis 2017-09-09 17:09:50 +03:00 committed by Benedikt Heine
parent 4908a75a89
commit 0afdda11f3
2 changed files with 21 additions and 14 deletions

View File

@ -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 \

View File

@ -10,7 +10,6 @@
#include <cairo-xlib.h>
#include <cairo.h>
#include <gdk-pixbuf/gdk-pixbuf.h>
#include <gdk/gdk.h>
#include <glib-object.h>
#include <locale.h>
#include <math.h>
@ -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;
}