From c0ffcfbaf8af25468103dd92e0c7e83555e08c7a Mon Sep 17 00:00:00 2001 From: neeasade Date: Fri, 3 Jul 2020 11:20:51 -0500 Subject: [PATCH] Xresources and signal reloading note: also considered putting this in an xres.c file and #including it -- it's mostly self contained/might be worth it --- .Xresources | 5 +- config.def.h | 5 +- readme.org | 4 ++ x.c | 132 +++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 140 insertions(+), 6 deletions(-) diff --git a/.Xresources b/.Xresources index be59f18..8bc2576 100644 --- a/.Xresources +++ b/.Xresources @@ -3,10 +3,7 @@ ! see src/config.h for more information about option meanings. ! --- These options only take effect on startup. --- -st.termname: st-256color - -! if you do not set shell, precedence is: -e arg, utmp option, SHELL env var, /etc/passwd shell -st.shell: /bin/sh +st.termname: xst-256color ! --- The following options options can be reloaded via USR1 signal. --- st.font: Liberation Mono:pixelsize=12:antialias=true:autohint=true; diff --git a/config.def.h b/config.def.h index 12926be..d358647 100644 --- a/config.def.h +++ b/config.def.h @@ -80,7 +80,7 @@ static unsigned int cursorthickness = 2; static int bellvolume = 0; /* default TERM value */ -char *termname = "st-256color"; +char *termname = "xst-256color"; /* * spaces per tab @@ -130,6 +130,7 @@ static const char *colorname[] = { "#cccccc", "#555555", "black", + "gray90", }; @@ -137,7 +138,7 @@ static const char *colorname[] = { * Default colors (colorname index) * foreground, background, cursor, reverse cursor */ -unsigned int defaultfg = 7; +unsigned int defaultfg = 259; unsigned int defaultbg = 258; static unsigned int defaultcs = 256; static unsigned int defaultrcs = 257; diff --git a/readme.org b/readme.org index 023c69a..cbed603 100644 --- a/readme.org +++ b/readme.org @@ -2,6 +2,10 @@ `xst` is a [[https://st.suckless.org/][st]] fork with some patches applied and other goodies. +*** Breaking changes with 0.8.4 + +- =st.bold_font= option is now inverted; set =st.disablebold= to 1 to remove bold (additionally there is disable{italic,roman}) + *** xst-specific stuff - Loads settings from Xresources. See [[./.Xresources][the reference file]]. diff --git a/x.c b/x.c index 8d16a29..c3ae6c5 100644 --- a/x.c +++ b/x.c @@ -14,6 +14,7 @@ #include #include #include +#include char *argv0; #include "arg.h" @@ -2004,6 +2005,135 @@ run(void) } } +#define XRESOURCE_LOAD_META(NAME) \ + if(!XrmGetResource(xrdb, "st." NAME, "st." NAME, &type, &ret)) \ + XrmGetResource(xrdb, "*." NAME, "*." NAME, &type, &ret); \ + if (ret.addr != NULL && !strncmp("String", type, 64)) + +#define XRESOURCE_LOAD_STRING(NAME, DST) \ + XRESOURCE_LOAD_META(NAME) \ + DST = ret.addr; + +#define XRESOURCE_LOAD_CHAR(NAME, DST) \ + XRESOURCE_LOAD_META(NAME) \ + DST = ret.addr[0]; + +#define XRESOURCE_LOAD_INTEGER(NAME, DST) \ + XRESOURCE_LOAD_META(NAME) \ + DST = strtoul(ret.addr, NULL, 10); + +#define XRESOURCE_LOAD_FLOAT(NAME, DST) \ + XRESOURCE_LOAD_META(NAME) \ + DST = strtof(ret.addr, NULL); + +void +xrdb_load(void) +{ + /* XXX */ + char *xrm; + char *type; + XrmDatabase xrdb; + XrmValue ret; + Display *dpy; + + if(!(dpy = XOpenDisplay(NULL))) + die("Can't open display\n"); + + XrmInitialize(); + xrm = XResourceManagerString(dpy); + + if (xrm != NULL) { + xrdb = XrmGetStringDatabase(xrm); + + /* handling colors here without macros to do via loop. */ + int i = 0; + char loadValue[12] = ""; + for (i = 0; i < 256; i++) + { + sprintf(loadValue, "%s%d", "st.color", i); + + if(!XrmGetResource(xrdb, loadValue, loadValue, &type, &ret)) + { + sprintf(loadValue, "%s%d", "*.color", i); + if (!XrmGetResource(xrdb, loadValue, loadValue, &type, &ret)) + /* reset if not found (unless in range for defaults). */ + if (i > 15) + colorname[i] = NULL; + } + + if (ret.addr != NULL && !strncmp("String", type, 64)) + colorname[i] = ret.addr; + } + + XRESOURCE_LOAD_STRING("foreground", colorname[defaultfg]); + XRESOURCE_LOAD_STRING("background", colorname[defaultbg]); + XRESOURCE_LOAD_STRING("cursorfg", colorname[defaultcs]) + else { + // this looks confusing because we are chaining off of the if + // in the macro. probably we should be wrapping everything blocks + // so this isn't possible... + defaultcs = defaultfg; + } + XRESOURCE_LOAD_STRING("reverse-cursor", colorname[defaultrcs]) + else { + // see above. + defaultrcs = defaultbg; + } + + XRESOURCE_LOAD_STRING("font", font); + XRESOURCE_LOAD_STRING("termname", termname); + + /* XRESOURCE_LOAD_INTEGER("xfps", xfps); */ + /* XRESOURCE_LOAD_INTEGER("actionfps", actionfps); */ + XRESOURCE_LOAD_INTEGER("blinktimeout", blinktimeout); + XRESOURCE_LOAD_INTEGER("bellvolume", bellvolume); + XRESOURCE_LOAD_INTEGER("disablebold", disablebold); + XRESOURCE_LOAD_INTEGER("disableitalic", disableitalic); + XRESOURCE_LOAD_INTEGER("disableroman", disableroman); + XRESOURCE_LOAD_INTEGER("borderpx", borderpx); + /* XRESOURCE_LOAD_INTEGER("borderless", borderless); */ + XRESOURCE_LOAD_INTEGER("cursorshape", cursorshape); + + /* cursorblinkstate = 1; // in case if cursor shape was changed from a blinking one to a non-blinking */ + /* XRESOURCE_LOAD_INTEGER("cursorthickness", cursorthickness); */ + /* XRESOURCE_LOAD_INTEGER("cursorblinkstyle", cursorblinkstyle); */ + /* XRESOURCE_LOAD_INTEGER("cursorblinkontype", cursorblinkontype); */ + + /* todo: https://github.com/gnotclub/xst/commit/1e82647b0e04077e975679a4b4cf1eb02b04e6bc */ + /* XRESOURCE_LOAD_INTEGER("mouseScrollLines", mousescrolllines); */ + + XRESOURCE_LOAD_FLOAT("cwscale", cwscale); + XRESOURCE_LOAD_FLOAT("chscale", chscale); + + /* XRESOURCE_LOAD_CHAR("prompt_char", prompt_char); */ + + if (!opt_alpha) + XRESOURCE_LOAD_FLOAT("opacity", alpha); + } + XFlush(dpy); +} + +void +reload(int sig) +{ + xrdb_load(); + + /* colors, fonts */ + xloadcols(); + xunloadfonts(); + xloadfonts(font, 0); + + /* pretend the window just got resized */ + cresize(win.w, win.h); + + redraw(); + + /* triggers re-render if we're visible. */ + ttywrite("\033[O", 3, 1); + + signal(SIGUSR1, reload); +} + void usage(void) { @@ -2080,6 +2210,8 @@ main(int argc, char *argv[]) setlocale(LC_CTYPE, ""); XSetLocaleModifiers(""); + xrdb_load(); + signal(SIGUSR1, reload); cols = MAX(cols, 1); rows = MAX(rows, 1); tnew(cols, rows);