aboutsummaryrefslogtreecommitdiff
path: root/st.c
diff options
context:
space:
mode:
authorAurélien Aptel <aurelien.aptel@gmail.com>2010-10-16 17:13:22 +0200
committerAurélien Aptel <aurelien.aptel@gmail.com>2010-10-16 17:13:22 +0200
commitce27e634910e10c470b2dcb2edcd20f05d25343b (patch)
tree9de651cd88e5cad8da295c07bfac67f133751503 /st.c
parent9e004846def39ee73eeb06ba9b1be0e389752441 (diff)
downloadst-ce27e634910e10c470b2dcb2edcd20f05d25343b.tar.gz
st-ce27e634910e10c470b2dcb2edcd20f05d25343b.zip
redraw optimization.
Diffstat (limited to 'st.c')
-rw-r--r--st.c36
1 files changed, 24 insertions, 12 deletions
diff --git a/st.c b/st.c
index 0c6423a..4f17752 100644
--- a/st.c
+++ b/st.c
@@ -58,6 +58,7 @@ enum { GLYPH_SET=1, GLYPH_DIRTY=2 };
58enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8 }; 58enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8 };
59enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 }; 59enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 };
60enum { SCREEN_UPDATE, SCREEN_REDRAW }; 60enum { SCREEN_UPDATE, SCREEN_REDRAW };
61enum { WIN_VISIBLE=1, WIN_REDRAW=2, WIN_FOCUSED=4 };
61 62
62typedef struct { 63typedef struct {
63 char c; /* character code */ 64 char c; /* character code */
@@ -117,8 +118,7 @@ typedef struct {
117 int bufh; /* pixmap height */ 118 int bufh; /* pixmap height */
118 int ch; /* char height */ 119 int ch; /* char height */
119 int cw; /* char width */ 120 int cw; /* char width */
120 int focus; 121 char state; /* focus, redraw, visible */
121 int vis; /* is visible */
122} XWindow; 122} XWindow;
123 123
124typedef struct { 124typedef struct {
@@ -1166,7 +1166,7 @@ tputc(char c) {
1166 tnewline(); 1166 tnewline();
1167 break; 1167 break;
1168 case '\a': 1168 case '\a':
1169 if(!xw.focus) 1169 if(!(xw.state & WIN_FOCUSED))
1170 xseturgency(1); 1170 xseturgency(1);
1171 break; 1171 break;
1172 case '\033': 1172 case '\033':
@@ -1418,7 +1418,7 @@ xdrawcursor(void) {
1418 xclear(oldx, oldy, oldx, oldy); 1418 xclear(oldx, oldy, oldx, oldy);
1419 1419
1420 /* draw the new one */ 1420 /* draw the new one */
1421 if(!(term.c.state & CURSOR_HIDE) && xw.focus) { 1421 if(!(term.c.state & CURSOR_HIDE) && (xw.state & WIN_FOCUSED)) {
1422 xdraws(&g.c, g, term.c.x, term.c.y, 1); 1422 xdraws(&g.c, g, term.c.x, term.c.y, 1);
1423 oldx = term.c.x, oldy = term.c.y; 1423 oldx = term.c.x, oldy = term.c.y;
1424 } 1424 }
@@ -1458,7 +1458,7 @@ draw(int redraw_all) {
1458 Glyph base, new; 1458 Glyph base, new;
1459 char buf[DRAW_BUF_SIZ]; 1459 char buf[DRAW_BUF_SIZ];
1460 1460
1461 if(!xw.vis) 1461 if(!(xw.state & WIN_VISIBLE))
1462 return; 1462 return;
1463 1463
1464 xclear(0, 0, term.col-1, term.row-1); 1464 xclear(0, 0, term.col-1, term.row-1);
@@ -1487,27 +1487,36 @@ draw(int redraw_all) {
1487 } 1487 }
1488 xdrawcursor(); 1488 xdrawcursor();
1489 XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER); 1489 XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, 0, 0, xw.bufw, xw.bufh, BORDER, BORDER);
1490 XFlush(xw.dis);
1491} 1490}
1492 1491
1493#endif 1492#endif
1494 1493
1495void 1494void
1496expose(XEvent *ev) { 1495expose(XEvent *ev) {
1497 draw(SCREEN_REDRAW); 1496 XExposeEvent *e = &ev->xexpose;
1497 if(xw.state & WIN_REDRAW) {
1498 if(!e->count) {
1499 xw.state &= ~WIN_REDRAW;
1500 draw(SCREEN_REDRAW);
1501 }
1502 } else
1503 XCopyArea(xw.dis, xw.buf, xw.win, dc.gc, e->x-BORDER, e->y-BORDER,
1504 e->width, e->height, e->x, e->y);
1498} 1505}
1499 1506
1500void 1507void
1501visibility(XEvent *ev) { 1508visibility(XEvent *ev) {
1502 XVisibilityEvent *e = &ev->xvisibility; 1509 XVisibilityEvent *e = &ev->xvisibility;
1503 /* XXX if this goes from 0 to 1, need a full redraw for next Expose, 1510 if(e->state == VisibilityFullyObscured)
1504 * not just a buf copy */ 1511 xw.state &= ~WIN_VISIBLE;
1505 xw.vis = e->state != VisibilityFullyObscured; 1512 else if(!(xw.state & WIN_VISIBLE))
1513 /* need a full redraw for next Expose, not just a buf copy */
1514 xw.state |= WIN_VISIBLE | WIN_REDRAW;
1506} 1515}
1507 1516
1508void 1517void
1509unmap(XEvent *ev) { 1518unmap(XEvent *ev) {
1510 xw.vis = 0; 1519 xw.state &= ~WIN_VISIBLE;
1511} 1520}
1512 1521
1513void 1522void
@@ -1520,8 +1529,11 @@ xseturgency(int add) {
1520 1529
1521void 1530void
1522focus(XEvent *ev) { 1531focus(XEvent *ev) {
1523 if((xw.focus = ev->type == FocusIn)) 1532 if(ev->type == FocusIn) {
1533 xw.state |= WIN_FOCUSED;
1524 xseturgency(0); 1534 xseturgency(0);
1535 } else
1536 xw.state &= ~WIN_FOCUSED;
1525 draw(SCREEN_UPDATE); 1537 draw(SCREEN_UPDATE);
1526} 1538}
1527 1539