From 3d71a2e9a44257ceb87c7033b0c63d5b1a4c4421 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 29 Dec 2007 21:44:44 +0100 Subject: [PATCH] merge draw_get_image_{width,height}() into draw_get_image_size() --- draw.c | 25 ++++++------------------- draw.h | 12 ++++++++++-- screen.h | 9 --------- widgets/iconbox.c | 8 ++++---- widgets/netwmicon.c | 14 ++++++-------- 5 files changed, 26 insertions(+), 42 deletions(-) diff --git a/draw.c b/draw.c index 5efce78d..a57f6473 100644 --- a/draw.c +++ b/draw.c @@ -204,32 +204,19 @@ draw_image(DrawCtx *ctx, int x, int y, int wanted_h, const char *filename) } -int -draw_get_image_width(const char *filename) +Area +draw_get_image_size(const char *filename) { - int width; + Area size; cairo_surface_t *surface; surface = cairo_image_surface_create_from_png(filename); cairo_image_surface_get_width(surface); - width = cairo_image_surface_get_width(surface); + size.width = cairo_image_surface_get_width(surface); + size.height = cairo_image_surface_get_height(surface); cairo_surface_destroy(surface); - return width; -} - -int -draw_get_image_height(const char* filename) -{ - int height; - cairo_surface_t *surface; - - surface = cairo_image_surface_create_from_png(filename); - cairo_image_surface_get_height(surface); - height = cairo_image_surface_get_height(surface); - cairo_surface_destroy(surface); - - return height; + return size; } Drawable diff --git a/draw.h b/draw.h index dbd2c34d..a1813e0f 100644 --- a/draw.h +++ b/draw.h @@ -22,6 +22,15 @@ #ifndef AWESOME_DRAW_H #define AWESOME_DRAW_H +typedef struct +{ + /* Co-ords of upper left corner */ + int x; + int y; + int width; + int height; +} Area; + typedef struct { Display *display; @@ -40,8 +49,7 @@ void draw_rectangle(DrawCtx *, int, int, int, int, Bool, XColor); void draw_circle(DrawCtx *, int, int, int, Bool, XColor); void draw_image(DrawCtx *, int, int, int, const char *); void draw_image_from_argb_data(DrawCtx *, int, int, int, int, int, unsigned char *); -int draw_get_image_width(const char *filename); -int draw_get_image_height(const char *filename); +Area draw_get_image_size(const char *filename); Drawable draw_rotate(DrawCtx *, int, double, int, int); unsigned short textwidth(XftFont *, char *); diff --git a/screen.h b/screen.h index 9dbd823b..f4b5f564 100644 --- a/screen.h +++ b/screen.h @@ -26,15 +26,6 @@ #include -typedef struct -{ - /* Co-ords of upper left corner */ - int x; - int y; - int width; - int height; -} Area; - Area get_screen_area(int, Statusbar *, Padding *); Area get_display_area(int, Statusbar *, Padding *); int get_screen_bycoord(int, int); diff --git a/widgets/iconbox.c b/widgets/iconbox.c index 820ee560..5ca79bcf 100644 --- a/widgets/iconbox.c +++ b/widgets/iconbox.c @@ -29,10 +29,10 @@ static int iconbox_draw(Widget *widget, DrawCtx *ctx, int offset, int used __attribute__ ((unused))) { - int height; - widget->width = draw_get_image_width(widget->data); - height = draw_get_image_height(widget->data); - widget->width = ((double) widget->statusbar->height / height) * widget->width; + Area area; + + area = draw_get_image_size(widget->data); + widget->width = ((double) widget->statusbar->height / area.height) * area.width; widget->location = widget_calculate_offset(widget->statusbar->width, widget->width, offset, diff --git a/widgets/netwmicon.c b/widgets/netwmicon.c index 6df49ffd..cb071e5b 100644 --- a/widgets/netwmicon.c +++ b/widgets/netwmicon.c @@ -38,9 +38,9 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, unsigned char *wdata; Atom type; int format, width, height, size, i; + Area area; unsigned long items, rest; unsigned char *image, *imgdata; - char* icon; Rule* r; Client *sel = focus_get_current_client(widget->statusbar->screen); @@ -50,17 +50,15 @@ netwmicon_draw(Widget *widget, DrawCtx *ctx, int offset, for(r = globalconf.rules; r; r = r->next) if(r->icon && client_match_rule(sel, r)) { - icon = r->icon; - width = draw_get_image_width(icon); - height = draw_get_image_height(icon); - width = ((double) widget->statusbar->height / (double) height) * width; + area = draw_get_image_size(r->icon); + widget->width = ((double) widget->statusbar->height / (double) area.height) * area.width; widget->location = widget_calculate_offset(widget->statusbar->width, - width, + widget->width, offset, widget->alignment); - draw_image(ctx, widget->location, 0, widget->statusbar->height, icon); + draw_image(ctx, widget->location, 0, widget->statusbar->height, r->icon); - return width; + return widget->width; } if(XGetWindowProperty(ctx->display, sel->win,