| st-alpha-20240814-a0274bc.diff - sites - public wiki contents of suckless.org | |
| git clone git://git.suckless.org/sites | |
| Log | |
| Files | |
| Refs | |
| --- | |
| st-alpha-20240814-a0274bc.diff (3699B) | |
| --- | |
| 1 diff --git a/config.def.h b/config.def.h | |
| 2 index 2cd740a..019a4e1 100644 | |
| 3 --- a/config.def.h | |
| 4 +++ b/config.def.h | |
| 5 @@ -93,6 +93,9 @@ char *termname = "st-256color"; | |
| 6 */ | |
| 7 unsigned int tabspaces = 8; | |
| 8 | |
| 9 +/* bg opacity */ | |
| 10 +float alpha = 0.8; | |
| 11 + | |
| 12 /* Terminal colors (16 first used in escape sequence) */ | |
| 13 static const char *colorname[] = { | |
| 14 /* 8 normal colors */ | |
| 15 diff --git a/x.c b/x.c | |
| 16 index d73152b..f32fd6c 100644 | |
| 17 --- a/x.c | |
| 18 +++ b/x.c | |
| 19 @@ -105,6 +105,7 @@ typedef struct { | |
| 20 XSetWindowAttributes attrs; | |
| 21 int scr; | |
| 22 int isfixed; /* is fixed geometry? */ | |
| 23 + int depth; /* bit depth */ | |
| 24 int l, t; /* left and top offset */ | |
| 25 int gm; /* geometry mask */ | |
| 26 } XWindow; | |
| 27 @@ -752,7 +753,7 @@ xresize(int col, int row) | |
| 28 | |
| 29 XFreePixmap(xw.dpy, xw.buf); | |
| 30 xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, | |
| 31 - DefaultDepth(xw.dpy, xw.scr)); | |
| 32 + xw.depth); | |
| 33 XftDrawChange(xw.draw, xw.buf); | |
| 34 xclear(0, 0, win.w, win.h); | |
| 35 | |
| 36 @@ -812,6 +813,10 @@ xloadcols(void) | |
| 37 else | |
| 38 die("could not allocate color %d\n", i); | |
| 39 } | |
| 40 + | |
| 41 + dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha… | |
| 42 + dc.col[defaultbg].pixel &= 0x00FFFFFF; | |
| 43 + dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24; | |
| 44 loaded = 1; | |
| 45 } | |
| 46 | |
| 47 @@ -842,6 +847,12 @@ xsetcolorname(int x, const char *name) | |
| 48 XftColorFree(xw.dpy, xw.vis, xw.cmap, &dc.col[x]); | |
| 49 dc.col[x] = ncolor; | |
| 50 | |
| 51 + if (x == defaultbg) { | |
| 52 + dc.col[defaultbg].color.alpha = (unsigned short)(0xffff… | |
| 53 + dc.col[defaultbg].pixel &= 0x00FFFFFF; | |
| 54 + dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha… | |
| 55 + } | |
| 56 + | |
| 57 return 0; | |
| 58 } | |
| 59 | |
| 60 @@ -1134,11 +1145,25 @@ xinit(int cols, int rows) | |
| 61 Window parent, root; | |
| 62 pid_t thispid = getpid(); | |
| 63 XColor xmousefg, xmousebg; | |
| 64 + XWindowAttributes attr; | |
| 65 + XVisualInfo vis; | |
| 66 | |
| 67 if (!(xw.dpy = XOpenDisplay(NULL))) | |
| 68 die("can't open display\n"); | |
| 69 xw.scr = XDefaultScreen(xw.dpy); | |
| 70 - xw.vis = XDefaultVisual(xw.dpy, xw.scr); | |
| 71 + | |
| 72 + root = XRootWindow(xw.dpy, xw.scr); | |
| 73 + if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) | |
| 74 + parent = root; | |
| 75 + | |
| 76 + if (XMatchVisualInfo(xw.dpy, xw.scr, 32, TrueColor, &vis) != 0)… | |
| 77 + xw.vis = vis.visual; | |
| 78 + xw.depth = vis.depth; | |
| 79 + } else { | |
| 80 + XGetWindowAttributes(xw.dpy, parent, &attr); | |
| 81 + xw.vis = attr.visual; | |
| 82 + xw.depth = attr.depth; | |
| 83 + } | |
| 84 | |
| 85 /* font */ | |
| 86 if (!FcInit()) | |
| 87 @@ -1148,7 +1173,7 @@ xinit(int cols, int rows) | |
| 88 xloadfonts(usedfont, 0); | |
| 89 | |
| 90 /* colors */ | |
| 91 - xw.cmap = XDefaultColormap(xw.dpy, xw.scr); | |
| 92 + xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None); | |
| 93 xloadcols(); | |
| 94 | |
| 95 /* adjust fixed window geometry */ | |
| 96 @@ -1168,11 +1193,8 @@ xinit(int cols, int rows) | |
| 97 | ButtonMotionMask | ButtonPressMask | ButtonReleaseMas… | |
| 98 xw.attrs.colormap = xw.cmap; | |
| 99 | |
| 100 - root = XRootWindow(xw.dpy, xw.scr); | |
| 101 - if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) | |
| 102 - parent = root; | |
| 103 - xw.win = XCreateWindow(xw.dpy, root, xw.l, xw.t, | |
| 104 - win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr),… | |
| 105 + xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t, | |
| 106 + win.w, win.h, 0, xw.depth, InputOutput, | |
| 107 xw.vis, CWBackPixel | CWBorderPixel | CWBitGrav… | |
| 108 | CWEventMask | CWColormap, &xw.attrs); | |
| 109 if (parent != root) | |
| 110 @@ -1183,7 +1205,7 @@ xinit(int cols, int rows) | |
| 111 dc.gc = XCreateGC(xw.dpy, xw.win, GCGraphicsExposures, | |
| 112 &gcvalues); | |
| 113 xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, | |
| 114 - DefaultDepth(xw.dpy, xw.scr)); | |
| 115 + xw.depth); | |
| 116 XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel); | |
| 117 XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h); | |
| 118 | |
| 119 @@ -2047,6 +2069,10 @@ main(int argc, char *argv[]) | |
| 120 case 'a': | |
| 121 allowaltscreen = 0; | |
| 122 break; | |
| 123 + case 'A': | |
| 124 + alpha = strtof(EARGF(usage()), NULL); | |
| 125 + LIMIT(alpha, 0.0, 1.0); | |
| 126 + break; | |
| 127 case 'c': | |
| 128 opt_class = EARGF(usage()); | |
| 129 break; |