From 024ef921c9c9aa096aa45437cfb485f49004cc62 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Thu, 20 Mar 2008 09:08:15 +0100 Subject: [PATCH] Do not recreate statusbar DrawCtx on each draw, store it Signed-off-by: Julien Danjou --- statusbar.c | 68 ++++++++++++++++++++++++++--------------------------- structs.h | 2 ++ 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/statusbar.c b/statusbar.c index fbf502f32..8b45b521f 100644 --- a/statusbar.c +++ b/statusbar.c @@ -113,42 +113,16 @@ statusbar_draw(Statusbar *statusbar) area_t rectangle = { 0, 0, 0, 0, NULL, NULL }; Drawable d; - /* don't waste our time */ - switch(statusbar->position) - { - case Off: - return; - break; - case Right: - case Left: - /* we need a new pixmap this way [ ] to render */ - XFreePixmap(globalconf.display, statusbar->sw->drawable); - d = XCreatePixmap(globalconf.display, - RootWindow(globalconf.display, phys_screen), - statusbar->width, statusbar->height, - DefaultDepth(globalconf.display, phys_screen)); - statusbar->sw->drawable = d; - break; - default: - break; - } - - DrawCtx *ctx = draw_context_new(globalconf.display, - phys_screen, - statusbar->width, - statusbar->height, - statusbar->sw->drawable); - rectangle.width = statusbar->width; rectangle.height = statusbar->height; - draw_rectangle(ctx, rectangle, True, + draw_rectangle(statusbar->ctx, rectangle, True, globalconf.screens[statusbar->screen].styles.normal.bg); for(widget = statusbar->widgets; widget; widget = widget->next) if (widget->alignment == AlignLeft) { widget->cache.needs_update = False; - left += widget->draw(widget, ctx, left, (left + right)); + left += widget->draw(widget, statusbar->ctx, left, (left + right)); } /* renders right widget from last to first */ @@ -158,26 +132,26 @@ statusbar_draw(Statusbar *statusbar) if (widget->alignment == AlignRight) { widget->cache.needs_update = False; - right += widget->draw(widget, ctx, right, (left + right)); + right += widget->draw(widget, statusbar->ctx, right, (left + right)); } for(widget = statusbar->widgets; widget; widget = widget->next) if (widget->alignment == AlignFlex) { widget->cache.needs_update = False; - left += widget->draw(widget, ctx, left, (left + right)); + left += widget->draw(widget, statusbar->ctx, left, (left + right)); } switch(statusbar->position) { case Right: - d = draw_rotate(ctx, phys_screen, M_PI_2, + d = draw_rotate(statusbar->ctx, phys_screen, M_PI_2, statusbar->height, 0); XFreePixmap(globalconf.display, statusbar->sw->drawable); statusbar->sw->drawable = d; break; case Left: - d = draw_rotate(ctx, phys_screen, - M_PI_2, + d = draw_rotate(statusbar->ctx, phys_screen, - M_PI_2, 0, statusbar->width); XFreePixmap(globalconf.display, statusbar->sw->drawable); statusbar->sw->drawable = d; @@ -186,8 +160,6 @@ statusbar_draw(Statusbar *statusbar) break; } - draw_context_delete(ctx); - statusbar_display(statusbar); } @@ -213,6 +185,7 @@ void statusbar_init(Statusbar *statusbar) { Statusbar *sb; + Drawable dw; int phys_screen = get_phys_screen(statusbar->screen); area_t area = screen_get_area(statusbar->screen, globalconf.screens[statusbar->screen].statusbar, @@ -258,6 +231,33 @@ statusbar_init(Statusbar *statusbar) statusbar_position_update(statusbar); + switch(statusbar->position) + { + case Off: + return; + case Right: + case Left: + /* we need a new pixmap this way [ ] to render */ + dw = XCreatePixmap(globalconf.display, + RootWindow(globalconf.display, phys_screen), + statusbar->width, statusbar->height, + DefaultDepth(globalconf.display, phys_screen)); + statusbar->ctx = draw_context_new(globalconf.display, + phys_screen, + statusbar->width, + statusbar->height, + dw); + break; + default: + statusbar->ctx = draw_context_new(globalconf.display, + phys_screen, + statusbar->width, + statusbar->height, + statusbar->sw->drawable); + break; + } + + statusbar_draw(statusbar); } diff --git a/structs.h b/structs.h index fc5e0194e..938972217 100644 --- a/structs.h +++ b/structs.h @@ -159,6 +159,8 @@ struct Statusbar int screen; /** Widget list */ Widget *widgets; + /** Draw context */ + DrawCtx *ctx; /** Next and previous statusbars */ Statusbar *prev, *next; };