From 0df27e0f6a7bbfcfbbec0432536b0d41bfd094b3 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 30 Dec 2007 12:33:57 +0100 Subject: [PATCH] split the display part of statusbar_draw(), move it to new statusbar_display(), and call it for expose events --- draw.c | 13 +++++++++++-- draw.h | 3 ++- event.c | 2 +- statusbar.c | 39 +++++++++++++++++++++++++++++---------- statusbar.h | 1 + 5 files changed, 44 insertions(+), 14 deletions(-) diff --git a/draw.c b/draw.c index 0c1029e4..cad2555d 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 b0989f8d..fc2df2ae 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 86e72460..2defe275 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 51351dbc..af7d85a9 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 13c6f6ad..5e21b1cd 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);