diff options
author | Christoph Lohmann <20h@r-36.net> | 2013-02-15 19:30:43 +0100 |
---|---|---|
committer | Christoph Lohmann <20h@r-36.net> | 2013-02-15 19:30:43 +0100 |
commit | 086cd61511aa5ca4cbef0048137bb9ae0467d283 (patch) | |
tree | 04e17ce948bac9cb69ea51356446cf710b09ed94 | |
parent | 95033753be32e93915ddce14ea41b8765b665771 (diff) | |
download | st-086cd61511aa5ca4cbef0048137bb9ae0467d283.tar.gz st-086cd61511aa5ca4cbef0048137bb9ae0467d283.tar.bz2 |
Doing it like the new run() was proposed.
-rw-r--r-- | config.def.h | 3 | ||||
-rw-r--r-- | st.c | 38 |
2 files changed, 17 insertions, 24 deletions
diff --git a/config.def.h b/config.def.h index 8732ca3..35e5cf9 100644 --- a/config.def.h +++ b/config.def.h @@ -14,7 +14,8 @@ static unsigned int doubleclicktimeout = 300; static unsigned int tripleclicktimeout = 600; /* frames per second st should at maximum draw to the screen */ -static unsigned int framespersecond = 60; +static unsigned int xfps = 30; +static unsigned int actionfps = 5; /* TERM value */ static char termname[] = "st-256color"; @@ -3166,12 +3166,12 @@ void run(void) { XEvent ev; fd_set rfd; - int xfd = XConnectionNumber(xw.dpy); + int xfd = XConnectionNumber(xw.dpy), xev; struct timeval drawtimeout, *tv = NULL, now, last; gettimeofday(&last, NULL); - for(;;) { + for(xev = actionfps;;) { FD_ZERO(&rfd); FD_SET(cmdfd, &rfd); FD_SET(xfd, &rfd); @@ -3184,22 +3184,16 @@ run(void) { gettimeofday(&now, NULL); /* usecs until (next) frame */ drawtimeout.tv_sec = 0; - drawtimeout.tv_usec = \ - ((1000/framespersecond) - TIMEDIFF(now, last)) * 1000; - - /* Let us draw a frame. */ - if(drawtimeout.tv_usec <= 0) { - draw(); - XFlush(xw.dpy); - - last = now; - tv = NULL; - } + drawtimeout.tv_usec = (1000/xfps) * 1000; + tv = &drawtimeout; if(FD_ISSET(cmdfd, &rfd)) ttyread(); - if(FD_ISSET(xfd, &rfd)) { + if(FD_ISSET(xfd, &rfd)) + xev = actionfps; + + if(TIMEDIFF(now, last) > (xev ? (1000/xfps) : (1000/actionfps))) { while(XPending(xw.dpy)) { XNextEvent(xw.dpy, &ev); if(XFilterEvent(&ev, None)) @@ -3208,16 +3202,14 @@ run(void) { (handler[ev.type])(&ev); } - if(drawtimeout.tv_usec <= 0) { - draw(); - XFlush(xw.dpy); - } - } + draw(); + XFlush(xw.dpy); + last = now; - /* There is still some time to wait until next frame. */ - if(drawtimeout.tv_usec > 0) { - tv = &drawtimeout; - continue; + if(xev && !FD_ISSET(xfd, &rfd)) + xev--; + if(!FD_ISSET(cmdfd, &rfd) && !FD_ISSET(xfd, &rfd)) + tv = NULL; } } } |