stop being stupid, use only one Drawable

This commit is contained in:
Julien Danjou 2008-01-23 19:10:53 +01:00
parent 9e1994d879
commit 7ad43fe713
3 changed files with 16 additions and 28 deletions

16
draw.c
View File

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

3
draw.h
View File

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

View File

@ -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,
d = draw_rotate(ctx, phys_screen, M_PI_2,
statusbar->height, 0);
draw_free_context(ctx);
XFreePixmap(globalconf.display, statusbar->sw->drawable);
statusbar->sw->drawable = d;
break;
case Left:
statusbar->sw->drawable = draw_rotate(ctx, phys_screen, - M_PI_2,
d = draw_rotate(ctx, phys_screen, - M_PI_2,
0, statusbar->width);
draw_free_context(ctx);
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);
}