add sgrstatus + xresources patches
This commit is contained in:
parent
29597ef4b6
commit
de65109eb5
2
drw.c
2
drw.c
|
@ -195,7 +195,7 @@ drw_clr_create(Drw *drw, Clr *dest, const char *clrname)
|
||||||
/* Wrapper to create color schemes. The caller has to call free(3) on the
|
/* Wrapper to create color schemes. The caller has to call free(3) on the
|
||||||
* returned color scheme when done using it. */
|
* returned color scheme when done using it. */
|
||||||
Clr *
|
Clr *
|
||||||
drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount)
|
drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount)
|
||||||
{
|
{
|
||||||
size_t i;
|
size_t i;
|
||||||
Clr *ret;
|
Clr *ret;
|
||||||
|
|
2
drw.h
2
drw.h
|
@ -40,7 +40,7 @@ void drw_font_getexts(Fnt *font, const char *text, unsigned int len, unsigned in
|
||||||
|
|
||||||
/* Colorscheme abstraction */
|
/* Colorscheme abstraction */
|
||||||
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
|
void drw_clr_create(Drw *drw, Clr *dest, const char *clrname);
|
||||||
Clr *drw_scm_create(Drw *drw, const char *clrnames[], size_t clrcount);
|
Clr *drw_scm_create(Drw *drw, char *clrnames[], size_t clrcount);
|
||||||
|
|
||||||
/* Cursor abstraction */
|
/* Cursor abstraction */
|
||||||
Cur *drw_cur_create(Drw *drw, int shape);
|
Cur *drw_cur_create(Drw *drw, int shape);
|
||||||
|
|
256
dwm.c
256
dwm.c
|
@ -36,6 +36,7 @@
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/Xproto.h>
|
#include <X11/Xproto.h>
|
||||||
#include <X11/Xutil.h>
|
#include <X11/Xutil.h>
|
||||||
|
#include <X11/Xresource.h>
|
||||||
#ifdef XINERAMA
|
#ifdef XINERAMA
|
||||||
#include <X11/extensions/Xinerama.h>
|
#include <X11/extensions/Xinerama.h>
|
||||||
#endif /* XINERAMA */
|
#endif /* XINERAMA */
|
||||||
|
@ -148,6 +149,19 @@ typedef struct {
|
||||||
int monitor;
|
int monitor;
|
||||||
} Rule;
|
} Rule;
|
||||||
|
|
||||||
|
/* Xresources preferences */
|
||||||
|
enum resource_type {
|
||||||
|
STRING = 0,
|
||||||
|
INTEGER = 1,
|
||||||
|
FLOAT = 2
|
||||||
|
};
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
char *name;
|
||||||
|
enum resource_type type;
|
||||||
|
void *dst;
|
||||||
|
} ResourcePref;
|
||||||
|
|
||||||
/* function declarations */
|
/* function declarations */
|
||||||
static void applyrules(Client *c);
|
static void applyrules(Client *c);
|
||||||
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
|
static int applysizehints(Client *c, int *x, int *y, int *w, int *h, int interact);
|
||||||
|
@ -251,10 +265,12 @@ static int xerror(Display *dpy, XErrorEvent *ee);
|
||||||
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
static int xerrordummy(Display *dpy, XErrorEvent *ee);
|
||||||
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
static int xerrorstart(Display *dpy, XErrorEvent *ee);
|
||||||
static void zoom(const Arg *arg);
|
static void zoom(const Arg *arg);
|
||||||
|
static void load_xresources(void);
|
||||||
|
static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);
|
||||||
|
|
||||||
/* variables */
|
/* variables */
|
||||||
static const char broken[] = "broken";
|
static const char broken[] = "broken";
|
||||||
static char stext[256];
|
static char stext[512];
|
||||||
static int screen;
|
static int screen;
|
||||||
static int sw, sh; /* X display screen geometry width, height */
|
static int sw, sh; /* X display screen geometry width, height */
|
||||||
static int bh; /* bar height */
|
static int bh; /* bar height */
|
||||||
|
@ -282,6 +298,7 @@ static int restart = 0;
|
||||||
static int running = 1;
|
static int running = 1;
|
||||||
static Cur *cursor[CurLast];
|
static Cur *cursor[CurLast];
|
||||||
static Clr **scheme;
|
static Clr **scheme;
|
||||||
|
static Clr *barclrs;
|
||||||
static Display *dpy;
|
static Display *dpy;
|
||||||
static Drw *drw;
|
static Drw *drw;
|
||||||
static Monitor *mons, *selmon;
|
static Monitor *mons, *selmon;
|
||||||
|
@ -904,6 +921,25 @@ dirtomon(int dir)
|
||||||
return m;
|
return m;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
resetfntlist(Fnt *orighead, Fnt *curhead)
|
||||||
|
{
|
||||||
|
if (orighead != curhead) {
|
||||||
|
Fnt *f;
|
||||||
|
for (f = orighead; f->next; f = f->next);
|
||||||
|
f->next = curhead;
|
||||||
|
for (f = f->next; f->next != orighead; f = f->next);
|
||||||
|
f->next = NULL;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum SgrFlags {
|
||||||
|
REVERSE = 1 << 0,
|
||||||
|
UNDERLINE = 1 << 1,
|
||||||
|
STRIKETHROUGH = 1 << 2,
|
||||||
|
OVERLINE = 1 << 3
|
||||||
|
};
|
||||||
|
|
||||||
void
|
void
|
||||||
drawbar(Monitor *m)
|
drawbar(Monitor *m)
|
||||||
{
|
{
|
||||||
|
@ -918,9 +954,162 @@ drawbar(Monitor *m)
|
||||||
|
|
||||||
/* draw status first so it can be overdrawn by tags later */
|
/* draw status first so it can be overdrawn by tags later */
|
||||||
if (m == selmon) { /* status is only drawn on selected monitor */
|
if (m == selmon) { /* status is only drawn on selected monitor */
|
||||||
|
char buffer[sizeof(stext)];
|
||||||
|
Clr scm[3];
|
||||||
|
int wr, rd;
|
||||||
|
int pw;
|
||||||
|
int fg = 7;
|
||||||
|
int bg = 0;
|
||||||
|
int fmt = 0;
|
||||||
|
int lp = lrpad / 2 - 2;
|
||||||
|
Fnt *fset = drw->fonts;
|
||||||
|
|
||||||
|
memcpy(scm, scheme[SchemeNorm], sizeof(scm));
|
||||||
|
|
||||||
|
drw_setscheme(drw, scm);
|
||||||
|
|
||||||
|
for (tw = 0, wr = 0, rd = 0; stext[rd]; rd++) {
|
||||||
|
if (stext[rd] == '' && stext[rd + 1] == '[') {
|
||||||
|
size_t alen = strspn(stext + rd + 2,
|
||||||
|
"0123456789;");
|
||||||
|
if (stext[rd + alen + 2] == 'm') {
|
||||||
|
buffer[wr] = '\0';
|
||||||
|
tw += TEXTW(buffer) - lrpad;
|
||||||
|
wr = 0;
|
||||||
|
|
||||||
|
char *ep = stext + rd + 1;
|
||||||
|
while (*ep != 'm') {
|
||||||
|
unsigned v = strtoul(ep + 1, &ep, 10);
|
||||||
|
if (v == 0 || (v >= 10 && v <= 19)) {
|
||||||
|
int fi = v % 10;
|
||||||
|
Fnt *f;
|
||||||
|
Fnt *p;
|
||||||
|
resetfntlist(fset, drw->fonts);
|
||||||
|
for (p = NULL, f = fset; f && fi--; p = f, f = f->next);
|
||||||
|
if (f) {
|
||||||
|
if (p) {
|
||||||
|
p->next = NULL;
|
||||||
|
for (p = f; p->next; p = p->next);
|
||||||
|
p->next = fset;
|
||||||
|
}
|
||||||
|
drw_setfontset(drw, f);
|
||||||
|
} else {
|
||||||
|
drw_setfontset(drw, fset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rd += alen + 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buffer[wr++] = stext[rd];
|
||||||
|
}
|
||||||
|
buffer[wr] = '\0';
|
||||||
|
|
||||||
|
tw += TEXTW(buffer) - lrpad / 2 + 2;
|
||||||
|
x = m->ww - tw;
|
||||||
|
|
||||||
|
resetfntlist(fset, drw->fonts);
|
||||||
|
drw_setfontset(drw, fset);
|
||||||
|
|
||||||
|
for (wr = 0, rd = 0; stext[rd]; rd++) {
|
||||||
|
if (stext[rd] == '' && stext[rd + 1] == '[') {
|
||||||
|
size_t alen = strspn(stext + rd + 2,
|
||||||
|
"0123456789;");
|
||||||
|
if (stext[rd + alen + 2] == 'm') {
|
||||||
|
buffer[wr] = '\0';
|
||||||
|
pw = TEXTW(buffer) - lrpad;
|
||||||
|
drw_text(drw, x, 0, pw + lp, bh, lp, buffer, fmt & REVERSE);
|
||||||
|
if (fmt & UNDERLINE)
|
||||||
|
drw_rect(drw, x, (bh + drw->fonts->h) / 2, pw, 1, 1, fmt & REVERSE);
|
||||||
|
if (fmt & STRIKETHROUGH)
|
||||||
|
drw_rect(drw, x, bh / 2, pw, 1, 1, fmt & REVERSE);
|
||||||
|
if (fmt & OVERLINE)
|
||||||
|
drw_rect(drw, x, (bh - drw->fonts->h) / 2, pw, 1, 1, fmt & REVERSE);
|
||||||
|
x += pw + lp;
|
||||||
|
lp = 0;
|
||||||
|
|
||||||
|
char *ep = stext + rd + 1;
|
||||||
|
while (*ep != 'm') {
|
||||||
|
unsigned v = strtoul(ep + 1, &ep, 10);
|
||||||
|
if (v == 0) {
|
||||||
|
memcpy(scm, scheme[SchemeNorm], sizeof(scm));
|
||||||
|
fg = 7;
|
||||||
|
bg = 0;
|
||||||
|
fmt = 0;
|
||||||
|
resetfntlist(fset, drw->fonts);
|
||||||
|
drw_setfontset(drw, fset);
|
||||||
|
} else if (v == 1) {
|
||||||
|
fg |= 8;
|
||||||
|
scm[0] = barclrs[fg];
|
||||||
|
} else if (v == 4) {
|
||||||
|
fmt |= UNDERLINE;
|
||||||
|
} else if (v == 7) {
|
||||||
|
fmt |= REVERSE;
|
||||||
|
} else if (v == 9) {
|
||||||
|
fmt |= STRIKETHROUGH;
|
||||||
|
} else if (v >= 10 && v <= 19) {
|
||||||
|
int fi = v % 10;
|
||||||
|
Fnt *f;
|
||||||
|
Fnt *p;
|
||||||
|
resetfntlist(fset, drw->fonts);
|
||||||
|
for (p = NULL, f = fset; f && fi--; p = f, f = f->next);
|
||||||
|
if (f) {
|
||||||
|
if (p) {
|
||||||
|
p->next = NULL;
|
||||||
|
for (p = f; p->next; p = p->next);
|
||||||
|
p->next = fset;
|
||||||
|
}
|
||||||
|
drw_setfontset(drw, f);
|
||||||
|
} else {
|
||||||
|
drw_setfontset(drw, fset);
|
||||||
|
}
|
||||||
|
} else if (v == 22) {
|
||||||
|
fg &= ~8;
|
||||||
|
scm[0] = barclrs[fg];
|
||||||
|
} else if (v == 24) {
|
||||||
|
fmt &= ~UNDERLINE;
|
||||||
|
} else if (v == 27) {
|
||||||
|
fmt &= ~REVERSE;
|
||||||
|
} else if (v == 29) {
|
||||||
|
fmt &= ~STRIKETHROUGH;
|
||||||
|
} else if (v >= 30 && v <= 37) {
|
||||||
|
fg = v % 10 | (fg & 8);
|
||||||
|
scm[0] = barclrs[fg];
|
||||||
|
} else if (v >= 40 && v <= 47) {
|
||||||
|
bg = v % 10;
|
||||||
|
scm[1] = barclrs[bg];
|
||||||
|
} else if (v == 53) {
|
||||||
|
fmt |= OVERLINE;
|
||||||
|
} else if (v == 55) {
|
||||||
|
fmt &= ~OVERLINE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rd += alen + 2;
|
||||||
|
wr = 0;
|
||||||
|
|
||||||
|
drw_setscheme(drw, scm);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
buffer[wr++] = stext[rd];
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer[wr] = '\0';
|
||||||
|
pw = TEXTW(buffer) - lrpad;
|
||||||
|
drw_text(drw, x, 0, pw + lp, bh, lp, buffer, fmt & REVERSE);
|
||||||
|
if (fmt & UNDERLINE)
|
||||||
|
drw_rect(drw, x, (bh + drw->fonts->h) / 2, pw, 1, 1, fmt & REVERSE);
|
||||||
|
if (fmt & STRIKETHROUGH)
|
||||||
|
drw_rect(drw, x, bh / 2, pw, 1, 1, fmt & REVERSE);
|
||||||
|
if (fmt & OVERLINE)
|
||||||
|
drw_rect(drw, x, (bh - drw->fonts->h) / 2, pw, 1, 1, fmt & REVERSE);
|
||||||
|
|
||||||
drw_setscheme(drw, scheme[SchemeStatus]);
|
drw_setscheme(drw, scheme[SchemeStatus]);
|
||||||
tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
|
// tw = TEXTW(stext) - lrpad + 2; /* 2px right padding */
|
||||||
drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
|
// drw_text(drw, m->ww - tw, 0, tw, bh, 0, stext, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (c = m->clients; c; c = c->next) {
|
for (c = m->clients; c; c = c->next) {
|
||||||
|
@ -1866,6 +2055,11 @@ setup(void)
|
||||||
scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
|
scheme = ecalloc(LENGTH(colors), sizeof(Clr *));
|
||||||
for (i = 0; i < LENGTH(colors); i++)
|
for (i = 0; i < LENGTH(colors); i++)
|
||||||
scheme[i] = drw_scm_create(drw, colors[i], 3);
|
scheme[i] = drw_scm_create(drw, colors[i], 3);
|
||||||
|
|
||||||
|
barclrs = ecalloc(LENGTH(barcolors), sizeof(Clr));
|
||||||
|
for (i = 0; i < LENGTH(barcolors); i++)
|
||||||
|
drw_clr_create(drw, &barclrs[i], barcolors[i]);
|
||||||
|
|
||||||
/* init bars */
|
/* init bars */
|
||||||
updatebars();
|
updatebars();
|
||||||
updatestatus();
|
updatestatus();
|
||||||
|
@ -2462,6 +2656,60 @@ zoom(const Arg *arg)
|
||||||
pop(c);
|
pop(c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
|
||||||
|
{
|
||||||
|
char *sdst = NULL;
|
||||||
|
int *idst = NULL;
|
||||||
|
float *fdst = NULL;
|
||||||
|
|
||||||
|
sdst = dst;
|
||||||
|
idst = dst;
|
||||||
|
fdst = dst;
|
||||||
|
|
||||||
|
char fullname[256];
|
||||||
|
char *type;
|
||||||
|
XrmValue ret;
|
||||||
|
|
||||||
|
snprintf(fullname, sizeof(fullname), "%s.%s", "dwm", name);
|
||||||
|
fullname[sizeof(fullname) - 1] = '\0';
|
||||||
|
|
||||||
|
XrmGetResource(db, fullname, "*", &type, &ret);
|
||||||
|
if (!(ret.addr == NULL || strncmp("String", type, 64)))
|
||||||
|
{
|
||||||
|
switch (rtype) {
|
||||||
|
case STRING:
|
||||||
|
strcpy(sdst, ret.addr);
|
||||||
|
break;
|
||||||
|
case INTEGER:
|
||||||
|
*idst = strtoul(ret.addr, NULL, 10);
|
||||||
|
break;
|
||||||
|
case FLOAT:
|
||||||
|
*fdst = strtof(ret.addr, NULL);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
load_xresources(void)
|
||||||
|
{
|
||||||
|
Display *display;
|
||||||
|
char *resm;
|
||||||
|
XrmDatabase db;
|
||||||
|
ResourcePref *p;
|
||||||
|
|
||||||
|
display = XOpenDisplay(NULL);
|
||||||
|
resm = XResourceManagerString(display);
|
||||||
|
if (!resm)
|
||||||
|
return;
|
||||||
|
|
||||||
|
db = XrmGetStringDatabase(resm);
|
||||||
|
for (p = resources; p < resources + LENGTH(resources); p++)
|
||||||
|
resource_load(db, p->name, p->type, p->dst);
|
||||||
|
XCloseDisplay(display);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
@ -2474,6 +2722,8 @@ main(int argc, char *argv[])
|
||||||
if (!(dpy = XOpenDisplay(NULL)))
|
if (!(dpy = XOpenDisplay(NULL)))
|
||||||
die("dwm: cannot open display");
|
die("dwm: cannot open display");
|
||||||
checkotherwm();
|
checkotherwm();
|
||||||
|
XrmInitialize();
|
||||||
|
load_xresources();
|
||||||
setup();
|
setup();
|
||||||
#ifdef __OpenBSD__
|
#ifdef __OpenBSD__
|
||||||
if (pledge("stdio rpath proc exec", NULL) == -1)
|
if (pledge("stdio rpath proc exec", NULL) == -1)
|
||||||
|
|
Loading…
Reference in New Issue