Add unified Xresources theme engine, Default.xth export, and xthemes manager plugin
This commit is contained in:
@@ -118,7 +118,9 @@ static const char *colorname[] = {
|
||||
[255] = 0,
|
||||
|
||||
/* more colors can be added after 255 to use with DefaultXX */
|
||||
"#cccccc",
|
||||
"#161616",
|
||||
"#dddddd",
|
||||
"#f4d03f",
|
||||
"#555555",
|
||||
};
|
||||
|
||||
@@ -127,10 +129,10 @@ static const char *colorname[] = {
|
||||
* Default colors (colorname index)
|
||||
* foreground, background, cursor, reverse cursor
|
||||
*/
|
||||
unsigned int defaultfg = 7;
|
||||
unsigned int defaultbg = 0;
|
||||
static unsigned int defaultcs = 256;
|
||||
static unsigned int defaultrcs = 257;
|
||||
unsigned int defaultfg = 257;
|
||||
unsigned int defaultbg = 256;
|
||||
static unsigned int defaultcs = 258;
|
||||
static unsigned int defaultrcs = 259;
|
||||
|
||||
/*
|
||||
* Default shape of cursor
|
||||
|
||||
@@ -118,7 +118,9 @@ static const char *colorname[] = {
|
||||
[255] = 0,
|
||||
|
||||
/* more colors can be added after 255 to use with DefaultXX */
|
||||
"#cccccc",
|
||||
"#161616",
|
||||
"#dddddd",
|
||||
"#f4d03f",
|
||||
"#555555",
|
||||
};
|
||||
|
||||
@@ -127,10 +129,10 @@ static const char *colorname[] = {
|
||||
* Default colors (colorname index)
|
||||
* foreground, background, cursor, reverse cursor
|
||||
*/
|
||||
unsigned int defaultfg = 7;
|
||||
unsigned int defaultbg = 0;
|
||||
static unsigned int defaultcs = 256;
|
||||
static unsigned int defaultrcs = 257;
|
||||
unsigned int defaultfg = 257;
|
||||
unsigned int defaultbg = 256;
|
||||
static unsigned int defaultcs = 258;
|
||||
static unsigned int defaultrcs = 259;
|
||||
|
||||
/*
|
||||
* Default shape of cursor
|
||||
|
||||
+84
-5
@@ -1942,6 +1942,21 @@ resize(XEvent *e)
|
||||
cresize(e->xconfigure.width, e->xconfigure.height);
|
||||
}
|
||||
|
||||
static volatile sig_atomic_t st_reload_requested = 0;
|
||||
static char st_theme_font[256] = "";
|
||||
static char st_theme_bg[32] = "";
|
||||
static char st_theme_fg[32] = "";
|
||||
static char st_theme_cs[32] = "";
|
||||
|
||||
static void
|
||||
st_sigusr1(int unused)
|
||||
{
|
||||
(void)unused;
|
||||
st_reload_requested = 1;
|
||||
}
|
||||
|
||||
void config_init(void);
|
||||
|
||||
void
|
||||
run(void)
|
||||
{
|
||||
@@ -1970,8 +1985,19 @@ run(void)
|
||||
|
||||
ttyfd = ttynew(opt_line, shell, opt_io, opt_cmd);
|
||||
cresize(w, h);
|
||||
signal(SIGUSR1, st_sigusr1);
|
||||
|
||||
for (timeout = -1, drawing = 0, lastblink = (struct timespec){0};;) {
|
||||
if (st_reload_requested) {
|
||||
st_reload_requested = 0;
|
||||
config_init();
|
||||
xloadcols();
|
||||
xunloadfonts();
|
||||
xloadfonts(opt_font ? opt_font : font, 0);
|
||||
cresize(win.w, win.h);
|
||||
redraw();
|
||||
XFlush(xw.dpy);
|
||||
}
|
||||
FD_ZERO(&rfd);
|
||||
FD_SET(ttyfd, &rfd);
|
||||
FD_SET(xfd, &rfd);
|
||||
@@ -2084,18 +2110,71 @@ resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst)
|
||||
void
|
||||
config_init(void)
|
||||
{
|
||||
char *resm;
|
||||
XrmDatabase db;
|
||||
XrmDatabase db = NULL;
|
||||
ResourcePref *p;
|
||||
Atom actual_type = None;
|
||||
int actual_format = 0;
|
||||
unsigned long nitems = 0, bytes_after = 0;
|
||||
unsigned char *prop = NULL;
|
||||
char *type = NULL;
|
||||
XrmValue ret;
|
||||
|
||||
XrmInitialize();
|
||||
resm = XResourceManagerString(xw.dpy);
|
||||
if (!resm)
|
||||
{
|
||||
const char *home = getenv("HOME");
|
||||
char path[512];
|
||||
snprintf(path, sizeof(path), "%s/.Xresources", (home && home[0]) ? home : "/home/user");
|
||||
db = XrmGetFileDatabase(path);
|
||||
}
|
||||
if (!db && XGetWindowProperty(xw.dpy, DefaultRootWindow(xw.dpy), XA_RESOURCE_MANAGER,
|
||||
0L, 65536L, False, XA_STRING, &actual_type,
|
||||
&actual_format, &nitems, &bytes_after, &prop) == Success && prop) {
|
||||
if (actual_type == XA_STRING && actual_format == 8 && nitems > 0)
|
||||
db = XrmGetStringDatabase((const char *)prop);
|
||||
XFree(prop);
|
||||
}
|
||||
if (!db) {
|
||||
char *resm = XResourceManagerString(xw.dpy);
|
||||
if (resm)
|
||||
db = XrmGetStringDatabase(resm);
|
||||
}
|
||||
if (!db)
|
||||
return;
|
||||
|
||||
db = XrmGetStringDatabase(resm);
|
||||
for (p = resources; p < resources + LEN(resources); p++)
|
||||
resource_load(db, p->name, p->type, p->dst);
|
||||
|
||||
/* Also honor unified theme.* keys */
|
||||
const char *ff = NULL, *bsz = NULL;
|
||||
if (XrmGetResource(db, "theme.fontFace", "*", &type, &ret) && ret.addr && ret.addr[0])
|
||||
ff = ret.addr;
|
||||
if (XrmGetResource(db, "theme.baseFontSize", "*", &type, &ret) && ret.addr && ret.addr[0])
|
||||
bsz = ret.addr;
|
||||
if (ff || bsz) {
|
||||
int base_sz = bsz ? atoi(bsz) : 15;
|
||||
if (base_sz < 8 || base_sz > 32)
|
||||
base_sz = 15;
|
||||
int large_sz = (base_sz * 18 + 7) / 15;
|
||||
snprintf(st_theme_font, sizeof(st_theme_font),
|
||||
"%s:pixelsize=%d:style=Regular:antialias=true:autohint=true",
|
||||
ff ? ff : "Fira Code", large_sz);
|
||||
font = st_theme_font;
|
||||
}
|
||||
if (XrmGetResource(db, "theme.bgHeader", "*", &type, &ret) && ret.addr && ret.addr[0]) {
|
||||
snprintf(st_theme_bg, sizeof(st_theme_bg), "%s", ret.addr);
|
||||
colorname[256] = st_theme_bg;
|
||||
} else if (XrmGetResource(db, "theme.bgMain", "*", &type, &ret) && ret.addr && ret.addr[0]) {
|
||||
snprintf(st_theme_bg, sizeof(st_theme_bg), "%s", ret.addr);
|
||||
colorname[256] = st_theme_bg;
|
||||
}
|
||||
if (XrmGetResource(db, "theme.fgMain", "*", &type, &ret) && ret.addr && ret.addr[0]) {
|
||||
snprintf(st_theme_fg, sizeof(st_theme_fg), "%s", ret.addr);
|
||||
colorname[257] = st_theme_fg;
|
||||
}
|
||||
if (XrmGetResource(db, "theme.accent", "*", &type, &ret) && ret.addr && ret.addr[0]) {
|
||||
snprintf(st_theme_cs, sizeof(st_theme_cs), "%s", ret.addr);
|
||||
colorname[258] = st_theme_cs;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
|
||||
Reference in New Issue
Block a user