move drawable to statusbar struct

This commit is contained in:
Julien Danjou 2007-09-15 14:58:41 +02:00
parent b490276b66
commit 6a11f10764
4 changed files with 26 additions and 25 deletions

View File

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

View File

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

35
draw.c
View File

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

View File

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