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-patched-086cd61511aa5ca4cbef0048137bb9ae0467d283.tar.bz2 st-patched-086cd61511aa5ca4cbef0048137bb9ae0467d283.tar.xz st-patched-086cd61511aa5ca4cbef0048137bb9ae0467d283.zip |
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; | |||
14 | static unsigned int tripleclicktimeout = 600; | 14 | static unsigned int tripleclicktimeout = 600; |
15 | 15 | ||
16 | /* frames per second st should at maximum draw to the screen */ | 16 | /* frames per second st should at maximum draw to the screen */ |
17 | static unsigned int framespersecond = 60; | 17 | static unsigned int xfps = 30; |
18 | static unsigned int actionfps = 5; | ||
18 | 19 | ||
19 | /* TERM value */ | 20 | /* TERM value */ |
20 | static char termname[] = "st-256color"; | 21 | static char termname[] = "st-256color"; |
@@ -3166,12 +3166,12 @@ void | |||
3166 | run(void) { | 3166 | run(void) { |
3167 | XEvent ev; | 3167 | XEvent ev; |
3168 | fd_set rfd; | 3168 | fd_set rfd; |
3169 | int xfd = XConnectionNumber(xw.dpy); | 3169 | int xfd = XConnectionNumber(xw.dpy), xev; |
3170 | struct timeval drawtimeout, *tv = NULL, now, last; | 3170 | struct timeval drawtimeout, *tv = NULL, now, last; |
3171 | 3171 | ||
3172 | gettimeofday(&last, NULL); | 3172 | gettimeofday(&last, NULL); |
3173 | 3173 | ||
3174 | for(;;) { | 3174 | for(xev = actionfps;;) { |
3175 | FD_ZERO(&rfd); | 3175 | FD_ZERO(&rfd); |
3176 | FD_SET(cmdfd, &rfd); | 3176 | FD_SET(cmdfd, &rfd); |
3177 | FD_SET(xfd, &rfd); | 3177 | FD_SET(xfd, &rfd); |
@@ -3184,22 +3184,16 @@ run(void) { | |||
3184 | gettimeofday(&now, NULL); | 3184 | gettimeofday(&now, NULL); |
3185 | /* usecs until (next) frame */ | 3185 | /* usecs until (next) frame */ |
3186 | drawtimeout.tv_sec = 0; | 3186 | drawtimeout.tv_sec = 0; |
3187 | drawtimeout.tv_usec = \ | 3187 | drawtimeout.tv_usec = (1000/xfps) * 1000; |
3188 | ((1000/framespersecond) - TIMEDIFF(now, last)) * 1000; | 3188 | tv = &drawtimeout; |
3189 | |||
3190 | /* Let us draw a frame. */ | ||
3191 | if(drawtimeout.tv_usec <= 0) { | ||
3192 | draw(); | ||
3193 | XFlush(xw.dpy); | ||
3194 | |||
3195 | last = now; | ||
3196 | tv = NULL; | ||
3197 | } | ||
3198 | 3189 | ||
3199 | if(FD_ISSET(cmdfd, &rfd)) | 3190 | if(FD_ISSET(cmdfd, &rfd)) |
3200 | ttyread(); | 3191 | ttyread(); |
3201 | 3192 | ||
3202 | if(FD_ISSET(xfd, &rfd)) { | 3193 | if(FD_ISSET(xfd, &rfd)) |
3194 | xev = actionfps; | ||
3195 | |||
3196 | if(TIMEDIFF(now, last) > (xev ? (1000/xfps) : (1000/actionfps))) { | ||
3203 | while(XPending(xw.dpy)) { | 3197 | while(XPending(xw.dpy)) { |
3204 | XNextEvent(xw.dpy, &ev); | 3198 | XNextEvent(xw.dpy, &ev); |
3205 | if(XFilterEvent(&ev, None)) | 3199 | if(XFilterEvent(&ev, None)) |
@@ -3208,16 +3202,14 @@ run(void) { | |||
3208 | (handler[ev.type])(&ev); | 3202 | (handler[ev.type])(&ev); |
3209 | } | 3203 | } |
3210 | 3204 | ||
3211 | if(drawtimeout.tv_usec <= 0) { | 3205 | draw(); |
3212 | draw(); | 3206 | XFlush(xw.dpy); |
3213 | XFlush(xw.dpy); | 3207 | last = now; |
3214 | } | ||
3215 | } | ||
3216 | 3208 | ||
3217 | /* There is still some time to wait until next frame. */ | 3209 | if(xev && !FD_ISSET(xfd, &rfd)) |
3218 | if(drawtimeout.tv_usec > 0) { | 3210 | xev--; |
3219 | tv = &drawtimeout; | 3211 | if(!FD_ISSET(cmdfd, &rfd) && !FD_ISSET(xfd, &rfd)) |
3220 | continue; | 3212 | tv = NULL; |
3221 | } | 3213 | } |
3222 | } | 3214 | } |
3223 | } | 3215 | } |