aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRoberto E. Vargas Caballero <k0ga@shike2.com>2012-09-16 10:48:38 +0200
committerRoberto E. Vargas Caballero <k0ga@shike2.com>2012-09-16 10:48:38 +0200
commitc5a9b799d44be9c0fa4264dc34d9dd61321be795 (patch)
tree327a0f3e907db5dee0c7a678c5c701bc202e59fe
parent85849ce72aa4e9cee307a031b97777e9eba2d453 (diff)
downloadst-c5a9b799d44be9c0fa4264dc34d9dd61321be795.tar.gz
st-c5a9b799d44be9c0fa4264dc34d9dd61321be795.zip
Render only once in each main loop iteration
draw() runs over all lines of the screen and renders only the dirty lines, this avoids render lines which are not modified since last draw() call. In this moment the main loop is something like: - Wait something to read from file descriptors - Read from pseudo tty - Call draw() for rending - Read X events This cause the problem that all the X events that have to update the screen have to call draw() (because draw() is called before of X events handling), so you can have multiples renderings in only one iteration, that will waste a lot of resources. This patch change the main loop to: - Wait something to read from file descriptors - Read from pseudo tty - Read X events - Call draw() for rending So X events don't have to worry about rendering, because draw() is called after them. The only place where draw is called outside of the main loop is in redraw(), but it is necessary for getting a good tput flash. --- st.c | 29 ++++++----------------------- 1 file changed, 6 insertions(+), 23 deletions(-)
-rw-r--r--st.c29
1 files changed, 6 insertions, 23 deletions
diff --git a/st.c b/st.c
index d7ca875..397f6a6 100644
--- a/st.c
+++ b/st.c
@@ -288,7 +288,6 @@ static void ttywrite(const char *, size_t);
288static void xdraws(char *, Glyph, int, int, int, int); 288static void xdraws(char *, Glyph, int, int, int, int);
289static void xhints(void); 289static void xhints(void);
290static void xclear(int, int, int, int); 290static void xclear(int, int, int, int);
291static void xcopy(void);
292static void xdrawcursor(void); 291static void xdrawcursor(void);
293static void xinit(void); 292static void xinit(void);
294static void xloadcols(void); 293static void xloadcols(void);
@@ -635,7 +634,6 @@ void selclear(XEvent *e) {
635 return; 634 return;
636 sel.bx = -1; 635 sel.bx = -1;
637 tsetdirt(sel.b.y, sel.e.y); 636 tsetdirt(sel.b.y, sel.e.y);
638 draw();
639} 637}
640 638
641void 639void
@@ -685,8 +683,6 @@ xsetsel(char *str) {
685 683
686 clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0); 684 clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
687 XSetSelectionOwner(xw.dpy, clipboard, xw.win, CurrentTime); 685 XSetSelectionOwner(xw.dpy, clipboard, xw.win, CurrentTime);
688
689 XFlush(xw.dpy);
690} 686}
691 687
692void 688void
@@ -729,7 +725,6 @@ brelease(XEvent *e) {
729 } 725 }
730 memcpy(&sel.tclick2, &sel.tclick1, sizeof(struct timeval)); 726 memcpy(&sel.tclick2, &sel.tclick1, sizeof(struct timeval));
731 gettimeofday(&sel.tclick1, NULL); 727 gettimeofday(&sel.tclick1, NULL);
732 draw();
733} 728}
734 729
735void 730void
@@ -746,7 +741,6 @@ bmotion(XEvent *e) {
746 int starty = MIN(oldey, sel.ey); 741 int starty = MIN(oldey, sel.ey);
747 int endy = MAX(oldey, sel.ey); 742 int endy = MAX(oldey, sel.ey);
748 tsetdirt(starty, endy); 743 tsetdirt(starty, endy);
749 draw();
750 } 744 }
751 } 745 }
752} 746}
@@ -2091,13 +2085,6 @@ xdraws(char *s, Glyph base, int x, int y, int charlen, int bytelen) {
2091 XDrawLine(xw.dpy, xw.buf, dc.gc, winx, winy+1, winx+width-1, winy+1); 2085 XDrawLine(xw.dpy, xw.buf, dc.gc, winx, winy+1, winx+width-1, winy+1);
2092} 2086}
2093 2087
2094/* copy buffer pixmap to screen pixmap */
2095void
2096xcopy() {
2097 XdbeSwapInfo swpinfo[1] = {{xw.win, XdbeCopied}};
2098 XdbeSwapBuffers(xw.dpy, swpinfo, 1);
2099}
2100
2101void 2088void
2102xdrawcursor(void) { 2089xdrawcursor(void) {
2103 static int oldx = 0; 2090 static int oldx = 0;
@@ -2118,8 +2105,6 @@ xdrawcursor(void) {
2118 } else 2105 } else
2119 xclear(oldx, oldy, oldx, oldy); 2106 xclear(oldx, oldy, oldx, oldy);
2120 2107
2121 xcopy();
2122
2123 /* draw the new one */ 2108 /* draw the new one */
2124 if(!(term.c.state & CURSOR_HIDE)) { 2109 if(!(term.c.state & CURSOR_HIDE)) {
2125 if(!(xw.state & WIN_FOCUSED)) 2110 if(!(xw.state & WIN_FOCUSED))
@@ -2132,8 +2117,6 @@ xdrawcursor(void) {
2132 xdraws(g.c, g, term.c.x, term.c.y, 1, sl); 2117 xdraws(g.c, g, term.c.x, term.c.y, 1, sl);
2133 oldx = term.c.x, oldy = term.c.y; 2118 oldx = term.c.x, oldy = term.c.y;
2134 } 2119 }
2135
2136 xcopy();
2137} 2120}
2138 2121
2139void 2122void
@@ -2152,8 +2135,10 @@ redraw(void) {
2152 2135
2153void 2136void
2154draw() { 2137draw() {
2138 XdbeSwapInfo swpinfo[1] = {{xw.win, XdbeCopied}};
2139
2155 drawregion(0, 0, term.col, term.row); 2140 drawregion(0, 0, term.col, term.row);
2156 xcopy(); 2141 XdbeSwapBuffers(xw.dpy, swpinfo, 1);
2157} 2142}
2158 2143
2159void 2144void
@@ -2208,7 +2193,6 @@ expose(XEvent *ev) {
2208 if(!e->count) 2193 if(!e->count)
2209 xw.state &= ~WIN_REDRAW; 2194 xw.state &= ~WIN_REDRAW;
2210 } 2195 }
2211 xcopy();
2212} 2196}
2213 2197
2214void 2198void
@@ -2241,7 +2225,6 @@ focus(XEvent *ev) {
2241 xseturgency(0); 2225 xseturgency(0);
2242 } else 2226 } else
2243 xw.state &= ~WIN_FOCUSED; 2227 xw.state &= ~WIN_FOCUSED;
2244 draw();
2245} 2228}
2246 2229
2247char* 2230char*
@@ -2317,7 +2300,6 @@ cmessage(XEvent *e) {
2317 } else if(e->xclient.data.l[1] == XEMBED_FOCUS_OUT) { 2300 } else if(e->xclient.data.l[1] == XEMBED_FOCUS_OUT) {
2318 xw.state &= ~WIN_FOCUSED; 2301 xw.state &= ~WIN_FOCUSED;
2319 } 2302 }
2320 draw();
2321 } 2303 }
2322} 2304}
2323 2305
@@ -2358,8 +2340,6 @@ run(void) {
2358 if(FD_ISSET(cmdfd, &rfd)) 2340 if(FD_ISSET(cmdfd, &rfd))
2359 ttyread(); 2341 ttyread();
2360 2342
2361 draw();
2362
2363 while(XPending(xw.dpy)) { 2343 while(XPending(xw.dpy)) {
2364 XNextEvent(xw.dpy, &ev); 2344 XNextEvent(xw.dpy, &ev);
2365 if(XFilterEvent(&ev, xw.win)) 2345 if(XFilterEvent(&ev, xw.win))
@@ -2367,6 +2347,9 @@ run(void) {
2367 if(handler[ev.type]) 2347 if(handler[ev.type])
2368 (handler[ev.type])(&ev); 2348 (handler[ev.type])(&ev);
2369 } 2349 }
2350
2351 draw();
2352 XFlush(xw.dpy);
2370 } 2353 }
2371} 2354}
2372 2355