diff --git a/Makefile.am b/Makefile.am index 2dfd6f900..55f92fb9e 100644 --- a/Makefile.am +++ b/Makefile.am @@ -110,7 +110,7 @@ AWESOME_CFLAGS = -std=gnu99 -pipe \ -Wunused -Winit-self -Wpointer-arith -Wredundant-decls \ -Wmissing-prototypes -Wmissing-format-attribute -Wmissing-noreturn endif -AM_CPPFLAGS = $(X_CFLAGS) $(pangocairo_CFLAGS) $(confuse_CFLAGS) $(xrandr_CFLAGS) $(xinerama_CFLAGS) $(AWESOME_CFLAGS) $(imlib2_CFLAGS) +AM_CPPFLAGS = $(X_CFLAGS) $(pangocairo_CFLAGS) $(confuse_CFLAGS) $(xrandr_CFLAGS) $(xinerama_CFLAGS) $(AWESOME_CFLAGS) $(image_CFLAGS) bin_PROGRAMS += awesome awesome_SOURCES = \ @@ -143,7 +143,7 @@ awesome_SOURCES = \ ewmh.c ewmh.h awesome_SOURCES += $(LAYOUTS) awesome_SOURCES += $(WIDGETS) -awesome_LDADD = $(X_LIBS) $(pangocairo_LIBS) $(confuse_LIBS) $(xrandr_LIBS) $(xinerama_LIBS) $(imlib2_LIBS) +awesome_LDADD = $(X_LIBS) $(pangocairo_LIBS) $(confuse_LIBS) $(xrandr_LIBS) $(xinerama_LIBS) $(image_LIBS) bin_PROGRAMS += awesome-client awesome_client_SOURCES = \ @@ -162,7 +162,7 @@ awesome_message_SOURCES = \ common/xscreen.h common/xscreen.c \ awesome-message.c -awesome_message_LDADD = $(X_LIBS) $(pangocairo_LIBS) $(confuse_LIBS) $(xinerama_LIBS) $(imlib2_LIBS) +awesome_message_LDADD = $(X_LIBS) $(pangocairo_LIBS) $(confuse_LIBS) $(xinerama_LIBS) $(image_LIBS) bin_PROGRAMS += awesome-menu awesome_menu_SOURCES = \ @@ -174,7 +174,7 @@ awesome_menu_SOURCES = \ common/xutil.h common/xutil.c \ awesome-menu.c -awesome_menu_LDADD = $(X_LIBS) $(pangocairo_LIBS) $(confuse_LIBS) $(xinerama_LIBS) $(imlib2_LIBS) +awesome_menu_LDADD = $(X_LIBS) $(pangocairo_LIBS) $(confuse_LIBS) $(xinerama_LIBS) $(image_LIBS) if HAVE_XMLTO if HAVE_ASCIIDOC diff --git a/common/draw.c b/common/draw.c index 41244841a..c85986dd4 100644 --- a/common/draw.c +++ b/common/draw.c @@ -20,7 +20,12 @@ */ #include +#ifdef HAVE_GTK +#include +#include +#else #include +#endif #include #include @@ -608,6 +613,71 @@ void draw_image_from_argb_data(DrawCtx *ctx, int x, int y, int w, int h, cairo_surface_destroy(source); } +#ifdef HAVE_GTK + +/** Draw an image (PNG format only) from a file to a draw context + * \param ctx Draw context to draw to + * \param x x coordinate + * \param y y coordinate + * \param wanted_h wanted height: if > 0, image will be resized + * \param filename file name to draw + */ +void +draw_image(DrawCtx *ctx, int x, int y, int wanted_h, const char *filename) +{ + + double ratio; + int w, h; + cairo_t *cr; + GdkPixbuf *pixbuf; + GError *error=NULL; + + if(!(pixbuf = gdk_pixbuf_new_from_file(filename,&error))) + return warn("cannot load image %s: %s\n", filename, error->message); + + w = gdk_pixbuf_get_width(pixbuf); + h = gdk_pixbuf_get_height(pixbuf); + + cr = cairo_create(ctx->surface); + if(wanted_h > 0 && h > 0) + { + ratio = (double) wanted_h / (double) h; + cairo_scale(cr, ratio, ratio); + gdk_cairo_set_source_pixbuf(cr, pixbuf, x/ratio, y/ratio); + } + else + gdk_cairo_set_source_pixbuf(cr, pixbuf, (double) x, (double) y); + + cairo_paint(cr); + + gdk_pixbuf_unref(pixbuf); + + cairo_destroy(cr); +} + +/** get an image size + * \param filename file name + * \return area_t structure with width and height set to image size + */ +area_t +draw_get_image_size(const char *filename) +{ + area_t size = { -1, -1, -1, -1, NULL, NULL }; + gint width, height; + + if(gdk_pixbuf_get_file_info(filename, &width, &height)) + { + size.width = width; + size.height = height; + } + else + warn("cannot load image %s: %s\n", filename, "format unrecognized"); + + return size; +} + +#else /* HAVE_GTK */ + static const char * draw_imlib_load_strerror(Imlib_Load_Error e) { @@ -719,6 +789,7 @@ draw_get_image_size(const char *filename) return size; } +#endif /* HAVE_GTK */ /** Rotate a drawable * \param ctx Draw context to draw to diff --git a/configure.ac b/configure.ac index 2eb99f646..09d52daad 100644 --- a/configure.ac +++ b/configure.ac @@ -117,8 +117,16 @@ PKG_CHECK_MODULES([xinerama], [xinerama],, [AC_MSG_ERROR([awesome requires Xinerama.])]) PKG_CHECK_MODULES([xrandr], [xrandr],, [AC_MSG_ERROR([awesome requires Xrandr.])]) -PKG_CHECK_MODULES([imlib2], [imlib2],, - [AC_MSG_ERROR([awesome requires Imlib2.])]) +AC_ARG_WITH([gtk], AS_HELP_STRING([--with-gtk], [Build with gtk library (default: disabled)])) + +if test "x$with_gtk" == "xyes"; then + PKG_CHECK_MODULES([image], [gtk+-2.0 >= 2.2],, + [AC_MSG_ERROR([Cannot find gtk+-2.0 >= 2.2])]) + AC_DEFINE([HAVE_GTK],1,[Defined to use gtk]) +else + PKG_CHECK_MODULES([image], [imlib2],, + [AC_MSG_ERROR([awesome requires Imlib2.])]) +fi # Checks for header files. AC_PATH_X