[draw] Add option to link against GTK instead of Imlib2
I added an option to the configure script to link against gdk instead of imlib2. Most people already have gdk installed so that way they can use awesome without installing imlib2, and gdk's pixbuf was explicitly designed to replace imlib2. Also, a nice side effect is that GDK works directly with cairo surfaces, so the process of loading images should be faster, although since awesome does very little image loading it probably wont have a noticable impact on performance, but it certainly won't hurt. Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
6f001de781
commit
cee3e9b60d
|
@ -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
|
||||
|
|
|
@ -20,7 +20,12 @@
|
|||
*/
|
||||
|
||||
#include <cairo-xlib.h>
|
||||
#ifdef HAVE_GTK
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk-pixbuf/gdk-pixbuf.h>
|
||||
#else
|
||||
#include <Imlib2.h>
|
||||
#endif
|
||||
|
||||
#include <langinfo.h>
|
||||
#include <iconv.h>
|
||||
|
@ -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
|
||||
|
|
10
configure.ac
10
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_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
|
||||
|
|
Loading…
Reference in New Issue