diff options
author | Aurélien Aptel <aurelien.aptel@gmail.com> | 2010-10-16 17:13:22 +0200 |
---|---|---|
committer | Aurélien Aptel <aurelien.aptel@gmail.com> | 2010-10-16 17:13:22 +0200 |
commit | ce27e634910e10c470b2dcb2edcd20f05d25343b (patch) | |
tree | 9de651cd88e5cad8da295c07bfac67f133751503 /st.c | |
parent | 9e004846def39ee73eeb06ba9b1be0e389752441 (diff) | |
download | st-ce27e634910e10c470b2dcb2edcd20f05d25343b.tar.gz st-ce27e634910e10c470b2dcb2edcd20f05d25343b.zip |
redraw optimization.
Diffstat (limited to 'st.c')
-rw-r--r-- | st.c | 36 |
1 files changed, 24 insertions, 12 deletions
@@ -58,6 +58,7 @@ enum { GLYPH_SET=1, GLYPH_DIRTY=2 }; | |||
58 | enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8 }; | 58 | enum { MODE_WRAP=1, MODE_INSERT=2, MODE_APPKEYPAD=4, MODE_ALTSCREEN=8 }; |
59 | enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 }; | 59 | enum { ESC_START=1, ESC_CSI=2, ESC_OSC=4, ESC_TITLE=8, ESC_ALTCHARSET=16 }; |
60 | enum { SCREEN_UPDATE, SCREEN_REDRAW }; | 60 | enum { SCREEN_UPDATE, SCREEN_REDRAW }; |
61 | enum { WIN_VISIBLE=1, WIN_REDRAW=2, WIN_FOCUSED=4 }; | ||
61 | 62 | ||
62 | typedef struct { | 63 | typedef 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 | ||
124 | typedef struct { | 124 | typedef 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 | ||
1495 | void | 1494 | void |
1496 | expose(XEvent *ev) { | 1495 | expose(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 | ||
1500 | void | 1507 | void |
1501 | visibility(XEvent *ev) { | 1508 | visibility(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 | ||
1508 | void | 1517 | void |
1509 | unmap(XEvent *ev) { | 1518 | unmap(XEvent *ev) { |
1510 | xw.vis = 0; | 1519 | xw.state &= ~WIN_VISIBLE; |
1511 | } | 1520 | } |
1512 | 1521 | ||
1513 | void | 1522 | void |
@@ -1520,8 +1529,11 @@ xseturgency(int add) { | |||
1520 | 1529 | ||
1521 | void | 1530 | void |
1522 | focus(XEvent *ev) { | 1531 | focus(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 | ||