X-Git-Url: https://git.danieliu.xyz/?a=blobdiff_plain;f=st.c;h=108908721d2dab133753096e02c1b4b5ebec7b5a;hb=638a30359d26c1f84a87f0f8df17df1765068029;hp=16462c7c97e415ca8ae7d57ab2e69d434049f61e;hpb=6f87a39444166674daa94860d365e72343e0b882;p=st.git diff --git a/st.c b/st.c index 16462c7..1089087 100644 --- a/st.c +++ b/st.c @@ -190,6 +190,7 @@ static void xdrawcursor(void); static void xinit(void); static void xloadcols(void); static void xseturgency(int); +static void xresize(int, int); static void expose(XEvent *); static void visibility(XEvent *); @@ -1168,6 +1169,8 @@ tputc(char c) { case '\r': tmoveto(0, term.c.y); break; + case '\f': + case '\v': case '\n': /* go to first col if the mode is set */ tnewline(IS_SET(MODE_CRLF)); @@ -1255,6 +1258,36 @@ tresize(int col, int row) { tsetscroll(0, row-1); } +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.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr)); + XCopyArea(xw.dis, xw.buf, newbuf, dc.gc, 0, 0, xw.bufw, xw.bufh, 0, 0); + XFreePixmap(xw.dis, xw.buf); + XSetForeground(xw.dis, dc.gc, dc.col[DefaultBG]); + if(xw.bufw > oldw) + XFillRectangle(xw.dis, 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.dis, xw.win, BORDER+xw.bufw, BORDER, + xw.w-xw.bufh-BORDER, BORDER+MIN(xw.bufh, oldh), + False); + if(xw.bufh > oldh) + XFillRectangle(xw.dis, newbuf, dc.gc, 0, oldh, + xw.bufw, xw.bufh-oldh); + else if(xw.bufh < oldh && (BORDER > 0 || xw.h > xw.bufh)) + XClearArea(xw.dis, xw.win, BORDER, BORDER+xw.bufh, + xw.w-2*BORDER, xw.h-xw.bufh-BORDER, + False); + xw.buf = newbuf; +} + void xloadcols(void) { int i, r, g, b; @@ -1613,16 +1646,13 @@ resize(XEvent *e) { xw.w = e->xconfigure.width; xw.h = e->xconfigure.height; - xw.bufw = xw.w - 2*BORDER; - xw.bufh = xw.h - 2*BORDER; - col = xw.bufw / xw.cw; - row = xw.bufh / xw.ch; + col = (xw.w - 2*BORDER) / xw.cw; + row = (xw.h - 2*BORDER) / xw.ch; + if(col == term.col && row == term.row) + return; tresize(col, row); ttyresize(col, row); - xw.bufh = MAX(1, xw.bufh); - xw.bufw = MAX(1, xw.bufw); - XFreePixmap(xw.dis, xw.buf); - xw.buf = XCreatePixmap(xw.dis, xw.win, xw.bufw, xw.bufh, XDefaultDepth(xw.dis, xw.scr)); + xresize(col, row); } void