Adding a more efficient drawing code.
Thanks Mihail Zenkov <mihail.zenkov@gmail.com> for giving the hint!
This commit is contained in:
parent
b7261c84aa
commit
95033753be
|
@ -9,10 +9,13 @@ static char font[] = "Liberation Mono:pixelsize=12:antialias=false:autohint=fals
|
||||||
static int borderpx = 2;
|
static int borderpx = 2;
|
||||||
static char shell[] = "/bin/sh";
|
static char shell[] = "/bin/sh";
|
||||||
|
|
||||||
/* double-click timeout (in milliseconds) between clicks for selection */
|
/* timeouts (in milliseconds) */
|
||||||
static unsigned int doubleclicktimeout = 300;
|
static unsigned int doubleclicktimeout = 300;
|
||||||
static unsigned int tripleclicktimeout = 600;
|
static unsigned int tripleclicktimeout = 600;
|
||||||
|
|
||||||
|
/* frames per second st should at maximum draw to the screen */
|
||||||
|
static unsigned int framespersecond = 60;
|
||||||
|
|
||||||
/* TERM value */
|
/* TERM value */
|
||||||
static char termname[] = "st-256color";
|
static char termname[] = "st-256color";
|
||||||
|
|
||||||
|
|
65
st.c
65
st.c
|
@ -3166,10 +3166,12 @@ void
|
||||||
run(void) {
|
run(void) {
|
||||||
XEvent ev;
|
XEvent ev;
|
||||||
fd_set rfd;
|
fd_set rfd;
|
||||||
int xfd = XConnectionNumber(xw.dpy), i;
|
int xfd = XConnectionNumber(xw.dpy);
|
||||||
struct timeval drawtimeout, *tv = NULL;
|
struct timeval drawtimeout, *tv = NULL, now, last;
|
||||||
|
|
||||||
for(i = 0;; i++) {
|
gettimeofday(&last, NULL);
|
||||||
|
|
||||||
|
for(;;) {
|
||||||
FD_ZERO(&rfd);
|
FD_ZERO(&rfd);
|
||||||
FD_SET(cmdfd, &rfd);
|
FD_SET(cmdfd, &rfd);
|
||||||
FD_SET(xfd, &rfd);
|
FD_SET(xfd, &rfd);
|
||||||
|
@ -3179,35 +3181,44 @@ run(void) {
|
||||||
die("select failed: %s\n", SERRNO);
|
die("select failed: %s\n", SERRNO);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
gettimeofday(&now, NULL);
|
||||||
* Stop after a certain number of reads so the user does not
|
/* usecs until (next) frame */
|
||||||
* feel like the system is stuttering.
|
drawtimeout.tv_sec = 0;
|
||||||
*/
|
drawtimeout.tv_usec = \
|
||||||
if(i < 1000 && FD_ISSET(cmdfd, &rfd)) {
|
((1000/framespersecond) - TIMEDIFF(now, last)) * 1000;
|
||||||
|
|
||||||
|
/* Let us draw a frame. */
|
||||||
|
if(drawtimeout.tv_usec <= 0) {
|
||||||
|
draw();
|
||||||
|
XFlush(xw.dpy);
|
||||||
|
|
||||||
|
last = now;
|
||||||
|
tv = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(FD_ISSET(cmdfd, &rfd))
|
||||||
ttyread();
|
ttyread();
|
||||||
|
|
||||||
/*
|
if(FD_ISSET(xfd, &rfd)) {
|
||||||
* Just wait a bit so it isn't disturbing the
|
while(XPending(xw.dpy)) {
|
||||||
* user and the system is able to write something.
|
XNextEvent(xw.dpy, &ev);
|
||||||
*/
|
if(XFilterEvent(&ev, None))
|
||||||
drawtimeout.tv_sec = 0;
|
continue;
|
||||||
drawtimeout.tv_usec = 5;
|
if(handler[ev.type])
|
||||||
|
(handler[ev.type])(&ev);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(drawtimeout.tv_usec <= 0) {
|
||||||
|
draw();
|
||||||
|
XFlush(xw.dpy);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* There is still some time to wait until next frame. */
|
||||||
|
if(drawtimeout.tv_usec > 0) {
|
||||||
tv = &drawtimeout;
|
tv = &drawtimeout;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
i = 0;
|
|
||||||
tv = NULL;
|
|
||||||
|
|
||||||
while(XPending(xw.dpy)) {
|
|
||||||
XNextEvent(xw.dpy, &ev);
|
|
||||||
if(XFilterEvent(&ev, None))
|
|
||||||
continue;
|
|
||||||
if(handler[ev.type])
|
|
||||||
(handler[ev.type])(&ev);
|
|
||||||
}
|
|
||||||
|
|
||||||
draw();
|
|
||||||
XFlush(xw.dpy);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue