st-alpha-20170509-5a10aca.diff - sites - public wiki contents of suckless.org
(HTM) git clone git://git.suckless.org/sites
(DIR) Log
(DIR) Files
(DIR) Refs
---
st-alpha-20170509-5a10aca.diff (5374B)
---
1 diff --git a/config.def.h b/config.def.h
2 index 877afab..0e423b1 100644
3 --- a/config.def.h
4 +++ b/config.def.h
5 @@ -82,6 +82,9 @@ char termname[] = "st-256color";
6 */
7 static unsigned int tabspaces = 8;
8
9 +/* bg opacity */
10 +unsigned int alpha = 0xcc;
11 +
12 /* Terminal colors (16 first used in escape sequence) */
13 const char *colorname[] = {
14 /* 8 normal colors */
15 @@ -109,6 +112,7 @@ 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 @@ const char *colorname[] = {
24 * foreground, background, cursor, reverse cursor
25 */
26 unsigned int defaultfg = 7;
27 -unsigned int defaultbg = 0;
28 +unsigned int defaultbg = 257;
29 unsigned int defaultcs = 256;
30 unsigned int defaultrcs = 257;
31
32 diff --git a/config.mk b/config.mk
33 index c84c5ee..2854f6c 100644
34 --- a/config.mk
35 +++ b/config.mk
36 @@ -14,7 +14,7 @@ X11LIB = /usr/X11R6/lib
37 INCS = -I. -I/usr/include -I${X11INC} \
38 `pkg-config --cflags fontconfig` \
39 `pkg-config --cflags freetype2`
40 -LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXft \
41 +LIBS = -L/usr/lib -lc -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 44d4938..180fdba 100644
47 --- a/st.h
48 +++ b/st.h
49 @@ -251,6 +251,7 @@ extern unsigned int blinktimeout;
50 extern char termname[];
51 extern const char *colorname[];
52 extern size_t colornamelen;
53 +extern unsigned int alpha;
54 extern unsigned int defaultfg;
55 extern unsigned int defaultbg;
56 extern unsigned int defaultcs;
57 diff --git a/win.h b/win.h
58 index 428111c..05e8482 100644
59 --- a/win.h
60 +++ b/win.h
61 @@ -5,6 +5,10 @@
62 #define XK_NO_MOD 0
63 #define XK_SWITCH_MOD (1<<13)
64
65 +/* alpha */
66 +#define OPAQUE 0Xff
67 +#define USE_ARGB (alpha != OPAQUE && opt_embed == NULL)
68 +
69 typedef XftGlyphFontSpec GlyphFontSpec;
70
71 void draw(void);
72 diff --git a/x.c b/x.c
73 index fbfd350..5d111da 100644
74 --- a/x.c
75 +++ b/x.c
76 @@ -49,6 +49,7 @@ typedef struct {
77 XSetWindowAttributes attrs;
78 int scr;
79 int isfixed; /* is fixed geometry? */
80 + int depth; /* bit depth */
81 int l, t; /* left and top offset */
82 int gm; /* geometry mask */
83 } XWindow;
84 @@ -562,7 +563,7 @@ xresize(int col, int row)
85
86 XFreePixmap(xw.dpy, xw.buf);
87 xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
88 - DefaultDepth(xw.dpy, xw.scr));
89 + xw.depth);
90 XftDrawChange(xw.draw, xw.buf);
91 xclear(0, 0, win.w, win.h);
92 }
93 @@ -619,6 +620,13 @@ xloadcols(void)
94 else
95 die("Could not allocate color %d\n", i);
96 }
97 +
98 + /* set alpha value of bg color */
99 + if (USE_ARGB) {
100 + dc.col[defaultbg].color.alpha = (0xffff * alpha) / OPAQUE;
101 + dc.col[defaultbg].pixel &= 0x00111111;
102 + dc.col[defaultbg].pixel |= alpha << 24;
103 + }
104 loaded = 1;
105 }
106
107 @@ -640,6 +648,17 @@ xsetcolorname(int x, const char *name)
108 return 0;
109 }
110
111 +void
112 +xtermclear(int col1, int row1, int col2, int row2)
113 +{
114 + XftDrawRect(xw.draw,
115 + &dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg],
116 + borderpx + col1 * win.cw,
117 + borderpx + row1 * win.ch,
118 + (col2-col1+1) * win.cw,
119 + (row2-row1+1) * win.ch);
120 +}
121 +
122 /*
123 * Absolute coordinates.
124 */
125 @@ -879,7 +898,40 @@ xinit(void)
126 if (!(xw.dpy = XOpenDisplay(NULL)))
127 die("Can't open display\n");
128 xw.scr = XDefaultScreen(xw.dpy);
129 - xw.vis = XDefaultVisual(xw.dpy, xw.scr);
130 + xw.depth = (USE_ARGB) ? 32: XDefaultDepth(xw.dpy, xw.scr);
131 + if (!USE_ARGB)
132 + xw.vis = XDefaultVisual(xw.dpy, xw.scr);
133 + else {
134 + XVisualInfo *vis;
135 + XRenderPictFormat *fmt;
136 + int nvi;
137 + int i;
138 +
139 + XVisualInfo tpl = {
140 + .screen = xw.scr,
141 + .depth = 32,
142 + .class = TrueColor
143 + };
144 +
145 + vis = XGetVisualInfo(xw.dpy,
146 + VisualScreenMask | VisualDepthMask | VisualClassMask,
147 + &tpl, &nvi);
148 + xw.vis = NULL;
149 + for (i = 0; i < nvi; i++) {
150 + fmt = XRenderFindVisualFormat(xw.dpy, vis[i].visual);
151 + if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
152 + xw.vis = vis[i].visual;
153 + break;
154 + }
155 + }
156 +
157 + XFree(vis);
158 +
159 + if (!xw.vis) {
160 + fprintf(stderr, "Couldn't find ARGB visual.\n");
161 + exit(1);
162 + }
163 + }
164
165 /* font */
166 if (!FcInit())
167 @@ -889,7 +941,11 @@ xinit(void)
168 xloadfonts(usedfont, 0);
169
170 /* colors */
171 - xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
172 + if (!USE_ARGB)
173 + xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
174 + else
175 + xw.cmap = XCreateColormap(xw.dpy, XRootWindow(xw.dpy, xw.scr),
176 + xw.vis, None);
177 xloadcols();
178
179 /* adjust fixed window geometry */
180 @@ -912,16 +968,15 @@ xinit(void)
181 if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
182 parent = XRootWindow(xw.dpy, xw.scr);
183 xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
184 - win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
185 + win.w, win.h, 0, xw.depth, InputOutput,
186 xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
187 | CWEventMask | CWColormap, &xw.attrs);
188
189 memset(&gcvalues, 0, sizeof(gcvalues));
190 gcvalues.graphics_exposures = False;
191 - dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
192 - &gcvalues);
193 - xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
194 - DefaultDepth(xw.dpy, xw.scr));
195 + xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
196 + dc.gc = XCreateGC(xw.dpy, (USE_ARGB) ? xw.buf: parent,
197 + GCGraphicsExposures, &gcvalues);
198 XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
199 XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
200