remove DC from global in draw.c
This commit is contained in:
parent
d6c63bd086
commit
9897e5a839
|
@ -300,7 +300,7 @@ main(int argc, char *argv[])
|
||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
parse_config(dpy, DefaultScreen(dpy), &dc, &awesomeconf);
|
parse_config(dpy, DefaultScreen(dpy), &dc, &awesomeconf);
|
||||||
setup(dpy, &awesomeconf);
|
setup(dpy, &awesomeconf);
|
||||||
drawstatus(dpy, &awesomeconf);
|
drawstatus(dpy, &dc, &awesomeconf);
|
||||||
scan(dpy, &awesomeconf);
|
scan(dpy, &awesomeconf);
|
||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
|
|
||||||
|
@ -354,7 +354,7 @@ main(int argc, char *argv[])
|
||||||
if(p > awesomeconf.statustext)
|
if(p > awesomeconf.statustext)
|
||||||
strncpy(awesomeconf.statustext, p + 1, sizeof(awesomeconf.statustext));
|
strncpy(awesomeconf.statustext, p + 1, sizeof(awesomeconf.statustext));
|
||||||
}
|
}
|
||||||
drawstatus(dpy, &awesomeconf);
|
drawstatus(dpy, &dc, &awesomeconf);
|
||||||
}
|
}
|
||||||
|
|
||||||
while(XPending(dpy))
|
while(XPending(dpy))
|
||||||
|
|
2
client.c
2
client.c
|
@ -275,7 +275,7 @@ focus(Display *disp, DC *drawcontext, Client * c, Bool selscreen, awesome_config
|
||||||
if(!selscreen)
|
if(!selscreen)
|
||||||
return;
|
return;
|
||||||
sel = c;
|
sel = c;
|
||||||
drawstatus(disp, awesomeconf);
|
drawstatus(disp, drawcontext, awesomeconf);
|
||||||
if(sel)
|
if(sel)
|
||||||
{
|
{
|
||||||
XSetWindowBorder(sel->display, sel->win, drawcontext->sel[ColBorder]);
|
XSetWindowBorder(sel->display, sel->win, drawcontext->sel[ColBorder]);
|
||||||
|
|
2
config.c
2
config.c
|
@ -247,7 +247,7 @@ parse_config(Display * disp, int scr, DC * drawcontext, awesome_config *awesomec
|
||||||
}
|
}
|
||||||
awesomeconf->layouts[i].symbol = config_setting_get_string_elem(confsublayouts, 0);
|
awesomeconf->layouts[i].symbol = config_setting_get_string_elem(confsublayouts, 0);
|
||||||
|
|
||||||
j = textw(awesomeconf->layouts[i].symbol);
|
j = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->layouts[i].symbol, drawcontext->font.height);
|
||||||
if(j > awesomeconf->statusbar.width)
|
if(j > awesomeconf->statusbar.width)
|
||||||
awesomeconf->statusbar.width = j;
|
awesomeconf->statusbar.width = j;
|
||||||
}
|
}
|
||||||
|
|
97
draw.c
97
draw.c
|
@ -21,21 +21,20 @@
|
||||||
|
|
||||||
#include "layout.h"
|
#include "layout.h"
|
||||||
|
|
||||||
extern DC dc; /* global draw context */
|
|
||||||
extern Client *clients, *sel, *stack; /* global client list and stack */
|
extern Client *clients, *sel, *stack; /* global client list and stack */
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
drawtext(Display *disp, const char *text, unsigned long col[ColLast])
|
drawtext(Display *disp, DC drawcontext, const char *text, unsigned long col[ColLast])
|
||||||
{
|
{
|
||||||
int x, y, w, h;
|
int x, y, w, h;
|
||||||
static char buf[256];
|
static char buf[256];
|
||||||
unsigned int len, olen;
|
unsigned int len, olen;
|
||||||
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
|
XRectangle r = { drawcontext.x, drawcontext.y, drawcontext.w, drawcontext.h };
|
||||||
|
|
||||||
XSetForeground(disp, dc.gc, col[ColBG]);
|
XSetForeground(disp, drawcontext.gc, col[ColBG]);
|
||||||
XFillRectangles(disp, dc.drawable, dc.gc, &r, 1);
|
XFillRectangles(disp, drawcontext.drawable, drawcontext.gc, &r, 1);
|
||||||
if(!text)
|
if(!text)
|
||||||
return;
|
return;
|
||||||
w = 0;
|
w = 0;
|
||||||
|
@ -44,13 +43,13 @@ drawtext(Display *disp, const char *text, unsigned long col[ColLast])
|
||||||
len = sizeof buf - 1;
|
len = sizeof buf - 1;
|
||||||
memcpy(buf, text, len);
|
memcpy(buf, text, len);
|
||||||
buf[len] = 0;
|
buf[len] = 0;
|
||||||
h = dc.font.ascent + dc.font.descent;
|
h = drawcontext.font.ascent + drawcontext.font.descent;
|
||||||
y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent;
|
y = drawcontext.y + (drawcontext.h / 2) - (h / 2) + drawcontext.font.ascent;
|
||||||
x = dc.x + (h / 2);
|
x = drawcontext.x + (h / 2);
|
||||||
/* shorten text if necessary */
|
/* shorten text if necessary */
|
||||||
while(len && (w = textnw(buf, len)) > dc.w - h)
|
while(len && (w = textnw(drawcontext.font.set, drawcontext.font.xfont, buf, len)) > drawcontext.w - h)
|
||||||
buf[--len] = 0;
|
buf[--len] = 0;
|
||||||
if(w > dc.w)
|
if(w > drawcontext.w)
|
||||||
return; /* too long */
|
return; /* too long */
|
||||||
if(len < olen)
|
if(len < olen)
|
||||||
{
|
{
|
||||||
|
@ -61,34 +60,34 @@ drawtext(Display *disp, const char *text, unsigned long col[ColLast])
|
||||||
if(len > 3)
|
if(len > 3)
|
||||||
buf[len - 3] = '.';
|
buf[len - 3] = '.';
|
||||||
}
|
}
|
||||||
XSetForeground(disp, dc.gc, col[ColFG]);
|
XSetForeground(disp, drawcontext.gc, col[ColFG]);
|
||||||
if(dc.font.set)
|
if(drawcontext.font.set)
|
||||||
XmbDrawString(disp, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
|
XmbDrawString(disp, drawcontext.drawable, drawcontext.font.set, drawcontext.gc, x, y, buf, len);
|
||||||
else
|
else
|
||||||
XDrawString(disp, dc.drawable, dc.gc, x, y, buf, len);
|
XDrawString(disp, drawcontext.drawable, drawcontext.gc, x, y, buf, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
drawsquare(Bool filled, Bool empty, unsigned long col[ColLast], Display *disp)
|
drawsquare(Bool filled, Bool empty, unsigned long col[ColLast], Display *disp, DC drawcontext)
|
||||||
{
|
{
|
||||||
int x;
|
int x;
|
||||||
XGCValues gcv;
|
XGCValues gcv;
|
||||||
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
|
XRectangle r = { drawcontext.x, drawcontext.y, drawcontext.w, drawcontext.h };
|
||||||
|
|
||||||
gcv.foreground = col[ColFG];
|
gcv.foreground = col[ColFG];
|
||||||
XChangeGC(disp, dc.gc, GCForeground, &gcv);
|
XChangeGC(disp, drawcontext.gc, GCForeground, &gcv);
|
||||||
x = (dc.font.ascent + dc.font.descent + 2) / 4;
|
x = (drawcontext.font.ascent + drawcontext.font.descent + 2) / 4;
|
||||||
r.x = dc.x + 1;
|
r.x = drawcontext.x + 1;
|
||||||
r.y = dc.y + 1;
|
r.y = drawcontext.y + 1;
|
||||||
if(filled)
|
if(filled)
|
||||||
{
|
{
|
||||||
r.width = r.height = x + 1;
|
r.width = r.height = x + 1;
|
||||||
XFillRectangles(disp, dc.drawable, dc.gc, &r, 1);
|
XFillRectangles(disp, drawcontext.drawable, drawcontext.gc, &r, 1);
|
||||||
}
|
}
|
||||||
else if(empty)
|
else if(empty)
|
||||||
{
|
{
|
||||||
r.width = r.height = x;
|
r.width = r.height = x;
|
||||||
XDrawRectangles(disp, dc.drawable, dc.gc, &r, 1);
|
XDrawRectangles(disp, drawcontext.drawable, drawcontext.gc, &r, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -111,60 +110,60 @@ isoccupied(unsigned int t)
|
||||||
/* extern */
|
/* extern */
|
||||||
|
|
||||||
unsigned int
|
unsigned int
|
||||||
textnw(const char *text, unsigned int len)
|
textnw(XFontSet set, XFontStruct *xfont, const char *text, unsigned int len)
|
||||||
{
|
{
|
||||||
XRectangle r;
|
XRectangle r;
|
||||||
|
|
||||||
if(dc.font.set)
|
if(set)
|
||||||
{
|
{
|
||||||
XmbTextExtents(dc.font.set, text, len, NULL, &r);
|
XmbTextExtents(set, text, len, NULL, &r);
|
||||||
return r.width;
|
return r.width;
|
||||||
}
|
}
|
||||||
return XTextWidth(dc.font.xfont, text, len);
|
return XTextWidth(xfont, text, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drawstatus(Display *disp, awesome_config * awesomeconf)
|
drawstatus(Display *disp, DC *drawcontext, awesome_config * awesomeconf)
|
||||||
{
|
{
|
||||||
int x, i;
|
int x, i;
|
||||||
dc.x = dc.y = 0;
|
drawcontext->x = drawcontext->y = 0;
|
||||||
for(i = 0; i < awesomeconf->ntags; i++)
|
for(i = 0; i < awesomeconf->ntags; i++)
|
||||||
{
|
{
|
||||||
dc.w = textw(awesomeconf->tags[i]);
|
drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->tags[i], drawcontext->font.height);
|
||||||
if(awesomeconf->selected_tags[i])
|
if(awesomeconf->selected_tags[i])
|
||||||
{
|
{
|
||||||
drawtext(disp, awesomeconf->tags[i], dc.sel);
|
drawtext(disp, *drawcontext, awesomeconf->tags[i], drawcontext->sel);
|
||||||
drawsquare(sel && sel->tags[i], isoccupied(i), dc.sel, disp);
|
drawsquare(sel && sel->tags[i], isoccupied(i), drawcontext->sel, disp, *drawcontext);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
drawtext(disp, awesomeconf->tags[i], dc.norm);
|
drawtext(disp, *drawcontext, awesomeconf->tags[i], drawcontext->norm);
|
||||||
drawsquare(sel && sel->tags[i], isoccupied(i), dc.norm, disp);
|
drawsquare(sel && sel->tags[i], isoccupied(i), drawcontext->norm, disp, *drawcontext);
|
||||||
}
|
}
|
||||||
dc.x += dc.w;
|
drawcontext->x += drawcontext->w;
|
||||||
}
|
}
|
||||||
dc.w = awesomeconf->statusbar.width;
|
drawcontext->w = awesomeconf->statusbar.width;
|
||||||
drawtext(disp, awesomeconf->current_layout->symbol, dc.norm);
|
drawtext(disp, *drawcontext, awesomeconf->current_layout->symbol, drawcontext->norm);
|
||||||
x = dc.x + dc.w;
|
x = drawcontext->x + drawcontext->w;
|
||||||
dc.w = textw(awesomeconf->statustext);
|
drawcontext->w = textw(drawcontext->font.set, drawcontext->font.xfont, awesomeconf->statustext, drawcontext->font.height);
|
||||||
dc.x = DisplayWidth(disp, DefaultScreen(disp)) - dc.w;
|
drawcontext->x = DisplayWidth(disp, DefaultScreen(disp)) - drawcontext->w;
|
||||||
if(dc.x < x)
|
if(drawcontext->x < x)
|
||||||
{
|
{
|
||||||
dc.x = x;
|
drawcontext->x = x;
|
||||||
dc.w = DisplayWidth(disp, DefaultScreen(disp)) - x;
|
drawcontext->w = DisplayWidth(disp, DefaultScreen(disp)) - x;
|
||||||
}
|
}
|
||||||
drawtext(disp, awesomeconf->statustext, dc.norm);
|
drawtext(disp, *drawcontext, awesomeconf->statustext, drawcontext->norm);
|
||||||
if((dc.w = dc.x - x) > awesomeconf->statusbar.height)
|
if((drawcontext->w = drawcontext->x - x) > awesomeconf->statusbar.height)
|
||||||
{
|
{
|
||||||
dc.x = x;
|
drawcontext->x = x;
|
||||||
if(sel)
|
if(sel)
|
||||||
{
|
{
|
||||||
drawtext(disp, sel->name, dc.sel);
|
drawtext(disp, *drawcontext, sel->name, drawcontext->sel);
|
||||||
drawsquare(sel->ismax, sel->isfloating, dc.sel, disp);
|
drawsquare(sel->ismax, sel->isfloating, drawcontext->sel, disp, *drawcontext);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
drawtext(disp, NULL, dc.norm);
|
drawtext(disp, *drawcontext, NULL, drawcontext->norm);
|
||||||
}
|
}
|
||||||
XCopyArea(disp, dc.drawable, awesomeconf->statusbar.window, dc.gc, 0, 0, DisplayWidth(disp, DefaultScreen(disp)), awesomeconf->statusbar.height, 0, 0);
|
XCopyArea(disp, drawcontext->drawable, awesomeconf->statusbar.window, drawcontext->gc, 0, 0, DisplayWidth(disp, DefaultScreen(disp)), awesomeconf->statusbar.height, 0, 0);
|
||||||
XSync(disp, False);
|
XSync(disp, False);
|
||||||
}
|
}
|
||||||
|
|
6
draw.h
6
draw.h
|
@ -24,9 +24,9 @@
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
#define textw(text) (textnw(text, a_strlen(text)) + dc.font.height)
|
#define textw(set, xfont, text, height) (textnw(set, xfont, text, a_strlen(text)) + height)
|
||||||
|
|
||||||
void drawstatus(Display *, awesome_config *); /* draw the bar */
|
void drawstatus(Display *, DC *, awesome_config *); /* draw the bar */
|
||||||
unsigned int textnw(const char *, unsigned int);
|
unsigned int textnw(XFontSet, XFontStruct *, const char *, unsigned int);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
6
event.c
6
event.c
|
@ -149,7 +149,7 @@ handle_event_buttonpress(XEvent * e, awesome_config *awesomeconf)
|
||||||
int x = 0;
|
int x = 0;
|
||||||
for(i = 0; i < awesomeconf->ntags; i++)
|
for(i = 0; i < awesomeconf->ntags; i++)
|
||||||
{
|
{
|
||||||
x += textw(awesomeconf->tags[i]);
|
x += textw(dc.font.set, dc.font.xfont, awesomeconf->tags[i], dc.font.height);
|
||||||
if(ev->x < x)
|
if(ev->x < x)
|
||||||
{
|
{
|
||||||
if(ev->button == Button1)
|
if(ev->button == Button1)
|
||||||
|
@ -299,7 +299,7 @@ handle_event_expose(XEvent * e, awesome_config *awesomeconf)
|
||||||
XExposeEvent *ev = &e->xexpose;
|
XExposeEvent *ev = &e->xexpose;
|
||||||
|
|
||||||
if(!ev->count && awesomeconf->statusbar.window == ev->window)
|
if(!ev->count && awesomeconf->statusbar.window == ev->window)
|
||||||
drawstatus(e->xany.display, awesomeconf);
|
drawstatus(e->xany.display, &dc, awesomeconf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -375,7 +375,7 @@ handle_event_propertynotify(XEvent * e, awesome_config *awesomeconf)
|
||||||
{
|
{
|
||||||
updatetitle(c);
|
updatetitle(c);
|
||||||
if(c == sel)
|
if(c == sel)
|
||||||
drawstatus(e->xany.display, awesomeconf);
|
drawstatus(e->xany.display, &dc, awesomeconf);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
6
layout.c
6
layout.c
|
@ -109,7 +109,7 @@ restack(Display * disp, awesome_config *awesomeconf)
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
XWindowChanges wc;
|
XWindowChanges wc;
|
||||||
|
|
||||||
drawstatus(disp, awesomeconf);
|
drawstatus(disp, &dc, awesomeconf);
|
||||||
if(!sel)
|
if(!sel)
|
||||||
return;
|
return;
|
||||||
if(sel->isfloating || IS_ARRANGE(floating))
|
if(sel->isfloating || IS_ARRANGE(floating))
|
||||||
|
@ -176,7 +176,7 @@ uicb_setlayout(Display *disp, awesome_config * awesomeconf, const char *arg)
|
||||||
if(sel)
|
if(sel)
|
||||||
arrange(disp, awesomeconf);
|
arrange(disp, awesomeconf);
|
||||||
else
|
else
|
||||||
drawstatus(disp, awesomeconf);
|
drawstatus(disp, &dc, awesomeconf);
|
||||||
|
|
||||||
saveawesomeprops(disp, awesomeconf);
|
saveawesomeprops(disp, awesomeconf);
|
||||||
|
|
||||||
|
@ -221,7 +221,7 @@ maximize(int x, int y, int w, int h, awesome_config *awesomeconf)
|
||||||
else
|
else
|
||||||
sel->isfloating = False;
|
sel->isfloating = False;
|
||||||
|
|
||||||
drawstatus(sel->display, awesomeconf);
|
drawstatus(sel->display, &dc, awesomeconf);
|
||||||
|
|
||||||
while(XCheckMaskEvent(sel->display, EnterWindowMask, &ev));
|
while(XCheckMaskEvent(sel->display, EnterWindowMask, &ev));
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,7 @@
|
||||||
|
|
||||||
/* extern */
|
/* extern */
|
||||||
extern Client *sel, *clients;
|
extern Client *sel, *clients;
|
||||||
|
extern DC dc;
|
||||||
|
|
||||||
/* static */
|
/* static */
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ uicb_setnmaster(Display *disp,
|
||||||
if(sel)
|
if(sel)
|
||||||
arrange(disp, awesomeconf);
|
arrange(disp, awesomeconf);
|
||||||
else
|
else
|
||||||
drawstatus(disp, awesomeconf);
|
drawstatus(disp, &dc, awesomeconf);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in New Issue