st-alpha-0.8.1.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.1.diff (5464B)
---
1 diff --git a/config.def.h b/config.def.h
2 index 82b1b09..2c721e8 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 +unsigned int alpha = 0xcc;
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 = 257;
29 static unsigned int defaultcs = 256;
30 static unsigned int defaultrcs = 257;
31
32 diff --git a/config.mk b/config.mk
33 index 039c42c..b1fa717 100644
34 --- a/config.mk
35 +++ b/config.mk
36 @@ -11,10 +11,10 @@ X11INC = /usr/X11R6/include
37 X11LIB = /usr/X11R6/lib
38
39 # includes and libs
40 -INCS = -I$(X11INC) \
41 +INCS = -I. -I/usr/include -I${X11INC} \
42 `pkg-config --cflags fontconfig` \
43 `pkg-config --cflags freetype2`
44 -LIBS = -L$(X11LIB) -lm -lrt -lX11 -lutil -lXft \
45 +LIBS = -L/usr/lib -lc -L${X11LIB} -lm -lrt -lX11 -lutil -lXft -lXrender\
46 `pkg-config --libs fontconfig` \
47 `pkg-config --libs freetype2`
48
49 diff --git a/st.h b/st.h
50 index dac64d8..433c74f 100644
51 --- a/st.h
52 +++ b/st.h
53 @@ -119,5 +119,6 @@ extern char *worddelimiters;
54 extern int allowaltscreen;
55 extern char *termname;
56 extern unsigned int tabspaces;
57 +extern unsigned int alpha;
58 extern unsigned int defaultfg;
59 extern unsigned int defaultbg;
60 diff --git a/x.c b/x.c
61 index c0bd890..0562571 100644
62 --- a/x.c
63 +++ b/x.c
64 @@ -48,6 +48,10 @@ typedef struct {
65 #define XK_NO_MOD 0
66 #define XK_SWITCH_MOD (1<<13)
67
68 +/* alpha */
69 +#define OPAQUE 0Xff
70 +#define USE_ARGB (alpha != OPAQUE && opt_embed == NULL)
71 +
72 /* function definitions used in config.h */
73 static void clipcopy(const Arg *);
74 static void clippaste(const Arg *);
75 @@ -98,6 +102,7 @@ typedef struct {
76 XSetWindowAttributes attrs;
77 int scr;
78 int isfixed; /* is fixed geometry? */
79 + int depth; /* bit depth */
80 int l, t; /* left and top offset */
81 int gm; /* geometry mask */
82 } XWindow;
83 @@ -686,7 +691,7 @@ xresize(int col, int row)
84
85 XFreePixmap(xw.dpy, xw.buf);
86 xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
87 - DefaultDepth(xw.dpy, xw.scr));
88 + xw.depth);
89 XftDrawChange(xw.draw, xw.buf);
90 xclear(0, 0, win.w, win.h);
91
92 @@ -746,6 +751,13 @@ xloadcols(void)
93 else
94 die("could not allocate color %d\n", i);
95 }
96 +
97 + /* set alpha value of bg color */
98 + if (USE_ARGB) {
99 + dc.col[defaultbg].color.alpha = (0xffff * alpha) / OPAQUE;
100 + dc.col[defaultbg].pixel &= 0x00111111;
101 + dc.col[defaultbg].pixel |= alpha << 24;
102 + }
103 loaded = 1;
104 }
105
106 @@ -767,6 +779,17 @@ xsetcolorname(int x, const char *name)
107 return 0;
108 }
109
110 +void
111 +xtermclear(int col1, int row1, int col2, int row2)
112 +{
113 + XftDrawRect(xw.draw,
114 + &dc.col[IS_SET(MODE_REVERSE) ? defaultfg : defaultbg],
115 + borderpx + col1 * win.cw,
116 + borderpx + row1 * win.ch,
117 + (col2-col1+1) * win.cw,
118 + (row2-row1+1) * win.ch);
119 +}
120 +
121 /*
122 * Absolute coordinates.
123 */
124 @@ -1004,7 +1027,40 @@ xinit(int cols, int rows)
125 if (!(xw.dpy = XOpenDisplay(NULL)))
126 die("can't open display\n");
127 xw.scr = XDefaultScreen(xw.dpy);
128 - xw.vis = XDefaultVisual(xw.dpy, xw.scr);
129 + xw.depth = (USE_ARGB) ? 32: XDefaultDepth(xw.dpy, xw.scr);
130 + if (!USE_ARGB)
131 + xw.vis = XDefaultVisual(xw.dpy, xw.scr);
132 + else {
133 + XVisualInfo *vis;
134 + XRenderPictFormat *fmt;
135 + int nvi;
136 + int i;
137 +
138 + XVisualInfo tpl = {
139 + .screen = xw.scr,
140 + .depth = 32,
141 + .class = TrueColor
142 + };
143 +
144 + vis = XGetVisualInfo(xw.dpy,
145 + VisualScreenMask | VisualDepthMask | VisualClassMask,
146 + &tpl, &nvi);
147 + xw.vis = NULL;
148 + for (i = 0; i < nvi; i++) {
149 + fmt = XRenderFindVisualFormat(xw.dpy, vis[i].visual);
150 + if (fmt->type == PictTypeDirect && fmt->direct.alphaMask) {
151 + xw.vis = vis[i].visual;
152 + break;
153 + }
154 + }
155 +
156 + XFree(vis);
157 +
158 + if (!xw.vis) {
159 + fprintf(stderr, "Couldn't find ARGB visual.\n");
160 + exit(1);
161 + }
162 + }
163
164 /* font */
165 if (!FcInit())
166 @@ -1014,7 +1070,11 @@ xinit(int cols, int rows)
167 xloadfonts(usedfont, 0);
168
169 /* colors */
170 - xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
171 + if (!USE_ARGB)
172 + xw.cmap = XDefaultColormap(xw.dpy, xw.scr);
173 + else
174 + xw.cmap = XCreateColormap(xw.dpy, XRootWindow(xw.dpy, xw.scr),
175 + xw.vis, None);
176 xloadcols();
177
178 /* adjust fixed window geometry */
179 @@ -1037,16 +1097,15 @@ xinit(int cols, int rows)
180 if (!(opt_embed && (parent = strtol(opt_embed, NULL, 0))))
181 parent = XRootWindow(xw.dpy, xw.scr);
182 xw.win = XCreateWindow(xw.dpy, parent, xw.l, xw.t,
183 - win.w, win.h, 0, XDefaultDepth(xw.dpy, xw.scr), InputOutput,
184 + win.w, win.h, 0, xw.depth, InputOutput,
185 xw.vis, CWBackPixel | CWBorderPixel | CWBitGravity
186 | CWEventMask | CWColormap, &xw.attrs);
187
188 memset(&gcvalues, 0, sizeof(gcvalues));
189 gcvalues.graphics_exposures = False;
190 - dc.gc = XCreateGC(xw.dpy, parent, GCGraphicsExposures,
191 - &gcvalues);
192 - xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h,
193 - DefaultDepth(xw.dpy, xw.scr));
194 + xw.buf = XCreatePixmap(xw.dpy, xw.win, win.w, win.h, xw.depth);
195 + dc.gc = XCreateGC(xw.dpy, (USE_ARGB) ? xw.buf: parent,
196 + GCGraphicsExposures, &gcvalues);
197 XSetForeground(xw.dpy, dc.gc, dc.col[defaultbg].pixel);
198 XFillRectangle(xw.dpy, xw.buf, dc.gc, 0, 0, win.w, win.h);
199