Add preliminary support for XPM format

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-03-19 17:34:05 +01:00
parent 58402c9641
commit df2555d9fe
9 changed files with 54 additions and 13 deletions

View File

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

View File

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

View File

@ -22,6 +22,8 @@
#include <cairo.h>
#include <cairo-xlib.h>
#include <X11/xpm.h>
#include <langinfo.h>
#include <iconv.h>
#include <errno.h>
@ -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;

View File

@ -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 *);

View File

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

View File

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

View File

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

View File

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

View File

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