applied Julian's enum approach,
however renamed theme into scheme resp. Theme into ClrScheme
This commit is contained in:
parent
5364697914
commit
33a74489f0
20
drw.c
20
drw.c
|
@ -109,8 +109,7 @@ drw_clr_create(Drw *drw, const char *clrname) {
|
||||||
|
|
||||||
void
|
void
|
||||||
drw_clr_free(Clr *clr) {
|
drw_clr_free(Clr *clr) {
|
||||||
if(!clr)
|
if(clr)
|
||||||
return;
|
|
||||||
free(clr);
|
free(clr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -121,19 +120,18 @@ drw_setfont(Drw *drw, Fnt *font) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drw_settheme(Drw *drw, Theme *theme) {
|
drw_setscheme(Drw *drw, ClrScheme *scheme) {
|
||||||
if(!drw || !theme)
|
if(drw && scheme)
|
||||||
return;
|
drw->scheme = scheme;
|
||||||
drw->theme = theme;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert) {
|
drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert) {
|
||||||
int dx;
|
int dx;
|
||||||
|
|
||||||
if(!drw || !drw->font || !drw->theme)
|
if(!drw || !drw->font || !drw->scheme)
|
||||||
return;
|
return;
|
||||||
XSetForeground(drw->dpy, drw->gc, invert ? drw->theme->bg->rgb : drw->theme->fg->rgb);
|
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->rgb : drw->scheme->fg->rgb);
|
||||||
dx = (drw->font->ascent + drw->font->descent + 2) / 4;
|
dx = (drw->font->ascent + drw->font->descent + 2) / 4;
|
||||||
if(filled)
|
if(filled)
|
||||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx+1, dx+1);
|
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x+1, y+1, dx+1, dx+1);
|
||||||
|
@ -147,9 +145,9 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex
|
||||||
int i, tx, ty, th, len, olen;
|
int i, tx, ty, th, len, olen;
|
||||||
Extnts tex;
|
Extnts tex;
|
||||||
|
|
||||||
if(!drw || !drw->theme)
|
if(!drw || !drw->scheme)
|
||||||
return;
|
return;
|
||||||
XSetForeground(drw->dpy, drw->gc, invert ? drw->theme->fg->rgb : drw->theme->bg->rgb);
|
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->fg->rgb : drw->scheme->bg->rgb);
|
||||||
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
XFillRectangle(drw->dpy, drw->drawable, drw->gc, x, y, w, h);
|
||||||
if(!text || !drw->font)
|
if(!text || !drw->font)
|
||||||
return;
|
return;
|
||||||
|
@ -166,7 +164,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, const char *tex
|
||||||
memcpy(buf, text, len);
|
memcpy(buf, text, len);
|
||||||
if(len < olen)
|
if(len < olen)
|
||||||
for(i = len; i && i > len - 3; buf[--i] = '.');
|
for(i = len; i && i > len - 3; buf[--i] = '.');
|
||||||
XSetForeground(drw->dpy, drw->gc, invert ? drw->theme->bg->rgb : drw->theme->fg->rgb);
|
XSetForeground(drw->dpy, drw->gc, invert ? drw->scheme->bg->rgb : drw->scheme->fg->rgb);
|
||||||
if(drw->font->set)
|
if(drw->font->set)
|
||||||
XmbDrawString(drw->dpy, drw->drawable, drw->font->set, drw->gc, tx, ty, buf, len);
|
XmbDrawString(drw->dpy, drw->drawable, drw->font->set, drw->gc, tx, ty, buf, len);
|
||||||
else
|
else
|
||||||
|
|
6
drw.h
6
drw.h
|
@ -20,7 +20,7 @@ typedef struct {
|
||||||
Clr *fg;
|
Clr *fg;
|
||||||
Clr *bg;
|
Clr *bg;
|
||||||
Clr *border;
|
Clr *border;
|
||||||
} Theme;
|
} ClrScheme;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
unsigned int w, h;
|
unsigned int w, h;
|
||||||
|
@ -29,7 +29,7 @@ typedef struct {
|
||||||
Window root;
|
Window root;
|
||||||
Drawable drawable;
|
Drawable drawable;
|
||||||
GC gc;
|
GC gc;
|
||||||
Theme *theme;
|
ClrScheme *scheme;
|
||||||
Fnt *font;
|
Fnt *font;
|
||||||
} Drw;
|
} Drw;
|
||||||
|
|
||||||
|
@ -59,7 +59,7 @@ void drw_cur_free(Drw *drw, Cur *cursor);
|
||||||
|
|
||||||
/* Drawing context manipulation */
|
/* Drawing context manipulation */
|
||||||
void drw_setfont(Drw *drw, Fnt *font);
|
void drw_setfont(Drw *drw, Fnt *font);
|
||||||
void drw_settheme(Drw *drw, Theme *theme);
|
void drw_setscheme(Drw *drw, ClrScheme *scheme);
|
||||||
|
|
||||||
/* Drawing functions */
|
/* Drawing functions */
|
||||||
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert);
|
void drw_rect(Drw *drw, int x, int y, unsigned int w, unsigned int h, int filled, int empty, int invert);
|
||||||
|
|
43
dwm.c
43
dwm.c
|
@ -58,7 +58,7 @@
|
||||||
|
|
||||||
/* enums */
|
/* enums */
|
||||||
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
enum { CurNormal, CurResize, CurMove, CurLast }; /* cursor */
|
||||||
enum { ColBorder, ColFG, ColBG, ColLast }; /* color */
|
enum { SchemeNorm, SchemeSel, SchemeLast }; /* color schemes */
|
||||||
enum { NetSupported, NetWMName, NetWMState,
|
enum { NetSupported, NetWMName, NetWMState,
|
||||||
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
|
NetWMFullscreen, NetActiveWindow, NetWMWindowType,
|
||||||
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
|
NetWMWindowTypeDialog, NetClientList, NetLast }; /* EWMH atoms */
|
||||||
|
@ -260,8 +260,7 @@ static void (*handler[LASTEvent]) (XEvent *) = {
|
||||||
static Atom wmatom[WMLast], netatom[NetLast];
|
static Atom wmatom[WMLast], netatom[NetLast];
|
||||||
static Bool running = True;
|
static Bool running = True;
|
||||||
static Cur *cursor[CurLast];
|
static Cur *cursor[CurLast];
|
||||||
static Theme thmnorm[ColLast];
|
static ClrScheme scheme[SchemeLast];
|
||||||
static Theme thmsel[ColLast];
|
|
||||||
static Display *dpy;
|
static Display *dpy;
|
||||||
static Drw *drw;
|
static Drw *drw;
|
||||||
static Fnt *fnt;
|
static Fnt *fnt;
|
||||||
|
@ -476,12 +475,12 @@ cleanup(void) {
|
||||||
drw_cur_free(drw, cursor[CurResize]);
|
drw_cur_free(drw, cursor[CurResize]);
|
||||||
drw_cur_free(drw, cursor[CurMove]);
|
drw_cur_free(drw, cursor[CurMove]);
|
||||||
drw_font_free(dpy, fnt);
|
drw_font_free(dpy, fnt);
|
||||||
drw_clr_free(thmnorm->border);
|
drw_clr_free(scheme[SchemeNorm].border);
|
||||||
drw_clr_free(thmnorm->bg);
|
drw_clr_free(scheme[SchemeNorm].bg);
|
||||||
drw_clr_free(thmnorm->fg);
|
drw_clr_free(scheme[SchemeNorm].fg);
|
||||||
drw_clr_free(thmsel->border);
|
drw_clr_free(scheme[SchemeSel].border);
|
||||||
drw_clr_free(thmsel->bg);
|
drw_clr_free(scheme[SchemeSel].bg);
|
||||||
drw_clr_free(thmsel->fg);
|
drw_clr_free(scheme[SchemeSel].fg);
|
||||||
drw_free(drw);
|
drw_free(drw);
|
||||||
XSync(dpy, False);
|
XSync(dpy, False);
|
||||||
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
|
XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, CurrentTime);
|
||||||
|
@ -705,14 +704,14 @@ drawbar(Monitor *m) {
|
||||||
x = 0;
|
x = 0;
|
||||||
for(i = 0; i < LENGTH(tags); i++) {
|
for(i = 0; i < LENGTH(tags); i++) {
|
||||||
w = TEXTW(tags[i]);
|
w = TEXTW(tags[i]);
|
||||||
drw_settheme(drw, m->tagset[m->seltags] & 1 << i ? thmsel : thmnorm);
|
drw_setscheme(drw, m->tagset[m->seltags] & 1 << i ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
|
||||||
drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i);
|
drw_text(drw, x, 0, w, bh, tags[i], urg & 1 << i);
|
||||||
drw_rect(drw, x, 0, w, bh, m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
|
drw_rect(drw, x, 0, w, bh, m == selmon && selmon->sel && selmon->sel->tags & 1 << i,
|
||||||
occ & 1 << i, urg & 1 << i);
|
occ & 1 << i, urg & 1 << i);
|
||||||
x += w;
|
x += w;
|
||||||
}
|
}
|
||||||
w = blw = TEXTW(m->ltsymbol);
|
w = blw = TEXTW(m->ltsymbol);
|
||||||
drw_settheme(drw, thmnorm);
|
drw_setscheme(drw, &scheme[SchemeNorm]);
|
||||||
drw_text(drw, x, 0, w, bh, m->ltsymbol, 0);
|
drw_text(drw, x, 0, w, bh, m->ltsymbol, 0);
|
||||||
x += w;
|
x += w;
|
||||||
xx = x;
|
xx = x;
|
||||||
|
@ -730,12 +729,12 @@ drawbar(Monitor *m) {
|
||||||
if((w = x - xx) > bh) {
|
if((w = x - xx) > bh) {
|
||||||
x = xx;
|
x = xx;
|
||||||
if(m->sel) {
|
if(m->sel) {
|
||||||
drw_settheme(drw, m == selmon ? thmsel : thmnorm);
|
drw_setscheme(drw, m == selmon ? &scheme[SchemeSel] : &scheme[SchemeNorm]);
|
||||||
drw_text(drw, x, 0, w, bh, m->sel->name, 0);
|
drw_text(drw, x, 0, w, bh, m->sel->name, 0);
|
||||||
drw_rect(drw, x, 0, w, bh, m->sel->isfixed, m->sel->isfloating, 0);
|
drw_rect(drw, x, 0, w, bh, m->sel->isfixed, m->sel->isfloating, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
drw_settheme(drw, thmnorm);
|
drw_setscheme(drw, &scheme[SchemeNorm]);
|
||||||
drw_text(drw, x, 0, w, bh, NULL, 0);
|
drw_text(drw, x, 0, w, bh, NULL, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -793,7 +792,7 @@ focus(Client *c) {
|
||||||
detachstack(c);
|
detachstack(c);
|
||||||
attachstack(c);
|
attachstack(c);
|
||||||
grabbuttons(c, True);
|
grabbuttons(c, True);
|
||||||
XSetWindowBorder(dpy, c->win, thmsel->border->rgb);
|
XSetWindowBorder(dpy, c->win, scheme[SchemeSel].border->rgb);
|
||||||
setfocus(c);
|
setfocus(c);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -1041,7 +1040,7 @@ manage(Window w, XWindowAttributes *wa) {
|
||||||
|
|
||||||
wc.border_width = c->bw;
|
wc.border_width = c->bw;
|
||||||
XConfigureWindow(dpy, w, CWBorderWidth, &wc);
|
XConfigureWindow(dpy, w, CWBorderWidth, &wc);
|
||||||
XSetWindowBorder(dpy, w, thmnorm->border->rgb);
|
XSetWindowBorder(dpy, w, scheme[SchemeNorm].border->rgb);
|
||||||
configure(c); /* propagates border_width, if size doesn't change */
|
configure(c); /* propagates border_width, if size doesn't change */
|
||||||
updatewindowtype(c);
|
updatewindowtype(c);
|
||||||
updatesizehints(c);
|
updatesizehints(c);
|
||||||
|
@ -1523,12 +1522,12 @@ setup(void) {
|
||||||
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
|
cursor[CurResize] = drw_cur_create(drw, XC_sizing);
|
||||||
cursor[CurMove] = drw_cur_create(drw, XC_fleur);
|
cursor[CurMove] = drw_cur_create(drw, XC_fleur);
|
||||||
/* init appearance */
|
/* init appearance */
|
||||||
thmnorm->border = drw_clr_create(drw, normbordercolor);
|
scheme[SchemeNorm].border = drw_clr_create(drw, normbordercolor);
|
||||||
thmnorm->bg = drw_clr_create(drw, normbgcolor);
|
scheme[SchemeNorm].bg = drw_clr_create(drw, normbgcolor);
|
||||||
thmnorm->fg = drw_clr_create(drw, normfgcolor);
|
scheme[SchemeNorm].fg = drw_clr_create(drw, normfgcolor);
|
||||||
thmsel->border = drw_clr_create(drw, selbordercolor);
|
scheme[SchemeSel].border = drw_clr_create(drw, selbordercolor);
|
||||||
thmsel->bg = drw_clr_create(drw, selbgcolor);
|
scheme[SchemeSel].bg = drw_clr_create(drw, selbgcolor);
|
||||||
thmsel->fg = drw_clr_create(drw, selfgcolor);
|
scheme[SchemeSel].fg = drw_clr_create(drw, selfgcolor);
|
||||||
/* init bars */
|
/* init bars */
|
||||||
updatebars();
|
updatebars();
|
||||||
updatestatus();
|
updatestatus();
|
||||||
|
@ -1674,7 +1673,7 @@ unfocus(Client *c, Bool setfocus) {
|
||||||
if(!c)
|
if(!c)
|
||||||
return;
|
return;
|
||||||
grabbuttons(c, False);
|
grabbuttons(c, False);
|
||||||
XSetWindowBorder(dpy, c->win, thmnorm->border->rgb);
|
XSetWindowBorder(dpy, c->win, scheme[SchemeNorm].border->rgb);
|
||||||
if(setfocus) {
|
if(setfocus) {
|
||||||
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
XSetInputFocus(dpy, root, RevertToPointerRoot, CurrentTime);
|
||||||
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
|
XDeleteProperty(dpy, root, netatom[NetActiveWindow]);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user