aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorChristoph Lohmann <20h@r-36.net>2012-09-29 11:17:16 +0200
committerChristoph Lohmann <20h@r-36.net>2012-09-29 11:17:16 +0200
commitd7b1e31eec9a87c666334006de25a7f8102c55a9 (patch)
tree38c83ac16f7444e560e3649504688182b7232494 /st.c
parent29b209f5f55c80e457a5a913a463bd24f8e307e9 (diff)
downloadst-d7b1e31eec9a87c666334006de25a7f8102c55a9.tar.gz
st-d7b1e31eec9a87c666334006de25a7f8102c55a9.zip
All xcolors are not Xft colors and the clearing of the borders has been
optimized. There is a speedup when resizing windows.
Diffstat (limited to 'st.c')
-rw-r--r--st.c83
1 files changed, 53 insertions, 30 deletions
diff --git a/st.c b/st.c
index bb80321..ab8540c 100644
--- a/st.c
+++ b/st.c
@@ -239,13 +239,11 @@ typedef struct {
239 int descent; 239 int descent;
240 short lbearing; 240 short lbearing;
241 short rbearing; 241 short rbearing;
242 XFontSet set;
243 XftFont* xft_set; 242 XftFont* xft_set;
244} Font; 243} Font;
245 244
246/* Drawing Context */ 245/* Drawing Context */
247typedef struct { 246typedef struct {
248 ulong col[LEN(colorname) < 256 ? 256 : LEN(colorname)];
249 XftColor xft_col[LEN(colorname) < 256 ? 256 : LEN(colorname)]; 247 XftColor xft_col[LEN(colorname) < 256 ? 256 : LEN(colorname)];
250 GC gc; 248 GC gc;
251 Font font, bfont, ifont, ibfont; 249 Font font, bfont, ifont, ibfont;
@@ -299,12 +297,14 @@ static void ttywrite(const char *, size_t);
299static void xdraws(char *, Glyph, int, int, int, int); 297static void xdraws(char *, Glyph, int, int, int, int);
300static void xhints(void); 298static void xhints(void);
301static void xclear(int, int, int, int); 299static void xclear(int, int, int, int);
300static void xclearborders(void);
302static void xdrawcursor(void); 301static void xdrawcursor(void);
303static void xinit(void); 302static void xinit(void);
304static void xloadcols(void); 303static void xloadcols(void);
305static void xresettitle(void); 304static void xresettitle(void);
306static void xseturgency(int); 305static void xseturgency(int);
307static void xsetsel(char*); 306static void xsetsel(char*);
307static void xtermclear(int, int, int, int);
308static void xresize(int, int); 308static void xresize(int, int);
309 309
310static void expose(XEvent *); 310static void expose(XEvent *);
@@ -1307,7 +1307,7 @@ tsetmode(bool priv, bool set, int *args, int narg) {
1307 break; 1307 break;
1308 case 5: /* DECSCNM -- Reverve video */ 1308 case 5: /* DECSCNM -- Reverve video */
1309 mode = term.mode; 1309 mode = term.mode;
1310 MODBIT(term.mode,set, MODE_REVERSE); 1310 MODBIT(term.mode, set, MODE_REVERSE);
1311 if(mode != term.mode) 1311 if(mode != term.mode)
1312 redraw(); 1312 redraw();
1313 break; 1313 break;
@@ -1789,7 +1789,7 @@ tputc(char *c, int len) {
1789 case 'c': /* RIS -- Reset to inital state */ 1789 case 'c': /* RIS -- Reset to inital state */
1790 treset(); 1790 treset();
1791 term.esc = 0; 1791 term.esc = 0;
1792 xclear(0, 0, xw.w, xw.h); 1792 xclearborders();
1793 xresettitle(); 1793 xresettitle();
1794 break; 1794 break;
1795 case '=': /* DECPAM -- Application keypad */ 1795 case '=': /* DECPAM -- Application keypad */
@@ -1914,17 +1914,19 @@ void
1914xloadcols(void) { 1914xloadcols(void) {
1915 int i, r, g, b; 1915 int i, r, g, b;
1916 XRenderColor xft_color = { .alpha = 0 }; 1916 XRenderColor xft_color = { .alpha = 0 };
1917 ulong white = WhitePixel(xw.dpy, xw.scr); 1917
1918 /* load default white color */
1919 if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, colorname[256], &dc.xft_col[256]))
1920 die("Could not allocate color '%s'\n", colorname[256]);
1918 1921
1919 /* load colors [0-15] colors and [256-LEN(colorname)[ (config.h) */ 1922 /* load colors [0-15] colors and [256-LEN(colorname)[ (config.h) */
1920 for(i = 0; i < LEN(colorname); i++) { 1923 for(i = 0; i < LEN(colorname); i++) {
1921 if(!colorname[i]) 1924 if(!colorname[i])
1922 continue; 1925 continue;
1923 if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, colorname[i], &dc.xft_col[i])) { 1926 if(!XftColorAllocName(xw.dpy, xw.vis, xw.cmap, colorname[i], &dc.xft_col[i])) {
1924 dc.col[i] = white; 1927 dc.xft_col[i] = dc.xft_col[256];
1925 fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]); 1928 fprintf(stderr, "Could not allocate color '%s'\n", colorname[i]);
1926 } else 1929 }
1927 dc.col[i] = dc.xft_col[i].pixel;
1928 } 1930 }
1929 1931
1930 /* load colors [16-255] ; same colors as xterm */ 1932 /* load colors [16-255] ; same colors as xterm */
@@ -1935,29 +1937,51 @@ xloadcols(void) {
1935 xft_color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g; 1937 xft_color.green = g == 0 ? 0 : 0x3737 + 0x2828 * g;
1936 xft_color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b; 1938 xft_color.blue = b == 0 ? 0 : 0x3737 + 0x2828 * b;
1937 if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &xft_color, &dc.xft_col[i])) { 1939 if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &xft_color, &dc.xft_col[i])) {
1938 dc.col[i] = white; 1940 dc.xft_col[i] = dc.xft_col[256];
1939 fprintf(stderr, "Could not allocate color %d\n", i); 1941 fprintf(stderr, "Could not allocate color %d\n", i);
1940 } else 1942 }
1941 dc.col[i] = dc.xft_col[i].pixel;
1942 i++; 1943 i++;
1943 } 1944 }
1944 1945
1945 for(r = 0; r < 24; r++, i++) { 1946 for(r = 0; r < 24; r++, i++) {
1946 xft_color.red = xft_color.green = xft_color.blue = 0x0808 + 0x0a0a * r; 1947 xft_color.red = xft_color.green = xft_color.blue = 0x0808 + 0x0a0a * r;
1947 if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &xft_color, &dc.xft_col[i])) { 1948 if(!XftColorAllocValue(xw.dpy, xw.vis, xw.cmap, &xft_color, &dc.xft_col[i])) {
1948 dc.col[i] = white; 1949 dc.xft_col[i] = dc.xft_col[256];
1949 fprintf(stderr, "Could not allocate color %d\n", i); 1950 fprintf(stderr, "Could not allocate color %d\n", i);
1950 } else 1951 }
1951 dc.col[i] = dc.xft_col[i].pixel;
1952 } 1952 }
1953} 1953}
1954 1954
1955void 1955void
1956xtermclear(int col1, int row1, int col2, int row2) {
1957 XftDrawRect(xw.xft_draw,
1958 &dc.xft_col[IS_SET(MODE_REVERSE) ? DefaultFG : DefaultBG],
1959 BORDER + col1 * xw.cw,
1960 BORDER + row1 * xw.ch,
1961 (col2-col1+1) * xw.cw,
1962 (row2-row1+1) * xw.ch);
1963}
1964
1965/*
1966 * Absolute coordinates.
1967 */
1968void
1956xclear(int x1, int y1, int x2, int y2) { 1969xclear(int x1, int y1, int x2, int y2) {
1957 XSetForeground(xw.dpy, dc.gc, dc.col[IS_SET(MODE_REVERSE) ? DefaultFG : DefaultBG]); 1970 XftDrawRect(xw.xft_draw,
1958 XFillRectangle(xw.dpy, xw.buf, dc.gc, 1971 &dc.xft_col[IS_SET(MODE_REVERSE) ? DefaultFG : DefaultBG],
1959 BORDER + x1 * xw.cw, BORDER + y1 * xw.ch, 1972 x1, y1, x2-x1, y2-y1);
1960 (x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch); 1973}
1974
1975void
1976xclearborders(void) {
1977 /* top and left border */
1978 xclear(0, 0, BORDER, xw.h);
1979 xclear(0, 0, xw.w, BORDER);
1980
1981 /* lower and right border */
1982 xclear(BORDER, xw.th - 1, xw.w, xw.h);
1983 /* Will just draw what hasn't been drawn by the previous call. */
1984 xclear(xw.tw - 1, BORDER, xw.w, xw.h - xw.th - 2);
1961} 1985}
1962 1986
1963void 1987void
@@ -2048,8 +2072,8 @@ xinit(void) {
2048 xw.fy = 0; 2072 xw.fy = 0;
2049 } 2073 }
2050 2074
2051 attrs.background_pixel = dc.col[DefaultBG]; 2075 attrs.background_pixel = dc.xft_col[DefaultBG].pixel;
2052 attrs.border_pixel = dc.col[DefaultBG]; 2076 attrs.border_pixel = dc.xft_col[DefaultBG].pixel;
2053 attrs.bit_gravity = NorthWestGravity; 2077 attrs.bit_gravity = NorthWestGravity;
2054 attrs.event_mask = FocusChangeMask | KeyPressMask 2078 attrs.event_mask = FocusChangeMask | KeyPressMask
2055 | ExposureMask | VisibilityChangeMask | StructureNotifyMask 2079 | ExposureMask | VisibilityChangeMask | StructureNotifyMask
@@ -2123,16 +2147,15 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
2123 if(base.mode & (ATTR_ITALIC|ATTR_ITALIC)) 2147 if(base.mode & (ATTR_ITALIC|ATTR_ITALIC))
2124 font = &dc.ibfont; 2148 font = &dc.ibfont;
2125 2149
2126 XSetBackground(xw.dpy, dc.gc, dc.col[bg]);
2127 XSetForeground(xw.dpy, dc.gc, dc.col[fg]);
2128
2129 XftTextExtentsUtf8(xw.dpy, font->xft_set, (FcChar8 *)s, bytelen, &extents); 2150 XftTextExtentsUtf8(xw.dpy, font->xft_set, (FcChar8 *)s, bytelen, &extents);
2130 width = extents.xOff; 2151 width = extents.xOff;
2131 XftDrawRect(xw.xft_draw, &dc.xft_col[bg], winx, winy - font->ascent, width, xw.ch); 2152 XftDrawRect(xw.xft_draw, &dc.xft_col[bg], winx, winy - font->ascent, width, xw.ch);
2132 XftDrawStringUtf8(xw.xft_draw, &dc.xft_col[fg], font->xft_set, winx, winy, (FcChar8 *)s, bytelen); 2153 XftDrawStringUtf8(xw.xft_draw, &dc.xft_col[fg], font->xft_set, winx, winy, (FcChar8 *)s, bytelen);
2133 2154
2134 if(base.mode & ATTR_UNDERLINE) 2155 if(base.mode & ATTR_UNDERLINE) {
2135 XDrawLine(xw.dpy, xw.buf, dc.gc, winx, winy+1, winx+width-1, winy+1); 2156 XftDrawRect(xw.xft_draw, &dc.xft_col[fg], winx, winy+1,
2157 width, 1);
2158 }
2136} 2159}
2137 2160
2138void 2161void
@@ -2153,7 +2176,7 @@ xdrawcursor(void) {
2153 sl = utf8size(term.line[oldy][oldx].c); 2176 sl = utf8size(term.line[oldy][oldx].c);
2154 xdraws(term.line[oldy][oldx].c, term.line[oldy][oldx], oldx, oldy, 1, sl); 2177 xdraws(term.line[oldy][oldx].c, term.line[oldy][oldx], oldx, oldy, 1, sl);
2155 } else 2178 } else
2156 xclear(oldx, oldy, oldx, oldy); 2179 xtermclear(oldx, oldy, oldx, oldy);
2157 2180
2158 /* draw the new one */ 2181 /* draw the new one */
2159 if(!(term.c.state & CURSOR_HIDE)) { 2182 if(!(term.c.state & CURSOR_HIDE)) {
@@ -2178,7 +2201,7 @@ void
2178redraw(void) { 2201redraw(void) {
2179 struct timespec tv = {0, REDRAW_TIMEOUT * 1000}; 2202 struct timespec tv = {0, REDRAW_TIMEOUT * 1000};
2180 2203
2181 xclear(0, 0, xw.w, xw.h); 2204 xclearborders();
2182 tfulldirt(); 2205 tfulldirt();
2183 draw(); 2206 draw();
2184 XSync(xw.dpy, False); /* necessary for a good tput flash */ 2207 XSync(xw.dpy, False); /* necessary for a good tput flash */
@@ -2186,7 +2209,7 @@ redraw(void) {
2186} 2209}
2187 2210
2188void 2211void
2189draw() { 2212draw(void) {
2190 XdbeSwapInfo swpinfo[1] = {{xw.win, XdbeCopied}}; 2213 XdbeSwapInfo swpinfo[1] = {{xw.win, XdbeCopied}};
2191 2214
2192 drawregion(0, 0, term.col, term.row); 2215 drawregion(0, 0, term.col, term.row);
@@ -2208,7 +2231,7 @@ drawregion(int x1, int y1, int x2, int y2) {
2208 for(y = y1; y < y2; y++) { 2231 for(y = y1; y < y2; y++) {
2209 if(!term.dirty[y]) 2232 if(!term.dirty[y])
2210 continue; 2233 continue;
2211 xclear(0, y, term.col, y); 2234 xtermclear(0, y, term.col, y);
2212 term.dirty[y] = 0; 2235 term.dirty[y] = 0;
2213 base = term.line[y][0]; 2236 base = term.line[y][0];
2214 ic = ib = ox = 0; 2237 ic = ib = ox = 0;
@@ -2371,9 +2394,9 @@ resize(XEvent *e) {
2371 if(col == term.col && row == term.row) 2394 if(col == term.col && row == term.row)
2372 return; 2395 return;
2373 2396
2374 xclear(0, 0, xw.w, xw.h);
2375 tresize(col, row); 2397 tresize(col, row);
2376 xresize(col, row); 2398 xresize(col, row);
2399 xclearborders();
2377 ttyresize(); 2400 ttyresize();
2378} 2401}
2379 2402