old-st

[ARCHIVED] my build of st
git clone git://git.ckyln.com/~cem/old-st.git
Log | Files | Refs | README | LICENSE

commit 5dc4de714bb30b7dcf2cee7ad06dd8ea25e7febb
parent ff7fe1be6bc29c4f4f8d9c15fd9b38c5c49407fd
Author: Cem Keylan <cem@ckyln.com>
Date:   Tue, 22 Oct 2019 14:34:20 +0300

removed multiple color-schemes for Xresources

Diffstat:
Mconfig.h | 115+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
Mst.h | 1-
Mx.c | 106+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------
3 files changed, 145 insertions(+), 77 deletions(-)

diff --git a/config.h b/config.h @@ -87,59 +87,39 @@ float alpha = 0.92; /* Terminal colors (16 first used in escape sequence) */ static const char *colorname[] = { - /* dracula */ - "#000000", /* 0: black */ - "#ff5555", /* 1: red */ - "#50fa7b", /* 2: green */ - "#f1fa8c", /* 3: yellow */ - "#bd93f9", /* 4: blue */ - "#ff79c6", /* 5: magenta */ - "#8be9fd", /* 6: cyan */ - "#bbbbbb", /* 7: white */ - "#44475a", /* 8: brblack */ - "#ff5555", /* 9: brred */ - "#50fa7b", /* 10: brgreen */ - "#f1fa8c", /* 11: bryellow */ - "#8be9fd", /* 12: brblue */ - "#ff79c6", /* 13: brmagenta*/ - "#8be9fd", /* 14: brcyan */ - "#ffffff", /* 15: brwhite */ - - - [256] = "#282a36", /* background */ - [257] = "#f8f8f2", /* foreground */ - + /* 8 normal colors */ + "black", + "red3", + "green3", + "yellow3", + "blue2", + "magenta3", + "cyan3", + "gray90", + + /* 8 bright colors */ + "gray50", + "red", + "green", + "yellow", + "#5c5cff", + "magenta", + "cyan", + "white", + + [255] = 0, + + /* more colors can be added after 255 to use with DefaultXX */ + "#cccccc", + "#555555", + "black", }; -/* Terminal colors for alternate (light) palette */ -static const char *altcolorname[] = { - /* solarized light */ - "#eee8d5", /* 0: black */ - "#dc322f", /* 1: red */ - "#859900", /* 2: green */ - "#b58900", /* 3: yellow */ - "#268bd2", /* 4: blue */ - "#d33682", /* 5: magenta */ - "#2aa198", /* 6: cyan */ - "#073642", /* 7: white */ - "#fdf6e3", /* 8: brblack */ - "#cb4b16", /* 9: brred */ - "#93a1a1", /* 10: brgreen */ - "#839496", /* 11: bryellow */ - "#657b83", /* 12: brblue */ - "#6c71c4", /* 13: brmagenta*/ - "#586e75", /* 14: brcyan */ - "#002b36", /* 15: brwhite */ - - [256] = "#fdf6e3", - [257] = "#657b83", -}; /* * Default colors (colorname index) - * foreground, background, cursor + * foreground, background, cursor, reverse cursor */ - unsigned int defaultfg = 257; unsigned int defaultbg = 256; static unsigned int defaultcs = 257; @@ -175,6 +155,43 @@ static unsigned int mousebg = 0; static unsigned int defaultattr = 11; /* + * Xresources preferences to load at startup + */ +ResourcePref resources[] = { + { "font", STRING, &font }, + { "color0", STRING, &colorname[0] }, + { "color1", STRING, &colorname[1] }, + { "color2", STRING, &colorname[2] }, + { "color3", STRING, &colorname[3] }, + { "color4", STRING, &colorname[4] }, + { "color5", STRING, &colorname[5] }, + { "color6", STRING, &colorname[6] }, + { "color7", STRING, &colorname[7] }, + { "color8", STRING, &colorname[8] }, + { "color9", STRING, &colorname[9] }, + { "color10", STRING, &colorname[10] }, + { "color11", STRING, &colorname[11] }, + { "color12", STRING, &colorname[12] }, + { "color13", STRING, &colorname[13] }, + { "color14", STRING, &colorname[14] }, + { "color15", STRING, &colorname[15] }, + { "background", STRING, &colorname[256] }, + { "foreground", STRING, &colorname[257] }, + { "cursorColor", STRING, &colorname[258] }, + { "termname", STRING, &termname }, + { "shell", STRING, &shell }, + { "xfps", INTEGER, &xfps }, + { "actionfps", INTEGER, &actionfps }, + { "blinktimeout", INTEGER, &blinktimeout }, + { "bellvolume", INTEGER, &bellvolume }, + { "tabspaces", INTEGER, &tabspaces }, + { "borderpx", INTEGER, &borderpx }, + { "cwscale", FLOAT, &cwscale }, + { "chscale", FLOAT, &chscale }, + { "alpha", FLOAT, &alpha }, +}; + +/* * Internal mouse shortcuts. * Beware that overloading Button1 will disable the selection. */ @@ -199,7 +216,7 @@ static char *copyoutput[] = { "/bin/sh", "-c", "st-copyout", "externalpipe", NUL /* Internal keyboard shortcuts. */ #define MODKEY Mod1Mask #define TERMMOD (ControlMask|ShiftMask) -#define WINMOD (Mod4Mask|ShiftMask) +#define WINMOD (Mod4Mask|ShiftMask) static Shortcut shortcuts[] = { /* mask keysym function argument */ @@ -221,9 +238,7 @@ static Shortcut shortcuts[] = { { WINMOD, XK_C, externalpipe, { .v = copyurlcmd } }, { WINMOD, XK_O, externalpipe, { .v = openurlcmd } }, { TERMMOD, XK_O, externalpipe, { .v = copyoutput } }, - { XK_ANY_MOD, XK_F6, swapcolors, {.i = 0} }, - }; /* diff --git a/st.h b/st.h @@ -120,7 +120,6 @@ extern char *vtiden; extern char *worddelimiters; extern int allowaltscreen; extern char *termname; -extern int usealtcolors; extern unsigned int tabspaces; extern unsigned int defaultfg; extern unsigned int defaultbg; diff --git a/x.c b/x.c @@ -14,6 +14,7 @@ #include <X11/keysym.h> #include <X11/Xft/Xft.h> #include <X11/XKBlib.h> +#include <X11/Xresource.h> static char *argv0; #include "arg.h" @@ -43,6 +44,19 @@ typedef struct { signed char appcursor; /* application cursor */ } Key; +/* Xresources preferences */ +enum resource_type { + STRING = 0, + INTEGER = 1, + FLOAT = 2 +}; + +typedef struct { + char *name; + enum resource_type type; + void *dst; +} ResourcePref; + /* X modifiers */ #define XK_ANY_MOD UINT_MAX #define XK_NO_MOD 0 @@ -53,7 +67,6 @@ static void clipcopy(const Arg *); static void clippaste(const Arg *); static void numlock(const Arg *); static void selpaste(const Arg *); -static void swapcolors(const Arg *); static void zoom(const Arg *); static void zoomabs(const Arg *); static void zoomreset(const Arg *); @@ -243,8 +256,6 @@ static char *opt_title = NULL; static int oldbutton = 3; /* button event on startup: 3 = release */ -int usealtcolors = 0; /* 1 to use alternate palette */ - void clipcopy(const Arg *dummy) { @@ -284,14 +295,6 @@ numlock(const Arg *dummy) } void -swapcolors(const Arg *dummy) -{ - usealtcolors = !usealtcolors; - xloadcols(); - redraw(); -} - -void zoom(const Arg *arg) { Arg larg; @@ -715,11 +718,6 @@ sixd_to_16bit(int x) return x == 0 ? 0 : 0x3737 + 0x2828 * x; } -const char* getcolorname(int i) -{ - return (usealtcolors) ? altcolorname[i] : colorname[i]; -} - int xloadcolor(int i, const char *name, Color *ncolor) { @@ -738,7 +736,7 @@ xloadcolor(int i, const char *name, Color *ncolor) return XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &color, ncolor); } else - name = getcolorname(i); + name = colorname[i]; } return XftColorAllocName(xw.dpy, xw.vis, xw.cmap, name, ncolor); @@ -755,14 +753,14 @@ xloadcols(void) for (cp = dc.col; cp < &dc.col[dc.collen]; ++cp) XftColorFree(xw.dpy, xw.vis, xw.cmap, cp); } else { - dc.collen = MAX(LEN(colorname), LEN(altcolorname)); + dc.collen = MAX(LEN(colorname), 256); dc.col = xmalloc(dc.collen * sizeof(Color)); } for (i = 0; i < dc.collen; i++) if (!xloadcolor(i, NULL, &dc.col[i])) { - if (getcolorname(i)) - die("could not allocate color '%s'\n", getcolorname(i)); + if (colorname[i]) + die("could not allocate color '%s'\n", colorname[i]); else die("could not allocate color %d\n", i); } @@ -808,8 +806,8 @@ xclear(int x1, int y1, int x2, int y2) void xhints(void) { - XClassHint class = {opt_name ? opt_name : termname, - opt_class ? opt_class : termname}; + XClassHint class = {opt_name ? opt_name : "st", + opt_class ? opt_class : "St"}; XWMHints wm = {.flags = InputHint, .input = 1}; XSizeHints *sizeh; @@ -1032,8 +1030,6 @@ xinit(int cols, int rows) XWindowAttributes attr; XVisualInfo vis; - if (!(xw.dpy = XOpenDisplay(NULL))) - die("can't open display\n"); xw.scr = XDefaultScreen(xw.dpy); if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) { @@ -1115,13 +1111,13 @@ xinit(int cols, int rows) cursor = XCreateFontCursor(xw.dpy, mouseshape); XDefineCursor(xw.dpy, xw.win, cursor); - if (XParseColor(xw.dpy, xw.cmap, getcolorname(mousefg), &xmousefg) == 0) { + if (XParseColor(xw.dpy, xw.cmap, colorname[mousefg], &xmousefg) == 0) { xmousefg.red = 0xffff; xmousefg.green = 0xffff; xmousefg.blue = 0xffff; } - if (XParseColor(xw.dpy, xw.cmap, getcolorname(mousebg), &xmousebg) == 0) { + if (XParseColor(xw.dpy, xw.cmap, colorname[mousebg], &xmousebg) == 0) { xmousebg.red = 0x0000; xmousebg.green = 0x0000; xmousebg.blue = 0x0000; @@ -1903,6 +1899,59 @@ run(void) } } +int +resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst) +{ + char **sdst = dst; + int *idst = dst; + float *fdst = dst; + + char fullname[256]; + char fullclass[256]; + char *type; + XrmValue ret; + + snprintf(fullname, sizeof(fullname), "%s.%s", + opt_name ? opt_name : "st", name); + snprintf(fullclass, sizeof(fullclass), "%s.%s", + opt_class ? opt_class : "St", name); + fullname[sizeof(fullname) - 1] = fullclass[sizeof(fullclass) - 1] = '\0'; + + XrmGetResource(db, fullname, fullclass, &type, &ret); + if (ret.addr == NULL || strncmp("String", type, 64)) + return 1; + + switch (rtype) { + case STRING: + *sdst = ret.addr; + break; + case INTEGER: + *idst = strtoul(ret.addr, NULL, 10); + break; + case FLOAT: + *fdst = strtof(ret.addr, NULL); + break; + } + return 0; +} + +void +config_init(void) +{ + char *resm; + XrmDatabase db; + ResourcePref *p; + + XrmInitialize(); + resm = XResourceManagerString(xw.dpy); + if (!resm) + return; + + db = XrmGetStringDatabase(resm); + for (p = resources; p < resources + LEN(resources); p++) + resource_load(db, p->name, p->type, p->dst); +} + void usage(void) { @@ -1979,6 +2028,11 @@ run: setlocale(LC_CTYPE, ""); XSetLocaleModifiers(""); + + if(!(xw.dpy = XOpenDisplay(NULL))) + die("Can't open display\n"); + + config_init(); cols = MAX(cols, 1); rows = MAX(rows, 1); tnew(cols, rows);