From 7cff3567e3a4b944b616096874cd3ceb0fb7300d Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Fri, 30 May 2008 17:53:10 +0200 Subject: [PATCH] [statusbar] Fix left and right statusbars alpha support Signed-off-by: Julien Danjou --- common/draw.c | 30 +++++++++++++++++------------- common/draw.h | 2 +- statusbar.c | 45 ++++++++++++++++++++++++++++++++++++--------- titlebar.c | 8 ++++++-- 4 files changed, 60 insertions(+), 25 deletions(-) diff --git a/common/draw.c b/common/draw.c index 22f969288..325b0bb8f 100644 --- a/common/draw.c +++ b/common/draw.c @@ -892,18 +892,23 @@ draw_get_image_size(const char *filename) } #endif /* WITH_IMLIB2 */ -/** Rotate a drawable - * \param ctx Draw context to draw to - * \param dest Drawable to draw the result - * \param dest_w Drawable width - * \param dest_h Drawable height - * \param angle angle to rotate - * \param tx translate to this x coordinate - * \param ty translate to this y coordinate - * \return new rotated drawable +/** Rotate a drawable. + * \param ctx Draw context to draw with. + * \param src Drawable to draw from. + * \param dest Drawable to draw to. + * \param src_w Drawable width. + * \param src_h Drawable height. + * \param dest_w Drawable width. + * \param dest_h Drawable height. + * \param angle angle to rotate. + * \param tx Translate to this x coordinate. + * \param ty Translate to this y coordinate. */ void -draw_rotate(draw_context_t *ctx, xcb_drawable_t dest, int dest_w, int dest_h, +draw_rotate(draw_context_t *ctx, + xcb_drawable_t src, xcb_drawable_t dest, + int src_w, int src_h, + int dest_w, int dest_h, double angle, int tx, int ty) { cairo_surface_t *surface, *source; @@ -911,8 +916,8 @@ draw_rotate(draw_context_t *ctx, xcb_drawable_t dest, int dest_w, int dest_h, surface = cairo_xcb_surface_create(ctx->connection, dest, ctx->visual, dest_w, dest_h); - source = cairo_xcb_surface_create(ctx->connection, ctx->drawable, - ctx->visual, ctx->width, ctx->height); + source = cairo_xcb_surface_create(ctx->connection, src, + ctx->visual, src_w, src_h); cr = cairo_create (surface); cairo_translate(cr, tx, ty); @@ -1049,7 +1054,6 @@ xcolor_new(xcb_connection_t *conn, int phys_screen, const char *colstr, xcolor_t colnum = strtoul(buf, NULL, 16); p_delete(&buf); color->alpha = RGB_COLOR_8_TO_16(strtoul(&colstr[7], NULL, 16)); - printf("%d alpha\n", color->alpha); if(errno != 0) { warn("awesome: error, invalid color '%s'", colstr); diff --git a/common/draw.h b/common/draw.h index 57833ec84..805c54ae7 100644 --- a/common/draw.h +++ b/common/draw.h @@ -141,7 +141,7 @@ void draw_circle(draw_context_t *, int, int, int, bool, xcolor_t); void draw_image(draw_context_t *, int, int, int, const char *); void draw_image_from_argb_data(draw_context_t *, int, int, int, int, int, unsigned char *); area_t draw_get_image_size(const char *filename); -void draw_rotate(draw_context_t *, xcb_drawable_t, int, int, double, int, int); +void draw_rotate(draw_context_t *, xcb_drawable_t, xcb_drawable_t, int, int, int, int, double, int, int); area_t draw_text_extents(xcb_connection_t *, int, font_t *, const char *); alignment_t draw_align_get_from_str(const char *); bool xcolor_new(xcb_connection_t *, int, const char *, xcolor_t *); diff --git a/statusbar.c b/statusbar.c index 59810a7da..135badef5 100644 --- a/statusbar.c +++ b/statusbar.c @@ -49,7 +49,7 @@ statusbar_draw(statusbar_t *statusbar) char *data; xcb_get_property_reply_t *prop_r; xcb_get_property_cookie_t prop_c; - area_t rectangle = { 0, 0, 0, 0, NULL, NULL }; + area_t rectangle = { 0, 0, 0, 0, NULL, NULL }, rootsize;; xcb_atom_t rootpix_atom, pixmap_atom; xutil_intern_atom_request_t rootpix_atom_req, pixmap_atom_req; @@ -80,12 +80,37 @@ statusbar_draw(statusbar_t *statusbar) if((data = xcb_get_property_value(prop_r))) { rootpix = *(xcb_pixmap_t *) data; - xcb_copy_area(globalconf.connection, rootpix, - statusbar->sw->drawable, statusbar->sw->gc, - statusbar->sw->geometry.x, statusbar->sw->geometry.y, - 0, 0, - statusbar->sw->geometry.width, - statusbar->sw->geometry.height); + switch(statusbar->position) + { + case Left: + rootsize = get_display_area(statusbar->phys_screen, NULL, NULL); + draw_rotate(statusbar->ctx, + rootpix, statusbar->ctx->drawable, + rootsize.width, rootsize.height, + statusbar->width, statusbar->height, + M_PI_2, + statusbar->sw->geometry.y + statusbar->width, + - statusbar->sw->geometry.x); + break; + case Right: + rootsize = get_display_area(statusbar->phys_screen, NULL, NULL); + draw_rotate(statusbar->ctx, + rootpix, statusbar->ctx->drawable, + rootsize.width, rootsize.height, + statusbar->width, statusbar->height, + - M_PI_2, + - statusbar->sw->geometry.y, + statusbar->sw->geometry.x + statusbar->height); + break; + default: + xcb_copy_area(globalconf.connection, rootpix, + statusbar->sw->drawable, statusbar->sw->gc, + statusbar->sw->geometry.x, statusbar->sw->geometry.y, + 0, 0, + statusbar->sw->geometry.width, + statusbar->sw->geometry.height); + break; + } } p_delete(&prop_r); } @@ -110,12 +135,14 @@ statusbar_draw(statusbar_t *statusbar) switch(statusbar->position) { case Right: - draw_rotate(statusbar->ctx, statusbar->sw->drawable, + draw_rotate(statusbar->ctx, statusbar->ctx->drawable, statusbar->sw->drawable, + statusbar->ctx->width, statusbar->ctx->height, statusbar->ctx->height, statusbar->ctx->width, M_PI_2, statusbar->height, 0); break; case Left: - draw_rotate(statusbar->ctx, statusbar->sw->drawable, + draw_rotate(statusbar->ctx, statusbar->ctx->drawable, statusbar->sw->drawable, + statusbar->ctx->width, statusbar->ctx->height, statusbar->ctx->height, statusbar->ctx->width, - M_PI_2, 0, statusbar->width); break; diff --git a/titlebar.c b/titlebar.c index 5094b8fdd..6b3c9ca45 100644 --- a/titlebar.c +++ b/titlebar.c @@ -108,12 +108,16 @@ titlebar_draw(client_t *c) switch(c->titlebar.position) { case Left: - draw_rotate(ctx, c->titlebar_sw->drawable, ctx->height, ctx->width, + draw_rotate(ctx, ctx->drawable, c->titlebar_sw->drawable, + ctx->width, ctx->height, + ctx->height, ctx->width, - M_PI_2, 0, c->titlebar_sw->geometry.height); xcb_free_pixmap(globalconf.connection, dw); break; case Right: - draw_rotate(ctx, c->titlebar_sw->drawable, ctx->height, ctx->width, + draw_rotate(ctx, ctx->drawable, c->titlebar_sw->drawable, + ctx->width, ctx->height, + ctx->height, ctx->width, M_PI_2, c->titlebar_sw->geometry.width, 0); xcb_free_pixmap(globalconf.connection, dw); default: