From 6a11f1076458dea279e5182d9a2e59e0eb0ba801 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sat, 15 Sep 2007 14:58:41 +0200 Subject: [PATCH] move drawable to statusbar struct --- awesome.c | 4 ++-- config.h | 3 ++- draw.c | 35 +++++++++++++++++------------------ event.c | 9 +++++---- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/awesome.c b/awesome.c index d6d4d521a..56e8b102c 100644 --- a/awesome.c +++ b/awesome.c @@ -62,7 +62,7 @@ cleanup(Display *disp, DC *drawcontext, awesome_config *awesomeconf) else XFreeFont(disp, drawcontext->font.xfont); XUngrabKey(disp, AnyKey, AnyModifier, DefaultRootWindow(disp)); - XFreePixmap(disp, drawcontext->drawable); + XFreePixmap(disp, awesomeconf->statusbar.drawable); XFreeGC(disp, drawcontext->gc); XDestroyWindow(disp, awesomeconf->statusbar.window); XFreeCursor(disp, drawcontext->cursor[CurNormal]); @@ -164,7 +164,7 @@ setup(Display *disp, DC *drawcontext, awesome_config *awesomeconf) updatebarpos(disp, awesomeconf->statusbar); XMapRaised(disp, awesomeconf->statusbar.window); /* pixmap for everything */ - drawcontext->drawable = XCreatePixmap(disp, DefaultRootWindow(disp), DisplayWidth(disp, DefaultScreen(disp)), awesomeconf->statusbar.height, DefaultDepth(disp, DefaultScreen(disp))); + awesomeconf->statusbar.drawable = XCreatePixmap(disp, DefaultRootWindow(disp), DisplayWidth(disp, DefaultScreen(disp)), awesomeconf->statusbar.height, DefaultDepth(disp, DefaultScreen(disp))); drawcontext->gc = XCreateGC(disp, DefaultRootWindow(disp), 0, 0); XSetLineAttributes(disp, drawcontext->gc, 1, LineSolid, CapButt, JoinMiter); if(!drawcontext->font.set) diff --git a/config.h b/config.h index 865b433d4..0893706d4 100644 --- a/config.h +++ b/config.h @@ -41,7 +41,6 @@ typedef struct int x, y, w, h; unsigned long norm[ColLast]; unsigned long sel[ColLast]; - Drawable drawable; GC gc; Cursor cursor[CurLast]; struct @@ -88,6 +87,8 @@ typedef struct int position; /** Window */ Window window; + /** Drawable object */ + Drawable drawable; } Statusbar; /** Main configuration structure */ diff --git a/draw.c b/draw.c index b13c00680..ee0672607 100644 --- a/draw.c +++ b/draw.c @@ -26,7 +26,7 @@ extern Client *clients, *sel, *stack; /* global client list and stack */ /* static */ static void -drawtext(Display *disp, DC drawcontext, const char *text, unsigned long col[ColLast]) +drawtext(Display *disp, DC drawcontext, Statusbar * statusbar, const char *text, unsigned long col[ColLast]) { int x, y, w, h; static char buf[256]; @@ -34,7 +34,7 @@ drawtext(Display *disp, DC drawcontext, const char *text, unsigned long col[ColL XRectangle r = { drawcontext.x, drawcontext.y, drawcontext.w, drawcontext.h }; XSetForeground(disp, drawcontext.gc, col[ColBG]); - XFillRectangles(disp, drawcontext.drawable, drawcontext.gc, &r, 1); + XFillRectangles(disp, statusbar->drawable, drawcontext.gc, &r, 1); if(!text) return; w = 0; @@ -62,13 +62,13 @@ drawtext(Display *disp, DC drawcontext, const char *text, unsigned long col[ColL } XSetForeground(disp, drawcontext.gc, col[ColFG]); if(drawcontext.font.set) - XmbDrawString(disp, drawcontext.drawable, drawcontext.font.set, drawcontext.gc, x, y, buf, len); + XmbDrawString(disp, statusbar->drawable, drawcontext.font.set, drawcontext.gc, x, y, buf, len); else - XDrawString(disp, drawcontext.drawable, drawcontext.gc, x, y, buf, len); + XDrawString(disp, statusbar->drawable, drawcontext.gc, x, y, buf, len); } static void -drawsquare(Bool filled, Bool empty, unsigned long col[ColLast], Display *disp, DC drawcontext) +drawsquare(Bool filled, Bool empty, unsigned long col[ColLast], Display *disp, DC drawcontext, Statusbar *statusbar) { int x; XGCValues gcv; @@ -82,12 +82,12 @@ drawsquare(Bool filled, Bool empty, unsigned long col[ColLast], Display *disp, D if(filled) { r.width = r.height = x + 1; - XFillRectangles(disp, drawcontext.drawable, drawcontext.gc, &r, 1); + XFillRectangles(disp, statusbar->drawable, drawcontext.gc, &r, 1); } else if(empty) { r.width = r.height = x; - XDrawRectangles(disp, drawcontext.drawable, drawcontext.gc, &r, 1); + XDrawRectangles(disp, statusbar->drawable, drawcontext.gc, &r, 1); } } @@ -106,7 +106,6 @@ isoccupied(unsigned int t) return False; } - /* extern */ unsigned int @@ -132,18 +131,18 @@ drawstatusbar(Display *disp, DC *drawcontext, awesome_config * awesomeconf) drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->tags[i], drawcontext->font.height); if(awesomeconf->selected_tags[i]) { - drawtext(disp, *drawcontext, awesomeconf->tags[i], drawcontext->sel); - drawsquare(sel && sel->tags[i], isoccupied(i), drawcontext->sel, disp, *drawcontext); + drawtext(disp, *drawcontext, &awesomeconf->statusbar, awesomeconf->tags[i], drawcontext->sel); + drawsquare(sel && sel->tags[i], isoccupied(i), drawcontext->sel, disp, *drawcontext, &awesomeconf->statusbar); } else { - drawtext(disp, *drawcontext, awesomeconf->tags[i], drawcontext->norm); - drawsquare(sel && sel->tags[i], isoccupied(i), drawcontext->norm, disp, *drawcontext); + drawtext(disp, *drawcontext, &awesomeconf->statusbar, awesomeconf->tags[i], drawcontext->norm); + drawsquare(sel && sel->tags[i], isoccupied(i), drawcontext->norm, disp, *drawcontext, &awesomeconf->statusbar); } drawcontext->x += drawcontext->w; } drawcontext->w = awesomeconf->statusbar.width; - drawtext(disp, *drawcontext, awesomeconf->current_layout->symbol, drawcontext->norm); + drawtext(disp, *drawcontext, &awesomeconf->statusbar, awesomeconf->current_layout->symbol, drawcontext->norm); x = drawcontext->x + drawcontext->w; drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->statustext, drawcontext->font.height); drawcontext->x = DisplayWidth(disp, DefaultScreen(disp)) - drawcontext->w; @@ -152,18 +151,18 @@ drawstatusbar(Display *disp, DC *drawcontext, awesome_config * awesomeconf) drawcontext->x = x; drawcontext->w = DisplayWidth(disp, DefaultScreen(disp)) - x; } - drawtext(disp, *drawcontext, awesomeconf->statustext, drawcontext->norm); + drawtext(disp, *drawcontext, &awesomeconf->statusbar, awesomeconf->statustext, drawcontext->norm); if((drawcontext->w = drawcontext->x - x) > awesomeconf->statusbar.height) { drawcontext->x = x; if(sel) { - drawtext(disp, *drawcontext, sel->name, drawcontext->sel); - drawsquare(sel->ismax, sel->isfloating, drawcontext->sel, disp, *drawcontext); + drawtext(disp, *drawcontext, &awesomeconf->statusbar, sel->name, drawcontext->sel); + drawsquare(sel->ismax, sel->isfloating, drawcontext->sel, disp, *drawcontext, &awesomeconf->statusbar); } else - drawtext(disp, *drawcontext, NULL, drawcontext->norm); + drawtext(disp, *drawcontext, &awesomeconf->statusbar, NULL, drawcontext->norm); } - XCopyArea(disp, drawcontext->drawable, awesomeconf->statusbar.window, drawcontext->gc, 0, 0, DisplayWidth(disp, DefaultScreen(disp)), awesomeconf->statusbar.height, 0, 0); + XCopyArea(disp, awesomeconf->statusbar.drawable, awesomeconf->statusbar.window, drawcontext->gc, 0, 0, DisplayWidth(disp, DefaultScreen(disp)), awesomeconf->statusbar.height, 0, 0); XSync(disp, False); } diff --git a/event.c b/event.c index abd57f2f3..cc69c1077 100644 --- a/event.c +++ b/event.c @@ -260,10 +260,11 @@ handle_event_configurenotify(XEvent * e, awesome_config *awesomeconf) { DisplayWidth(e->xany.display, DefaultScreen(e->xany.display)) = ev->width; DisplayHeight(e->xany.display, DefaultScreen(e->xany.display)) = ev->height; - XFreePixmap(e->xany.display, dc.drawable); - dc.drawable = XCreatePixmap(e->xany.display, DefaultRootWindow(e->xany.display), - DisplayWidth(e->xany.display, DefaultScreen(e->xany.display)), - awesomeconf->statusbar.height, DefaultDepth(e->xany.display, DefaultScreen(e->xany.display))); + XFreePixmap(e->xany.display, awesomeconf->statusbar.drawable); + awesomeconf->statusbar.drawable = XCreatePixmap(e->xany.display, DefaultRootWindow(e->xany.display), + DisplayWidth(e->xany.display, DefaultScreen(e->xany.display)), + awesomeconf->statusbar.height, + DefaultDepth(e->xany.display, DefaultScreen(e->xany.display))); XResizeWindow(e->xany.display, awesomeconf->statusbar.window, DisplayWidth(e->xany.display, DefaultScreen(e->xany.display)), awesomeconf->statusbar.height); updatebarpos(e->xany.display, awesomeconf->statusbar);