Xinqi Bao's Git

patch: anysize
[st.git] / patches / st-alpha-20220206-0.8.5.diff
1 diff --git a/config.def.h b/config.def.h
2 index 91ab8ca..6af616e 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/config.mk b/config.mk
16 index 4c4c5d5..0114bad 100644
17 --- a/config.mk
18 +++ b/config.mk
19 @@ -16,7 +16,7 @@ PKG_CONFIG = pkg-config
20 INCS = -I$(X11INC) \
21 `$(PKG_CONFIG) --cflags fontconfig` \
22 `$(PKG_CONFIG) --cflags freetype2`
23 -LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
24 +LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
25 `$(PKG_CONFIG) --libs fontconfig` \
26 `$(PKG_CONFIG) --libs freetype2`
27
28 diff --git a/st.h b/st.h
29 index 519b9bd..8bb533d 100644
30 --- a/st.h
31 +++ b/st.h
32 @@ -126,3 +126,4 @@ extern unsigned int tabspaces;
33 extern unsigned int defaultfg;
34 extern unsigned int defaultbg;
35 extern unsigned int defaultcs;
36 +extern float alpha;
37 diff --git a/x.c b/x.c
38 index 8a16faa..ddf4178 100644
39 --- a/x.c
40 +++ b/x.c
41 @@ -105,6 +105,7 @@ typedef struct {
42 XSetWindowAttributes attrs;
43 int scr;
44 int isfixed; /* is fixed geometry? */
45 + int depth; /* bit depth */
46 int l, t; /* left and top offset */
47 int gm; /* geometry mask */
48 } XWindow;
49 @@ -243,6 +244,7 @@ static char *usedfont = NULL;
50 static double usedfontsize = 0;
51 static double defaultfontsize = 0;
52
53 +static char *opt_alpha = NULL;
54 static char *opt_class = NULL;
55 static char **opt_cmd = NULL;
56 static char *opt_embed = NULL;
57 @@ -736,7 +738,7 @@ xresize(int col, int row)
58
59 XFreePixmap(xw.dpy, xw.buf);
60 xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
61 - DefaultDepth(xw.dpy, xw.scr));
62 + xw.depth);
63 XftDrawChange(xw.draw, xw.buf);
64 xclear(0, 0, win.w, win.h);
65
66 @@ -796,6 +798,13 @@ xloadcols(void)
67 else
68 die("could not allocate color %d\n", i);
69 }
70 +
71 + /* set alpha value of bg color */
72 + if (opt_alpha)
73 + alpha = strtof(opt_alpha, NULL);
74 + dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
75 + dc.col[defaultbg].pixel &= 0x00FFFFFF;
76 + dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
77 loaded = 1;
78 }
79
80 @@ -1118,11 +1127,23 @@ xinit(int cols, int rows)
81 Window parent;
82 pid_t thispid = getpid();
83 XColor xmousefg, xmousebg;
84 + XWindowAttributes attr;
85 + XVisualInfo vis;
86
87 if (!(xw.dpy = XOpenDisplay(NULL)))
88 die("can't open display\n");
89 xw.scr = XDefaultScreen(xw.dpy);
90 - xw.vis = XDefaultVisual(xw.dpy, xw.scr);
91 +
92 + if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
93 + parent = XRootWindow(xw.dpy, xw.scr);
94 + xw.depth = 32;
95 + } else {
96 + XGetWindowAttributes(xw.dpy, parent, &attr);
97 + xw.depth = attr.depth;
98 + }
99 +
100 + XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
101 + xw.vis = vis.visual;
102
103 /* font */
104 if (!FcInit())
105 @@ -1132,7 +1153,7 @@ xinit(int cols, int rows)
106 xloadfonts(usedfont, 0);
107
108 /* colors */
109 - xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
110 + xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
111 xloadcols();
112
113 /* adjust fixed window geometry */
114 @@ -1152,19 +1173,15 @@ xinit(int cols, int rows)
115 | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
116 xw.attrs.colormap = xw.cmap;
117
118 - if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
119 - parent = XRootWindow(xw.dpy, xw.scr);
120 xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
121 - win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
122 + win.w, win.h, 0, xw.depth, InputOutput,
123 xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
124 | CWEventMask | CWColormap, &xw.attrs);
125
126 memset(&gcvalues, 0, sizeof(gcvalues));
127 gcvalues.graphics_exposures = False;
128 - dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
129 - &gcvalues);
130 - xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
131 - DefaultDepth(xw.dpy, xw.scr));
132 + xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
133 + dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
134 XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
135 XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
136
137 @@ -2019,6 +2036,9 @@ main(int argc, char *argv[])
138 case 'a':
139 allowaltscreen = 0;
140 break;
141 + case 'A':
142 + opt_alpha = EARGF(usage());
143 + break;
144 case 'c':
145 opt_class = EARGF(usage());
146 break;