X-Git-Url: https://git.xinqibao.xyz/st.git/blobdiff_plain/cfea72c7b48261006079a327a9ce1adbe2bdc3e3..c6853fe18564437fe0a4cb06565a0a7d63d40b5a:/st.c?ds=inline diff --git a/st.c b/st.c index 4dc1c5a..4fc4d3d 100644 --- a/st.c +++ b/st.c @@ -24,6 +24,7 @@ #include #include #include +#include #if defined(__linux) #include @@ -178,15 +179,13 @@ typedef struct { Display* dpy; Colormap cmap; Window win; - Pixmap buf; + XdbeBackBuffer buf; Atom xembed; XIM xim; XIC xic; int scr; int w; /* window width */ int h; /* window height */ - int bufw; /* pixmap width */ - int bufh; /* pixmap height */ int ch; /* char height */ int cw; /* char width */ char state; /* focus, redraw, visible */ @@ -270,7 +269,7 @@ static void ttywrite(const char *, size_t); static void xdraws(char *, Glyph, int, int, int, int); static void xhints(void); static void xclear(int, int, int, int); -static void xcopy(int, int, int, int); +static void xcopy(); static void xdrawcursor(void); static void xinit(void); static void xloadcols(void); @@ -1620,32 +1619,8 @@ tresize(int col, int row) { void xresize(int col, int row) { - Pixmap newbuf; - int oldw, oldh; - - oldw = xw.bufw; - oldh = xw.bufh; - xw.bufw = MAX(1, col * xw.cw); - xw.bufh = MAX(1, row * xw.ch); - newbuf = XCreatePixmap(xw.dpy, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dpy, xw.scr)); - XCopyArea(xw.dpy, xw.buf, newbuf, dc.gc, 0, 0, xw.bufw, xw.bufh, 0, 0); - XFreePixmap(xw.dpy, xw.buf); - XSetForeground(xw.dpy, dc.gc, dc.col[DefaultBG]); - if(xw.bufw > oldw) - XFillRectangle(xw.dpy, newbuf, dc.gc, oldw, 0, - xw.bufw-oldw, MIN(xw.bufh, oldh)); - else if(xw.bufw < oldw && (BORDER > 0 || xw.w > xw.bufw)) - XClearArea(xw.dpy, xw.win, BORDER+xw.bufw, BORDER, - xw.w-xw.bufh-BORDER, BORDER+MIN(xw.bufh, oldh), - False); - if(xw.bufh > oldh) - XFillRectangle(xw.dpy, newbuf, dc.gc, 0, oldh, - xw.bufw, xw.bufh-oldh); - else if(xw.bufh < oldh && (BORDER > 0 || xw.h > xw.bufh)) - XClearArea(xw.dpy, xw.win, BORDER, BORDER+xw.bufh, - xw.w-2*BORDER, xw.h-xw.bufh-BORDER, - False); - xw.buf = newbuf; + xw.w = MAX(1, 2*BORDER + col * xw.cw); + xw.h = MAX(1, 2*BORDER + row * xw.ch); } void @@ -1694,7 +1669,7 @@ void xclear(int x1, int y1, int x2, int y2) { XSetForeground(xw.dpy, dc.gc, dc.col[IS_SET(MODE_REVERSE) ? DefaultFG : DefaultBG]); XFillRectangle(xw.dpy, xw.buf, dc.gc, - x1 * xw.cw, y1 * xw.ch, + BORDER + x1 * xw.cw, BORDER + y1 * xw.ch, (x2-x1+1) * xw.cw, (y2-y1+1) * xw.ch); } @@ -1780,10 +1755,8 @@ xinit(void) { xloadcols(); /* window - default size */ - xw.bufh = term.row * xw.ch; - xw.bufw = term.col * xw.cw; - xw.h = xw.bufh + 2*BORDER; - xw.w = xw.bufw + 2*BORDER; + xw.h = 2*BORDER + term.row * xw.ch; + xw.w = 2*BORDER + term.col * xw.cw; attrs.background_pixel = dc.col[DefaultBG]; attrs.border_pixel = dc.col[DefaultBG]; @@ -1801,7 +1774,7 @@ xinit(void) { CWBackPixel | CWBorderPixel | CWBitGravity | CWEventMask | CWColormap, &attrs); - xw.buf = XCreatePixmap(xw.dpy, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dpy, xw.scr)); + xw.buf = XdbeAllocateBackBufferName(xw.dpy, xw.win, XdbeCopied); /* input methods */ @@ -1830,7 +1803,7 @@ xinit(void) { void xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { int fg = base.fg, bg = base.bg, temp; - int winx = x*xw.cw, winy = y*xw.ch + dc.font.ascent, width = charlen*xw.cw; + int winx = BORDER+x*xw.cw, winy = BORDER+y*xw.ch + dc.font.ascent, width = charlen*xw.cw; XFontSet fontset = dc.font.set; int i; @@ -1871,10 +1844,10 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) { /* copy buffer pixmap to screen pixmap */ void -xcopy(int x, int y, int cols, int rows) { - int src_x = x*xw.cw, src_y = y*xw.ch, src_w = cols*xw.cw, src_h = rows*xw.ch; - int dst_x = BORDER+src_x, dst_y = BORDER+src_y; - XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, src_x, src_y, src_w, src_h, dst_x, dst_y); +xcopy() { + XdbeSwapInfo swpinfo[1] = {{xw.win, XdbeCopied}}; + XdbeSwapBuffers(xw.dpy, swpinfo, 1); + } void @@ -1918,6 +1891,7 @@ xdrawcursor(void) { void draw() { drawregion(0, 0, term.col, term.row); + xcopy(); gettimeofday(&xw.lastdraw, NULL); } @@ -1959,7 +1933,6 @@ drawregion(int x1, int y1, int x2, int y2) { } if(ib > 0) xdraws(buf, base, ox, y, ic, ib); - xcopy(0, y, term.col, 1); } xdrawcursor(); } @@ -1968,13 +1941,10 @@ void expose(XEvent *ev) { XExposeEvent *e = &ev->xexpose; if(xw.state & WIN_REDRAW) { - if(!e->count) { + if(!e->count) xw.state &= ~WIN_REDRAW; - xcopy(0, 0, term.col, term.row); - } - } else - XCopyArea(xw.dpy, xw.buf, xw.win, dc.gc, e->x-BORDER, e->y-BORDER, - e->width, e->height, e->x, e->y); + } + xcopy(); } void