Quickly swap out of loop to reduce indentation needed.
Reuse deltatime variable to reuse calculation.
---
 x.c | 56 +++++++++++++++++++++++++-------------------------------
 1 file changed, 25 insertions(+), 31 deletions(-)

diff --git a/x.c b/x.c
index 76fa689..5f879fa 100644
--- a/x.c
+++ b/x.c
@@ -1928,41 +1928,35 @@ run(void)
                }
                deltatime = TIMEDIFF(now, last);
                if (deltatime > 1000 / (xev ? xfps : actionfps)) {
-                       dodraw = 1;
                        last = now;
+                       dodraw = 1;
                }
 
-               if (dodraw) {
-                       while (XPending(xw.dpy)) {
-                               XNextEvent(xw.dpy, &ev);
-                               if (XFilterEvent(&ev, None))
-                                       continue;
-                               if (handler[ev.type])
-                                       (handler[ev.type])(&ev);
-                       }
+               if (!dodraw)
+                       continue;
+               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);
-
-                       if (xev && !FD_ISSET(xfd, &rfd))
-                               xev--;
-                       if (!FD_ISSET(ttyfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
-                               if (blinkset) {
-                                       if (TIMEDIFF(now, lastblink) \
-                                                       > blinktimeout) {
-                                               drawtimeout.tv_nsec = 1000;
-                                       } else {
-                                               drawtimeout.tv_nsec = (1E6 * \
-                                                       (blinktimeout - \
-                                                       TIMEDIFF(now,
-                                                               lastblink)));
-                                       }
-                                       drawtimeout.tv_sec = \
-                                           drawtimeout.tv_nsec / 1E9;
-                                       drawtimeout.tv_nsec %= (long)1E9;
-                               } else {
-                                       tv = NULL;
-                               }
+               draw();
+               XFlush(xw.dpy);
+
+               if (xev && !FD_ISSET(xfd, &rfd))
+                       xev--;
+               if (!FD_ISSET(ttyfd, &rfd) && !FD_ISSET(xfd, &rfd)) {
+                       if (blinkset) {
+                               deltatime = TIMEDIFF(now, lastblink);
+                               drawtimeout.tv_nsec = deltatime > blinktimeout
+                                       ? 1000
+                                       : 1E6 * (blinktimeout - deltatime);
+                               drawtimeout.tv_sec = drawtimeout.tv_nsec / 1E9;
+                               drawtimeout.tv_nsec %= (long)1E9;
+                       } else {
+                               tv = NULL;
                        }
                }
        }
-- 
2.25.0


Reply via email to