diff --git a/draw.c b/draw.c index 0c1029e41..cad2555dc 100644 --- a/draw.c +++ b/draw.c @@ -30,7 +30,7 @@ extern AwesomeConf globalconf; DrawCtx * -draw_get_context(Drawable drawable, int phys_screen, int width, int height) +draw_get_context(int phys_screen, int width, int height) { DrawCtx *d = p_new(DrawCtx, 1); @@ -39,11 +39,20 @@ draw_get_context(Drawable drawable, 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 = drawable; + d->drawable = XCreatePixmap(globalconf.display, + RootWindow(globalconf.display, phys_screen), + width, height, d->depth); return d; }; +void +draw_free_context(DrawCtx *ctx) +{ + XFreePixmap(globalconf.display, ctx->drawable); + p_delete(&ctx); +} + void draw_text(DrawCtx *ctx, int x, int y, int w, int h, XftFont *font, const char *text, XColor fg, XColor bg) { diff --git a/draw.h b/draw.h index b0989f8dd..fc2df2ae9 100644 --- a/draw.h +++ b/draw.h @@ -41,7 +41,8 @@ typedef struct int depth; } DrawCtx; -DrawCtx *draw_get_context(Drawable, int, int, int); +DrawCtx *draw_get_context(int, int, int); +void draw_free_context(DrawCtx *); void draw_text(DrawCtx *, int, int, int, int, XftFont *, const char *, XColor fg, XColor bg); void draw_rectangle(DrawCtx *, int, int, int, int, Bool, XColor); void draw_circle(DrawCtx *, int, int, int, Bool, XColor); diff --git a/event.c b/event.c index 86e724602..2defe2757 100644 --- a/event.c +++ b/event.c @@ -251,7 +251,7 @@ handle_event_expose(XEvent *e) if(!ev->count) for(screen = 0; screen < get_screen_count(); screen++) if(globalconf.screens[screen].statusbar->window == ev->window) - statusbar_draw(screen); + statusbar_display(screen); } void diff --git a/statusbar.c b/statusbar.c index 51351dbc1..af7d85a9a 100644 --- a/statusbar.c +++ b/statusbar.c @@ -45,7 +45,7 @@ statusbar_draw(int screen) if(vscreen.statusbar->position == BarOff) return; - DrawCtx *ctx = draw_get_context(vscreen.statusbar->drawable, phys_screen, + DrawCtx *ctx = draw_get_context(phys_screen, vscreen.statusbar->width, vscreen.statusbar->height); draw_rectangle(ctx, @@ -72,8 +72,8 @@ statusbar_draw(int screen) if (widget->alignment == AlignFlex) left += widget->draw(widget, ctx, left, (left + right)); - if(vscreen.statusbar->position == BarRight || - vscreen.statusbar->position == BarLeft) + if(vscreen.statusbar->position == BarRight + || vscreen.statusbar->position == BarLeft) { Drawable d; if(vscreen.statusbar->position == BarRight) @@ -88,21 +88,40 @@ statusbar_draw(int screen) - M_PI_2, 0, vscreen.statusbar->width); - XCopyArea(globalconf.display, d, + + vscreen.statusbar->drawable = d; + draw_free_context(ctx); + } + else + { + vscreen.statusbar->drawable = ctx->drawable; + /* just delete the struct, don't delete the drawable */ + p_delete(&ctx); + } + + + statusbar_display(screen); +} + + +void +statusbar_display(int screen) +{ + VirtScreen vscreen = globalconf.screens[screen]; + int phys_screen = get_phys_screen(screen); + + if(vscreen.statusbar->position == BarRight + || vscreen.statusbar->position == BarLeft) + XCopyArea(globalconf.display, vscreen.statusbar->drawable, vscreen.statusbar->window, DefaultGC(globalconf.display, phys_screen), 0, 0, vscreen.statusbar->height, vscreen.statusbar->width, 0, 0); - XFreePixmap(globalconf.display, d); - } else - XCopyArea(globalconf.display, ctx->drawable, + XCopyArea(globalconf.display, vscreen.statusbar->drawable, vscreen.statusbar->window, DefaultGC(globalconf.display, phys_screen), 0, 0, vscreen.statusbar->width, vscreen.statusbar->height, 0, 0); - - p_delete(&ctx); - XSync(globalconf.display, False); } void diff --git a/statusbar.h b/statusbar.h index 13c6f6ad3..5e21b1cdc 100644 --- a/statusbar.h +++ b/statusbar.h @@ -26,6 +26,7 @@ void statusbar_init(int); void statusbar_draw(int); +void statusbar_display(int); int statusbar_get_position_from_str(const char *); void statusbar_update_position(int);