commit fdd9a5d94541f44de251f2ff15585d300b09e322
parent 622d40eef6335c741b1b9eea22808b951903fdbb
Author: kocotian <kocotian@kocotian.pl>
Date: Wed, 23 Dec 2020 19:52:07 +0100
alpha, color schemes (with fix), configuration
Diffstat:
8 files changed, 91 insertions(+), 45 deletions(-)
diff --git a/config.def.h b/config.def.h
@@ -5,8 +5,8 @@
*
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/
-static char *font = "Liberation Mono:pixelsize=12:antialias=true:autohint=true";
-static int borderpx = 2;
+static char *font = "monospace:pixelsize=14:antialias=true:autohint=true";
+static int borderpx = 12;
/*
* What program is execed by st depends of these precedence rules:
@@ -93,35 +93,25 @@ char *termname = "st-256color";
*/
unsigned int tabspaces = 8;
-/* Terminal colors (16 first used in escape sequence) */
-static const char *colorname[] = {
- /* 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",
+/* bg opacity */
+float alpha = 0.85;
+
+/* Terminal colors (16 used in escape sequence) */
+static const char *palettes[][16] = {
+ {"black", "red3", "green3", "yellow3", "blue2", "magenta3", "cyan3", "gray90",
+ "gray50", "red", "green", "yellow", "#5c5cff", "magenta", "cyan", "white"},
+
+ {"#223", "#900", "#080", "#fe7", "#35e", "#fc5", "#18e", "#aaa",
+ "#666", "#f25", "#0b0", "#ff6", "#46f", "#d6a", "#6bf", "#ddd"},
+
+ {"#eaeaea", "#b7141f", "#457b24", "#fc7b08", "#134eb2", "#560088", "#0e717c", "#777777",
+ "#424242", "#e83b3f", "#7aba3a", "#fd8e09", "#54a4f3", "#aa4dbc", "#26bbd1", "#aaaaaa"},
+
+ {"#20242d", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#b3b8c3",
+ "#000000", "#b04b57", "#87b379", "#e5c179", "#7d8fa4", "#a47996", "#85a7a5", "#ffffff"},
};
+static const char **colorname;
/*
* Default colors (colorname index)
@@ -129,8 +119,8 @@ static const char *colorname[] = {
*/
unsigned int defaultfg = 7;
unsigned int defaultbg = 0;
-static unsigned int defaultcs = 256;
-static unsigned int defaultrcs = 257;
+unsigned int defaultcs = 256;
+unsigned int defaultrcs = 257;
/*
* Default shape of cursor
@@ -199,6 +189,15 @@ static Shortcut shortcuts[] = {
{ TERMMOD, XK_Y, selpaste, {.i = 0} },
{ ShiftMask, XK_Insert, selpaste, {.i = 0} },
{ TERMMOD, XK_Num_Lock, numlock, {.i = 0} },
+ { MODKEY|ShiftMask, XK_F1, setpalette, {.i = 0} },
+ { MODKEY|ShiftMask, XK_F2, setpalette, {.i = 1} },
+ { MODKEY|ShiftMask, XK_F3, setpalette, {.i = 2} },
+ { MODKEY|ShiftMask, XK_F4, setpalette, {.i = 3} },
+ { MODKEY|ShiftMask, XK_F5, setpalette, {.i = 4} },
+ { MODKEY|ShiftMask, XK_F6, setpalette, {.i = 5} },
+ { MODKEY|ShiftMask, XK_F7, setpalette, {.i = 6} },
+ { MODKEY|ShiftMask, XK_F8, setpalette, {.i = 7} },
+ { MODKEY|ShiftMask, XK_F9, setpalette, {.i = 8} },
};
/*
diff --git a/config.mk b/config.mk
@@ -16,7 +16,7 @@ PKG_CONFIG = pkg-config
INCS = -I$(X11INC) \
`$(PKG_CONFIG) --cflags fontconfig` \
`$(PKG_CONFIG) --cflags freetype2`
-LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
+LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
`$(PKG_CONFIG) --libs fontconfig` \
`$(PKG_CONFIG) --libs freetype2`
diff --git a/patches/st-alpha-0.8.2.diff b/patches/st-alpha-0.8.2.diff
diff --git a/patches/st-color_schemes-0.8.1.diff b/patches/st-color_schemes-0.8.1.diff
diff --git a/patches/st-osc_10_11_12-20200418-66520e1.diff b/patches/st-osc_10_11_12-20200418-66520e1.diff
diff --git a/st.c b/st.c
@@ -1878,12 +1878,23 @@ strhandle(void)
}
return;
case 4: /* color set */
- if (narg < 3)
+ case 10: /* foreground set */
+ case 11: /* background set */
+ case 12: /* cursor color */
+ if ((par == 4 && narg < 3) || narg < 2)
break;
- p = strescseq.args[2];
+ p = strescseq.args[((par == 4) ? 2 : 1)];
/* FALLTHROUGH */
case 104: /* color reset, here p = NULL */
- j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
+ if (par == 10)
+ j = defaultfg;
+ else if (par == 11)
+ j = defaultbg;
+ else if (par == 12)
+ j = defaultcs;
+ else
+ j = (narg > 1) ? atoi(strescseq.args[1]) : -1;
+
if (xsetcolorname(j, p)) {
if (par == 104 && narg <= 1)
return; /* color reset without parameter */
diff --git a/st.h b/st.h
@@ -123,3 +123,5 @@ extern char *termname;
extern unsigned int tabspaces;
extern unsigned int defaultfg;
extern unsigned int defaultbg;
+extern unsigned int defaultcs;
+extern float alpha;
diff --git a/x.c b/x.c
@@ -59,6 +59,7 @@ static void zoom(const Arg *);
static void zoomabs(const Arg *);
static void zoomreset(const Arg *);
static void ttysend(const Arg *);
+static void setpalette(const Arg *);
/* config.h for applying patches and the configuration. */
#include "config.h"
@@ -105,6 +106,7 @@ typedef struct {
XSetWindowAttributes attrs;
int scr;
int isfixed; /* is fixed geometry? */
+ int depth; /* bit depth */
int l, t; /* left and top offset */
int gm; /* geometry mask */
} XWindow;
@@ -243,6 +245,7 @@ static char *usedfont = NULL;
static double usedfontsize = 0;
static double defaultfontsize = 0;
+static char *opt_alpha = NULL;
static char *opt_class = NULL;
static char **opt_cmd = NULL;
static char *opt_embed = NULL;
@@ -734,7 +737,7 @@ xresize(int col, int row)
XFreePixmap(xw.dpy, xw.buf);
xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
- DefaultDepth(xw.dpy, xw.scr));
+ xw.depth);
XftDrawChange(xw.draw, xw.buf);
xclear(0, 0, win.w, win.h);
@@ -784,6 +787,7 @@ xloadcols(void)
XftColorFree(xw.dpy, xw.vis, xw.cmap, cp);
} else {
dc.collen = MAX(LEN(colorname), 256);
+ /* dc.collen = 16; */
dc.col = xmalloc(dc.collen * sizeof(Color));
}
@@ -794,6 +798,13 @@ xloadcols(void)
else
die("could not allocate color %d\n", i);
}
+
+ /* set alpha value of bg color */
+ if (opt_alpha)
+ alpha = strtof(opt_alpha, NULL);
+ dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
+ dc.col[defaultbg].pixel &= 0x00FFFFFF;
+ dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
loaded = 1;
}
@@ -1103,11 +1114,23 @@ xinit(int cols, int rows)
Window parent;
pid_t thispid = getpid();
XColor xmousefg, xmousebg;
+ XWindowAttributes attr;
+ XVisualInfo vis;
if (!(xw.dpy = XOpenDisplay(NULL)))
die("can't open display\n");
xw.scr = XDefaultScreen(xw.dpy);
- xw.vis = XDefaultVisual(xw.dpy, xw.scr);
+
+ if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
+ parent = XRootWindow(xw.dpy, xw.scr);
+ xw.depth = 32;
+ } else {
+ XGetWindowAttributes(xw.dpy, parent, &attr);
+ xw.depth = attr.depth;
+ }
+
+ XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
+ xw.vis = vis.visual;
/* font */
if (!FcInit())
@@ -1117,7 +1140,7 @@ xinit(int cols, int rows)
xloadfonts(usedfont, 0);
/* colors */
- xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
+ xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
xloadcols();
/* adjust fixed window geometry */
@@ -1137,19 +1160,15 @@ xinit(int cols, int rows)
| ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
xw.attrs.colormap = xw.cmap;
- if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
- parent = XRootWindow(xw.dpy, xw.scr);
xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
- win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
+ win.w, win.h, 0, xw.depth, InputOutput,
xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
| CWEventMask | CWColormap, &xw.attrs);
memset(&gcvalues, 0, sizeof(gcvalues));
gcvalues.graphics_exposures = False;
- dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
- &gcvalues);
- xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
- DefaultDepth(xw.dpy, xw.scr));
+ xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
+ dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
@@ -1843,6 +1862,7 @@ kpress(XEvent *ev)
len = 2;
}
}
+
ttywrite(buf, len, 1);
}
@@ -1991,6 +2011,15 @@ usage(void)
" [stty_args ...]\n", argv0, argv0);
}
+void setpalette(const Arg *arg) {
+
+ if ( arg->i < LEN(palettes) ) {
+ colorname = palettes[arg->i];
+ xloadcols();
+ cresize(win.w, win.h);
+ }
+}
+
int
main(int argc, char *argv[])
{
@@ -2002,6 +2031,9 @@ main(int argc, char *argv[])
case 'a':
allowaltscreen = 0;
break;
+ case 'A':
+ opt_alpha = EARGF(usage());
+ break;
case 'c':
opt_class = EARGF(usage());
break;
@@ -2043,6 +2075,8 @@ main(int argc, char *argv[])
} ARGEND;
run:
+ colorname = palettes[0];
+
if (argc > 0) /* eat all remaining arguments */
opt_cmd = argv;