diff options
author | Christoph Lohmann <20h@r-36.net> | 2013-02-15 19:10:22 +0100 |
---|---|---|
committer | Christoph Lohmann <20h@r-36.net> | 2013-02-15 19:10:22 +0100 |
commit | 95033753be32e93915ddce14ea41b8765b665771 (patch) | |
tree | 5c4f36908a54eaff9db4b03d87df96401ddef245 | |
parent | b7261c84aa3af984d5a7e5f5239c4173255a215d (diff) | |
download | st-patched-95033753be32e93915ddce14ea41b8765b665771.tar.bz2 st-patched-95033753be32e93915ddce14ea41b8765b665771.tar.xz st-patched-95033753be32e93915ddce14ea41b8765b665771.zip |
Adding a more efficient drawing code.
Thanks Mihail Zenkov <mihail.zenkov@gmail.com> for giving the hint!
-rw-r--r-- | config.def.h | 5 | ||||
-rw-r--r-- | st.c | 65 |
2 files changed, 42 insertions, 28 deletions
diff --git a/config.def.h b/config.def.h index 684adf7..8732ca3 100644 --- a/config.def.h +++ b/config.def.h | |||
@@ -9,10 +9,13 @@ static char font[] = "Liberation Mono:pixelsize=12:antialias=false:autohint=fals | |||
9 | static int borderpx = 2; | 9 | static int borderpx = 2; |
10 | static char shell[] = "/bin/sh"; | 10 | static char shell[] = "/bin/sh"; |
11 | 11 | ||
12 | /* double-click timeout (in milliseconds) between clicks for selection */ | 12 | /* timeouts (in milliseconds) */ |
13 | static unsigned int doubleclicktimeout = 300; | 13 | 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 */ | ||
17 | static unsigned int framespersecond = 60; | ||
18 | |||
16 | /* TERM value */ | 19 | /* TERM value */ |
17 | static char termname[] = "st-256color"; | 20 | static char termname[] = "st-256color"; |
18 | 21 | ||
@@ -3166,10 +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), i; | 3169 | int xfd = XConnectionNumber(xw.dpy); |
3170 | struct timeval drawtimeout, *tv = NULL; | 3170 | struct timeval drawtimeout, *tv = NULL, now, last; |
3171 | 3171 | ||
3172 | for(i = 0;; i++) { | 3172 | gettimeofday(&last, NULL); |
3173 | |||
3174 | for(;;) { | ||
3173 | FD_ZERO(&rfd); | 3175 | FD_ZERO(&rfd); |
3174 | FD_SET(cmdfd, &rfd); | 3176 | FD_SET(cmdfd, &rfd); |
3175 | FD_SET(xfd, &rfd); | 3177 | FD_SET(xfd, &rfd); |
@@ -3179,35 +3181,44 @@ run(void) { | |||
3179 | die("select failed: %s\n", SERRNO); | 3181 | die("select failed: %s\n", SERRNO); |
3180 | } | 3182 | } |
3181 | 3183 | ||
3182 | /* | 3184 | gettimeofday(&now, NULL); |
3183 | * Stop after a certain number of reads so the user does not | 3185 | /* usecs until (next) frame */ |
3184 | * feel like the system is stuttering. | 3186 | drawtimeout.tv_sec = 0; |
3185 | */ | 3187 | drawtimeout.tv_usec = \ |
3186 | if(i < 1000 && FD_ISSET(cmdfd, &rfd)) { | 3188 | ((1000/framespersecond) - TIMEDIFF(now, last)) * 1000; |
3187 | ttyread(); | ||
3188 | 3189 | ||
3189 | /* | 3190 | /* Let us draw a frame. */ |
3190 | * Just wait a bit so it isn't disturbing the | 3191 | if(drawtimeout.tv_usec <= 0) { |
3191 | * user and the system is able to write something. | 3192 | draw(); |
3192 | */ | 3193 | XFlush(xw.dpy); |
3193 | drawtimeout.tv_sec = 0; | 3194 | |
3194 | drawtimeout.tv_usec = 5; | 3195 | last = now; |
3195 | tv = &drawtimeout; | 3196 | tv = NULL; |
3196 | continue; | ||
3197 | } | 3197 | } |
3198 | i = 0; | ||
3199 | tv = NULL; | ||
3200 | 3198 | ||
3201 | while(XPending(xw.dpy)) { | 3199 | if(FD_ISSET(cmdfd, &rfd)) |
3202 | XNextEvent(xw.dpy, &ev); | 3200 | ttyread(); |
3203 | if(XFilterEvent(&ev, None)) | 3201 | |
3204 | continue; | 3202 | if(FD_ISSET(xfd, &rfd)) { |
3205 | if(handler[ev.type]) | 3203 | while(XPending(xw.dpy)) { |
3206 | (handler[ev.type])(&ev); | 3204 | XNextEvent(xw.dpy, &ev); |
3205 | if(XFilterEvent(&ev, None)) | ||
3206 | continue; | ||
3207 | if(handler[ev.type]) | ||
3208 | (handler[ev.type])(&ev); | ||
3209 | } | ||
3210 | |||
3211 | if(drawtimeout.tv_usec <= 0) { | ||
3212 | draw(); | ||
3213 | XFlush(xw.dpy); | ||
3214 | } | ||
3207 | } | 3215 | } |
3208 | 3216 | ||
3209 | draw(); | 3217 | /* There is still some time to wait until next frame. */ |
3210 | XFlush(xw.dpy); | 3218 | if(drawtimeout.tv_usec > 0) { |
3219 | tv = &drawtimeout; | ||
3220 | continue; | ||
3221 | } | ||
3211 | } | 3222 | } |
3212 | } | 3223 | } |
3213 | 3224 | ||