st-alpha-0.8.2.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
st-alpha-0.8.2.diff (4773B)
---
1 diff --git a/config.def.h b/config.def.h
2 index 0e01717..e116631 100644
3 --- a/config.def.h
4 +++ b/config.def.h
5 @@ -82,6 +82,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 @@ -109,6 +112,7 @@ static const char *colorname[] = {
16 /* more colors can be added after 255 to use with DefaultXX */
17 "#cccccc",
18 "#555555",
19 + "black",
20 };
21
22
23 @@ -117,7 +121,7 @@ static const char *colorname[] = {
24 * foreground, background, cursor, reverse cursor
25 */
26 unsigned int defaultfg = 7;
27 -unsigned int defaultbg = 0;
28 +unsigned int defaultbg = 258;
29 static unsigned int defaultcs = 256;
30 static unsigned int defaultrcs = 257;
31
32 diff --git a/config.mk b/config.mk
33 index 0cbb002..1d2f0e2 100644
34 --- a/config.mk
35 +++ b/config.mk
36 @@ -16,7 +16,7 @@ PKG_CONFIG = pkg-config
37 INCS = -I$(X11INC) \
38 `$(PKG_CONFIG) --cflags fontconfig` \
39 `$(PKG_CONFIG) --cflags freetype2`
40 -LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
41 +LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft -lXrender\
42 `$(PKG_CONFIG) --libs fontconfig` \
43 `$(PKG_CONFIG) --libs freetype2`
44
45 diff --git a/st.h b/st.h
46 index 38c61c4..b7634ab 100644
47 --- a/st.h
48 +++ b/st.h
49 @@ -120,3 +120,4 @@ extern char *termname;
50 extern unsigned int tabspaces;
51 extern unsigned int defaultfg;
52 extern unsigned int defaultbg;
53 +extern float alpha;
54 diff --git a/x.c b/x.c
55 index 0422421..588dec3 100644
56 --- a/x.c
57 +++ b/x.c
58 @@ -98,6 +98,7 @@ typedef struct {
59 XSetWindowAttributes attrs;
60 int scr;
61 int isfixed; /* is fixed geometry? */
62 + int depth; /* bit depth */
63 int l, t; /* left and top offset */
64 int gm; /* geometry mask */
65 } XWindow;
66 @@ -229,6 +230,7 @@ static char *usedfont = NULL;
67 static double usedfontsize = 0;
68 static double defaultfontsize = 0;
69
70 +static char *opt_alpha = NULL;
71 static char *opt_class = NULL;
72 static char **opt_cmd = NULL;
73 static char *opt_embed = NULL;
74 @@ -688,7 +690,7 @@ xresize(int col, int row)
75
76 XFreePixmap(xw.dpy, xw.buf);
77 xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
78 - DefaultDepth(xw.dpy, xw.scr));
79 + xw.depth);
80 XftDrawChange(xw.draw, xw.buf);
81 xclear(0, 0, win.w, win.h);
82
83 @@ -748,6 +750,13 @@ xloadcols(void)
84 else
85 die("could not allocate color %d\n", i);
86 }
87 +
88 + /* set alpha value of bg color */
89 + if (opt_alpha)
90 + alpha = strtof(opt_alpha, NULL);
91 + dc.col[defaultbg].color.alpha = (unsigned short)(0xffff * alpha);
92 + dc.col[defaultbg].pixel &= 0x00FFFFFF;
93 + dc.col[defaultbg].pixel |= (unsigned char)(0xff * alpha) << 24;
94 loaded = 1;
95 }
96
97 @@ -1004,11 +1013,23 @@ xinit(int cols, int rows)
98 Window parent;
99 pid_t thispid = getpid();
100 XColor xmousefg, xmousebg;
101 + XWindowAttributes attr;
102 + XVisualInfo vis;
103
104 if (!(xw.dpy = XOpenDisplay(NULL)))
105 die("can't open display\n");
106 xw.scr = XDefaultScreen(xw.dpy);
107 - xw.vis = XDefaultVisual(xw.dpy, xw.scr);
108 +
109 + if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0)))) {
110 + parent = XRootWindow(xw.dpy, xw.scr);
111 + xw.depth = 32;
112 + } else {
113 + XGetWindowAttributes(xw.dpy, parent, &attr);
114 + xw.depth = attr.depth;
115 + }
116 +
117 + XMatchVisualInfo(xw.dpy, xw.scr, xw.depth, TrueColor, &vis);
118 + xw.vis = vis.visual;
119
120 /* font */
121 if (!FcInit())
122 @@ -1018,7 +1039,7 @@ xinit(int cols, int rows)
123 xloadfonts(usedfont, 0);
124
125 /* colors */
126 - xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
127 + xw.cmap = XCreateColormap(xw.dpy, parent, xw.vis, None);
128 xloadcols();
129
130 /* adjust fixed window geometry */
131 @@ -1038,19 +1059,15 @@ xinit(int cols, int rows)
132 | ButtonMotionMask | ButtonPressMask | ButtonReleaseMask;
133 xw.attrs.colormap = xw.cmap;
134
135 - if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
136 - parent = XRootWindow(xw.dpy, xw.scr);
137 xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
138 - win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
139 + win.w, win.h, 0, xw.depth, InputOutput,
140 xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
141 | CWEventMask | CWColormap, &xw.attrs);
142
143 memset(&gcvalues, 0, sizeof(gcvalues));
144 gcvalues.graphics_exposures = False;
145 - dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
146 - &gcvalues);
147 - xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
148 - DefaultDepth(xw.dpy, xw.scr));
149 + xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
150 + dc.gc = XCreateGC(xw.dpy, xw.buf, GCGraphicsExposures, &gcvalues);
151 XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
152 XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
153
154 @@ -1894,6 +1911,9 @@ main(int argc, char *argv[])
155 case 'a':
156 allowaltscreen = 0;
157 break;
158 + case 'A':
159 + opt_alpha = EARGF(usage());
160 + break;
161 case 'c':
162 opt_class = EARGF(usage());
163 break;