diff --git a/Makefile.am b/Makefile.am index 55ccfc22f..9b2b6492d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -140,7 +140,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) +awesome_LDADD = $(X_LIBS) $(PANGOCAIRO_LIBS) $(CONFUSE_LIBS) $(XRANDR_LIBS) $(XINERAMA_LIBS) $(XPM_LIBS) bin_PROGRAMS += awesome-client awesome_client_SOURCES = \ @@ -159,7 +159,7 @@ awesome_message_SOURCES = \ common/xscreen.h common/xscreen.c \ awesome-message.c -awesome_message_LDADD = $(X_LIBS) $(PANGOCAIRO_LIBS) $(CONFUSE_LIBS) $(XINERAMA_LIBS) +awesome_message_LDADD = $(X_LIBS) $(PANGOCAIRO_LIBS) $(CONFUSE_LIBS) $(XINERAMA_LIBS) $(XPM_LIBS) bin_PROGRAMS += awesome-menu awesome_menu_SOURCES = \ @@ -171,7 +171,7 @@ awesome_menu_SOURCES = \ common/xutil.h common/xutil.c \ awesome-menu.c -awesome_menu_LDADD = $(X_LIBS) $(PANGOCAIRO_LIBS) $(CONFUSE_LIBS) $(XINERAMA_LIBS) +awesome_menu_LDADD = $(X_LIBS) $(PANGOCAIRO_LIBS) $(CONFUSE_LIBS) $(XINERAMA_LIBS) $(XPM_LIBS) if HAVE_XMLTO if HAVE_ASCIIDOC diff --git a/awesome-message.c b/awesome-message.c index 106a2ea92..aded3561f 100644 --- a/awesome-message.c +++ b/awesome-message.c @@ -184,7 +184,7 @@ main(int argc, char **argv) if(argc - optind >= 2) { - icon_geometry = draw_get_image_size(argv[optind + 1]); + icon_geometry = draw_image_size_format_png(argv[optind + 1]); if(icon_geometry.width <= 0 || icon_geometry.height <= 0) eprint("invalid image\n"); else diff --git a/common/draw.c b/common/draw.c index 10e5e52f0..f544420a4 100644 --- a/common/draw.c +++ b/common/draw.c @@ -22,6 +22,8 @@ #include #include +#include + #include #include #include @@ -581,6 +583,26 @@ void draw_image_from_argb_data(DrawCtx *ctx, int x, int y, int w, int h, cairo_surface_destroy(source); } +static void +draw_image_format_xpm(DrawCtx *ctx, int x, int y, char *filename) +{ + Pixmap pxm, shapemask; + XpmAttributes attr; + + if(XpmReadFileToPixmap(ctx->display, ctx->drawable, + filename, + &pxm, &shapemask, + &attr)) + return warn("cannot load image %s\n", filename); + + XCopyArea(ctx->display, pxm, ctx->drawable, + DefaultGC(ctx->display, ctx->phys_screen), + 0, 0, attr.width, attr.height, + x, y); + + XFreePixmap(ctx->display, pxm); +} + /** Draw an image (PNG format only) from a file to a draw context * \param ctx Draw context to draw to * \param x x coordinate @@ -588,8 +610,8 @@ void draw_image_from_argb_data(DrawCtx *ctx, int x, int y, int w, int h, * \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) +static void +draw_image_format_png(DrawCtx *ctx, int x, int y, int wanted_h, const char *filename) { double ratio; int h; @@ -619,12 +641,29 @@ draw_image(DrawCtx *ctx, int x, int y, int wanted_h, const char *filename) cairo_surface_destroy(source); } +void +draw_image(DrawCtx *ctx, int x, int y, int wanted_h, char *filename) +{ + char *dot; + + if(!a_strlen(filename)) + return; + + if(!(dot = strrchr(filename, '.'))) + return warn("cannot determine file type for %s\n", filename); + + if(!a_strcasecmp(++dot, "png")) + draw_image_format_png(ctx, x, y, wanted_h, filename); + else if(!a_strcasecmp(dot, "xpm")) + draw_image_format_xpm(ctx, x, y, filename); +} + /** Get an imag size (PNG format only) * \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) +draw_image_size_format_png(const char *filename) { area_t size = { -1, -1, -1, -1, NULL, NULL }; cairo_surface_t *surface; diff --git a/common/draw.h b/common/draw.h index 4d2e2afbb..94df16eaf 100644 --- a/common/draw.h +++ b/common/draw.h @@ -130,9 +130,9 @@ void draw_graph_setup(DrawCtx *); void draw_graph(DrawCtx *, area_t, int *, int *, int, Position, area_t, XColor *, XColor *, XColor *); void draw_graph_line(DrawCtx *, area_t, int *, int, Position, area_t, XColor *, XColor *, XColor *); void draw_circle(DrawCtx *, int, int, int, Bool, XColor); -void draw_image(DrawCtx *, int, int, int, const char *); +void draw_image(DrawCtx *, int, int, int, char *); void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char *); -area_t draw_get_image_size(const char *filename); +area_t draw_image_size_format_png(const char *filename); Drawable draw_rotate(DrawCtx *, int, double, int, int); unsigned short draw_textwidth(Display *, font_t *, char *); Alignment draw_align_get_from_str(const char *); diff --git a/configure.ac b/configure.ac index 94ea525b0..0a9b942a5 100644 --- a/configure.ac +++ b/configure.ac @@ -114,6 +114,8 @@ 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([XPM], [xpm],, + [AC_MSG_ERROR([awesome requires XPM.])]) # Checks for header files. AC_PATH_X diff --git a/widgets/focusicon.c b/widgets/focusicon.c index 71860cc77..a0b8588d7 100644 --- a/widgets/focusicon.c +++ b/widgets/focusicon.c @@ -48,7 +48,7 @@ focusicon_draw(Widget *widget, DrawCtx *ctx, int offset, if((r = rule_matching_client(sel)) && r->icon) { - area = draw_get_image_size(r->icon); + area = draw_image_size_format_png(r->icon); widget->area.width = ((double) widget->statusbar->height / (double) area.height) * area.width; if(!widget->user_supplied_x) diff --git a/widgets/iconbox.c b/widgets/iconbox.c index 3a3410f9f..4fc20e403 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -36,7 +36,7 @@ iconbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { Data *d = widget->data; - area_t area = draw_get_image_size(d->image); + area_t area = draw_image_size_format_png(d->image); /* image not valid */ if(area.width < 0 || area.height < 0) diff --git a/widgets/layoutinfo.c b/widgets/layoutinfo.c index 5f1c7cfd7..1d6ef076c 100644 --- a/widgets/layoutinfo.c +++ b/widgets/layoutinfo.c @@ -35,7 +35,7 @@ layoutinfo_draw(Widget *widget, int used __attribute__ ((unused))) { Tag **curtags = tags_get_current(widget->statusbar->screen); - area_t area = draw_get_image_size(curtags[0]->layout->image); + area_t area = draw_image_size_format_png(curtags[0]->layout->image); if(!widget->user_supplied_x) widget->area.x = widget_calculate_offset(widget->statusbar->width, diff --git a/widgets/tasklist.c b/widgets/tasklist.c index 218000808..ebcf9174b 100644 --- a/widgets/tasklist.c +++ b/widgets/tasklist.c @@ -136,7 +136,7 @@ tasklist_draw(Widget *widget, DrawCtx *ctx, int offset, int used) if((r = rule_matching_client(c)) && r->icon) { - area = draw_get_image_size(r->icon); + area = draw_image_size_format_png(r->icon); if(area.width > 0 && area.height > 0) { icon_width = ((double) widget->statusbar->height / (double) area.height) * area.width;