diff options
| author | Brandon Invergo <brandon@invergo.net> | 2012-07-28 14:27:26 +0200 |
|---|---|---|
| committer | Brandon Invergo <brandon@invergo.net> | 2012-07-28 14:27:26 +0200 |
| commit | 94771d05886fbdd2422e66b7c0256ab27fa375cb (patch) | |
| tree | 90848d3aba5b14f5ebc69780b7e61e5abf7f186b | |
| parent | 8fdba7494fe33d3be1f6f96b8e900ef1bca01d47 (diff) | |
| download | st-94771d05886fbdd2422e66b7c0256ab27fa375cb.tar.gz st-94771d05886fbdd2422e66b7c0256ab27fa375cb.zip | |
Implement Xdbe-based double-buffering
| -rw-r--r-- | config.mk | 2 | ||||
| -rw-r--r-- | st.c | 50 |
2 files changed, 13 insertions, 39 deletions
| @@ -12,7 +12,7 @@ X11LIB = /usr/X11R6/lib | |||
| 12 | 12 | ||
| 13 | # includes and libs | 13 | # includes and libs |
| 14 | INCS = -I. -I/usr/include -I${X11INC} | 14 | INCS = -I. -I/usr/include -I${X11INC} |
| 15 | LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lutil | 15 | LIBS = -L/usr/lib -lc -L${X11LIB} -lX11 -lutil -lXext |
| 16 | 16 | ||
| 17 | # flags | 17 | # flags |
| 18 | CPPFLAGS = -DVERSION=\"${VERSION}\" | 18 | CPPFLAGS = -DVERSION=\"${VERSION}\" |
| @@ -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); | |||
| 270 | static void xdraws(char *, Glyph, int, int, int, int); | 271 | static void xdraws(char *, Glyph, int, int, int, int); |
| 271 | static void xhints(void); | 272 | static void xhints(void); |
| 272 | static void xclear(int, int, int, int); | 273 | static void xclear(int, int, int, int); |
| 273 | static void xcopy(int, int, int, int); | 274 | static void xcopy(); |
| 274 | static void xdrawcursor(void); | 275 | static void xdrawcursor(void); |
| 275 | static void xinit(void); | 276 | static void xinit(void); |
| 276 | static void xloadcols(void); | 277 | static void xloadcols(void); |
| @@ -1620,32 +1621,8 @@ tresize(int col, int row) { | |||
| 1620 | 1621 | ||
| 1621 | void | 1622 | void |
| 1622 | xresize(int col, int row) { | 1623 | xresize(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 | ||
| 1651 | void | 1628 | void |
| @@ -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 */ |
| 1873 | void | 1850 | void |
| 1874 | xcopy(int x, int y, int cols, int rows) { | 1851 | xcopy() { |
| 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 | ||
| 1880 | void | 1857 | void |
| @@ -1918,6 +1895,7 @@ xdrawcursor(void) { | |||
| 1918 | void | 1895 | void |
| 1919 | draw() { | 1896 | draw() { |
| 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 | |||
| 1968 | expose(XEvent *ev) { | 1945 | expose(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 | ||
| 1980 | void | 1954 | void |
