aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrandon Invergo <brandon@invergo.net>2012-07-28 14:27:26 +0200
committerBrandon Invergo <brandon@invergo.net>2012-07-28 14:27:26 +0200
commit94771d05886fbdd2422e66b7c0256ab27fa375cb (patch)
tree90848d3aba5b14f5ebc69780b7e61e5abf7f186b
parent8fdba7494fe33d3be1f6f96b8e900ef1bca01d47 (diff)
downloadst-94771d05886fbdd2422e66b7c0256ab27fa375cb.tar.gz
st-94771d05886fbdd2422e66b7c0256ab27fa375cb.zip
Implement Xdbe-based double-buffering
-rw-r--r--config.mk2
-rw-r--r--st.c50
2 files changed, 13 insertions, 39 deletions
diff --git a/config.mk b/config.mk
index 082a295..4f273cd 100644
--- a/config.mk
+++ b/config.mk
@@ -12,7 +12,7 @@ X11LIB = /usr/X11R6/lib
12 12
13# includes and libs 13# includes and libs
14INCS = -I. -I/usr/include -I${X11INC} 14INCS = -I. -I/usr/include -I${X11INC}
15LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lutil 15LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lutil -lXext
16 16
17# flags 17# flags
18CPPFLAGS = -DVERSION=\"${VERSION}\" 18CPPFLAGS = -DVERSION=\"${VERSION}\"
diff --git a/st.c b/st.c
index 4dc1c5a..0e82eaf 100644
--- a/st.c
+++ b/st.c
@@ -24,6 +24,7 @@
24#include <X11/Xutil.h> 24#include <X11/Xutil.h>
25#include <X11/cursorfont.h> 25#include <X11/cursorfont.h>
26#include <X11/keysym.h> 26#include <X11/keysym.h>
27#include <X11/extensions/Xdbe.h>
27 28
28#if defined(__linux) 29#if defined(__linux)
29 #include <pty.h> 30 #include <pty.h>
@@ -178,7 +179,7 @@ typedef struct {
178 Display* dpy; 179 Display* dpy;
179 Colormap cmap; 180 Colormap cmap;
180 Window win; 181 Window win;
181 Pixmap buf; 182 XdbeBackBuffer buf;
182 Atom xembed; 183 Atom xembed;
183 XIM xim; 184 XIM xim;
184 XIC xic; 185 XIC xic;
@@ -270,7 +271,7 @@ static void ttywrite(const char *, size_t);
270static void xdraws(char *, Glyph, int, int, int, int); 271static void xdraws(char *, Glyph, int, int, int, int);
271static void xhints(void); 272static void xhints(void);
272static void xclear(int, int, int, int); 273static void xclear(int, int, int, int);
273static void xcopy(int, int, int, int); 274static void xcopy();
274static void xdrawcursor(void); 275static void xdrawcursor(void);
275static void xinit(void); 276static void xinit(void);
276static void xloadcols(void); 277static void xloadcols(void);
@@ -1620,32 +1621,8 @@ tresize(int col, int row) {
1620 1621
1621void 1622void
1622xresize(int col, int row) { 1623xresize(int col, int row) {
1623 Pixmap newbuf;
1624 int oldw, oldh;
1625
1626 oldw = xw.bufw;
1627 oldh = xw.bufh;
1628 xw.bufw = MAX(1, col * xw.cw); 1624 xw.bufw = MAX(1, col * xw.cw);
1629 xw.bufh = MAX(1, row * xw.ch); 1625 xw.bufh = MAX(1, row * xw.ch);
1630 newbuf = XCreatePixmap(xw.dpy, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dpy, xw.scr));
1631 XCopyArea(xw.dpy, xw.buf, newbuf, dc.gc, 0, 0, xw.bufw, xw.bufh, 0, 0);
1632 XFreePixmap(xw.dpy, xw.buf);
1633 XSetForeground(xw.dpy, dc.gc, dc.col[DefaultBG]);
1634 if(xw.bufw > oldw)
1635 XFillRectangle(xw.dpy, newbuf, dc.gc, oldw, 0,
1636 xw.bufw-oldw, MIN(xw.bufh, oldh));
1637 else if(xw.bufw < oldw && (BORDER > 0 || xw.w > xw.bufw))
1638 XClearArea(xw.dpy, xw.win, BORDER+xw.bufw, BORDER,
1639 xw.w-xw.bufh-BORDER, BORDER+MIN(xw.bufh, oldh),
1640 False);
1641 if(xw.bufh > oldh)
1642 XFillRectangle(xw.dpy, newbuf, dc.gc, 0, oldh,
1643 xw.bufw, xw.bufh-oldh);
1644 else if(xw.bufh < oldh && (BORDER > 0 || xw.h > xw.bufh))
1645 XClearArea(xw.dpy, xw.win, BORDER, BORDER+xw.bufh,
1646 xw.w-2*BORDER, xw.h-xw.bufh-BORDER,
1647 False);
1648 xw.buf = newbuf;
1649} 1626}
1650 1627
1651void 1628void
@@ -1801,7 +1778,7 @@ xinit(void) {
1801 CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask 1778 CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask
1802 | CWColormap, 1779 | CWColormap,
1803 &attrs); 1780 &attrs);
1804 xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dpy, xw.scr)); 1781 xw.buf = XdbeAllocateBackBufferName(xw.dpy, xw.win, XdbeCopied);
1805 1782
1806 1783
1807 /* input methods */ 1784 /* input methods */
@@ -1871,10 +1848,10 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
1871 1848
1872/* copy buffer pixmap to screen pixmap */ 1849/* copy buffer pixmap to screen pixmap */
1873void 1850void
1874xcopy(int x, int y, int cols, int rows) { 1851xcopy() {
1875 int src_x = x*xw.cw, src_y = y*xw.ch, src_w = cols*xw.cw, src_h = rows*xw.ch; 1852 XdbeSwapInfo swpinfo[1] = {{xw.win, XdbeCopied}};
1876 int dst_x = BORDER+src_x, dst_y = BORDER+src_y; 1853 XdbeSwapBuffers(xw.dpy, swpinfo, 1);
1877 XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, src_x, src_y, src_w, src_h, dst_x, dst_y); 1854
1878} 1855}
1879 1856
1880void 1857void
@@ -1918,6 +1895,7 @@ xdrawcursor(void) {
1918void 1895void
1919draw() { 1896draw() {
1920 drawregion(0, 0, term.col, term.row); 1897 drawregion(0, 0, term.col, term.row);
1898 xcopy();
1921 gettimeofday(&xw.lastdraw, NULL); 1899 gettimeofday(&xw.lastdraw, NULL);
1922} 1900}
1923 1901
@@ -1959,7 +1937,6 @@ drawregion(int x1, int y1, int x2, int y2) {
1959 } 1937 }
1960 if(ib > 0) 1938 if(ib > 0)
1961 xdraws(buf, base, ox, y, ic, ib); 1939 xdraws(buf, base, ox, y, ic, ib);
1962 xcopy(0, y, term.col, 1);
1963 } 1940 }
1964 xdrawcursor(); 1941 xdrawcursor();
1965} 1942}
@@ -1968,13 +1945,10 @@ void
1968expose(XEvent *ev) { 1945expose(XEvent *ev) {
1969 XExposeEvent *e = &ev->xexpose; 1946 XExposeEvent *e = &ev->xexpose;
1970 if(xw.state & WIN_REDRAW) { 1947 if(xw.state & WIN_REDRAW) {
1971 if(!e->count) { 1948 if(!e->count)
1972 xw.state &= ~WIN_REDRAW; 1949 xw.state &= ~WIN_REDRAW;
1973 xcopy(0, 0, term.col, term.row); 1950 }
1974 } 1951 xcopy();
1975 } else
1976 XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, e->x-BORDER, e->y-BORDER,
1977 e->width, e->height, e->x, e->y);
1978} 1952}
1979 1953
1980void 1954void