From 7ad43fe713a96517562982135ffaee29988e2e7d Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 23 Jan 2008 19:10:53 +0100 Subject: [PATCH] stop being stupid, use only one Drawable --- draw.c | 16 ++-------------- draw.h | 3 +-- statusbar.c | 25 +++++++++++++------------ 3 files changed, 16 insertions(+), 28 deletions(-) diff --git a/draw.c b/draw.c index 5912861c9..19d841e05 100644 --- a/draw.c +++ b/draw.c @@ -35,7 +35,7 @@ extern AwesomeConf globalconf; * \return draw context ref */ DrawCtx * -draw_get_context(int phys_screen, int width, int height) +draw_get_context(int phys_screen, int width, int height, Drawable dw) { DrawCtx *d = p_new(DrawCtx, 1); @@ -44,23 +44,11 @@ draw_get_context(int phys_screen, int width, int height) d->height = height; d->depth = DefaultDepth(globalconf.display, phys_screen); d->visual = DefaultVisual(globalconf.display, phys_screen); - d->drawable = XCreatePixmap(globalconf.display, - RootWindow(globalconf.display, phys_screen), - width, height, d->depth); + d->drawable = dw; return d; }; -/** Free a draw context and its drawable - * \param ctx the draw context to free - */ -void -draw_free_context(DrawCtx *ctx) -{ - XFreePixmap(globalconf.display, ctx->drawable); - p_delete(&ctx); -} - /** Draw text into a draw context * \param x x coord * \param y y coord diff --git a/draw.h b/draw.h index 0b7256483..48464c637 100644 --- a/draw.h +++ b/draw.h @@ -52,8 +52,7 @@ typedef struct int depth; } DrawCtx; -DrawCtx *draw_get_context(int, int, int); -void draw_free_context(DrawCtx *); +DrawCtx *draw_get_context(int, int, int, Drawable); void draw_text(DrawCtx *, Area, Alignment, int, XftFont *, const char *, XColor fg, XColor bg); void draw_rectangle(DrawCtx *, Area, Bool, XColor); void draw_graph(DrawCtx *, int, int, int, int *, int, XColor); diff --git a/statusbar.c b/statusbar.c index 8c723ff7f..60321f15b 100644 --- a/statusbar.c +++ b/statusbar.c @@ -76,16 +76,16 @@ statusbar_draw(Statusbar *statusbar) Widget *widget, *last_drawn = NULL; int left = 0, right = 0; Area rectangle = { 0, 0, 0, 0 }; + Drawable d; /* don't waste our time */ if(statusbar->position == Off) return; - XFreePixmap(globalconf.display, statusbar->sw->drawable); - DrawCtx *ctx = draw_get_context(phys_screen, statusbar->width, - statusbar->height); + statusbar->height, + statusbar->sw->drawable); rectangle.width = statusbar->width; rectangle.height = statusbar->height; @@ -119,22 +119,23 @@ statusbar_draw(Statusbar *statusbar) switch(statusbar->position) { case Right: - statusbar->sw->drawable = draw_rotate(ctx, phys_screen, M_PI_2, - statusbar->height, 0); - draw_free_context(ctx); + d = draw_rotate(ctx, phys_screen, M_PI_2, + statusbar->height, 0); + XFreePixmap(globalconf.display, statusbar->sw->drawable); + statusbar->sw->drawable = d; break; case Left: - statusbar->sw->drawable = draw_rotate(ctx, phys_screen, - M_PI_2, - 0, statusbar->width); - draw_free_context(ctx); + d = draw_rotate(ctx, phys_screen, - M_PI_2, + 0, statusbar->width); + XFreePixmap(globalconf.display, statusbar->sw->drawable); + statusbar->sw->drawable = d; break; default: - statusbar->sw->drawable = ctx->drawable; - /* just delete the struct, don't delete the drawable */ - p_delete(&ctx); break; } + p_delete(&ctx); + statusbar_display(statusbar); }