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(-)
static void xdraws(char *, Glyph, int, int, int, int);
static void xhints(void);
static void xclear(int, int, int, int);
static void xdraws(char *, Glyph, int, int, int, int);
static void xhints(void);
static void xclear(int, int, int, int);
-static void xcopy(void);
static void xdrawcursor(void);
static void xinit(void);
static void xloadcols(void);
static void xdrawcursor(void);
static void xinit(void);
static void xloadcols(void);
return;
sel.bx = -1;
tsetdirt(sel.b.y, sel.e.y);
return;
sel.bx = -1;
tsetdirt(sel.b.y, sel.e.y);
clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
XSetSelectionOwner(xw.dpy, clipboard, xw.win, CurrentTime);
clipboard = XInternAtom(xw.dpy, "CLIPBOARD", 0);
XSetSelectionOwner(xw.dpy, clipboard, xw.win, CurrentTime);
}
memcpy(&sel.tclick2, &sel.tclick1, sizeof(struct timeval));
gettimeofday(&sel.tclick1, NULL);
}
memcpy(&sel.tclick2, &sel.tclick1, sizeof(struct timeval));
gettimeofday(&sel.tclick1, NULL);
int starty = MIN(oldey, sel.ey);
int endy = MAX(oldey, sel.ey);
tsetdirt(starty, endy);
int starty = MIN(oldey, sel.ey);
int endy = MAX(oldey, sel.ey);
tsetdirt(starty, endy);
XDrawLine(xw.dpy, xw.buf, dc.gc, winx, winy+1, winx+width-1, winy+1);
}
XDrawLine(xw.dpy, xw.buf, dc.gc, winx, winy+1, winx+width-1, winy+1);
}
-/* copy buffer pixmap to screen pixmap */
-void
-xcopy() {
- XdbeSwapInfo swpinfo[1] = {{xw.win, XdbeCopied}};
- XdbeSwapBuffers(xw.dpy, swpinfo, 1);
-}
-
void
xdrawcursor(void) {
static int oldx = 0;
void
xdrawcursor(void) {
static int oldx = 0;
} else
xclear(oldx, oldy, oldx, oldy);
} else
xclear(oldx, oldy, oldx, oldy);
/* draw the new one */
if(!(term.c.state & CURSOR_HIDE)) {
if(!(xw.state & WIN_FOCUSED))
/* draw the new one */
if(!(term.c.state & CURSOR_HIDE)) {
if(!(xw.state & WIN_FOCUSED))
xdraws(g.c, g, term.c.x, term.c.y, 1, sl);
oldx = term.c.x, oldy = term.c.y;
}
xdraws(g.c, g, term.c.x, term.c.y, 1, sl);
oldx = term.c.x, oldy = term.c.y;
}
+ XdbeSwapInfo swpinfo[1] = {{xw.win, XdbeCopied}};
+
drawregion(0, 0, term.col, term.row);
drawregion(0, 0, term.col, term.row);
+ XdbeSwapBuffers(xw.dpy, swpinfo, 1);
if(!e->count)
xw.state &= ~WIN_REDRAW;
}
if(!e->count)
xw.state &= ~WIN_REDRAW;
}
xseturgency(0);
} else
xw.state &= ~WIN_FOCUSED;
xseturgency(0);
} else
xw.state &= ~WIN_FOCUSED;
} else if(e->xclient.data.l[1] == XEMBED_FOCUS_OUT) {
xw.state &= ~WIN_FOCUSED;
}
} else if(e->xclient.data.l[1] == XEMBED_FOCUS_OUT) {
xw.state &= ~WIN_FOCUSED;
}
if(FD_ISSET(cmdfd, &rfd))
ttyread();
if(FD_ISSET(cmdfd, &rfd))
ttyread();
while(XPending(xw.dpy)) {
XNextEvent(xw.dpy, &ev);
if(XFilterEvent(&ev, xw.win))
while(XPending(xw.dpy)) {
XNextEvent(xw.dpy, &ev);
if(XFilterEvent(&ev, xw.win))
if(handler[ev.type])
(handler[ev.type])(&ev);
}
if(handler[ev.type])
(handler[ev.type])(&ev);
}
+
+ draw();
+ XFlush(xw.dpy);