Krolyxon
Commit 5fce009

Branches

Refs →

nsxiv5fce009

Refactored main loop; properly fixes startup issue

Author
Bert Münnich
Date
2014-09-26 22:45 +0200
Committer
Bert Münnich · 2014-09-26 22:47 +0200
Parent
c1e0843
Commit
5fce009b73d52320aeae17f7d5c22ca740784173

+27 −32

1 file changed

  1. M main.c +27 −32
M main.c View
@@ -668,41 +668,39 @@ void run(void)
668668 int xfd;
669669 fd_set fds;
670670 struct timeval timeout;
671− bool discard, to_set;
671+ bool discard, load_thumb, to_set;
672672 XEvent ev, nextev;
673673
674674 while (true) {
675− while (mode == MODE_THUMB && tns.loadnext < tns.end &&
676− XPending(win.env.dpy) == 0)
677− {
678− /* load thumbnails */
679− set_timeout(redraw, TO_REDRAW_THUMBS, false);
680− if (!tns_load(&tns, tns.loadnext, false)) {
681− remove_file(tns.loadnext, false);
682− tns.dirty = true;
683− }
684− while (tns.loadnext < tns.end && tns.thumbs[tns.loadnext].im != NULL)
685− tns.loadnext++;
686− if (tns.loadnext >= tns.end)
687− redraw();
688− else
689− check_timeouts(NULL);
690− }
675+ to_set = check_timeouts(&timeout);
676+ load_thumb = mode == MODE_THUMB && tns.loadnext < tns.end;
691677
692− while (XPending(win.env.dpy) == 0
693− && ((to_set = check_timeouts(&timeout)) || info.fd != -1))
678+ if ((load_thumb || to_set || info.fd != -1) &&
679+ XPending(win.env.dpy) == 0)
694680 {
695− /* check for timeouts & input */
696− xfd = ConnectionNumber(win.env.dpy);
697− FD_ZERO(&fds);
698− FD_SET(xfd, &fds);
699− if (info.fd != -1) {
700− FD_SET(info.fd, &fds);
701− xfd = MAX(xfd, info.fd);
681+ if (load_thumb) {
682+ set_timeout(redraw, TO_REDRAW_THUMBS, false);
683+ if (!tns_load(&tns, tns.loadnext, false)) {
684+ remove_file(tns.loadnext, false);
685+ tns.dirty = true;
686+ }
687+ while (tns.loadnext < tns.end && tns.thumbs[tns.loadnext].im != NULL)
688+ tns.loadnext++;
689+ if (tns.loadnext >= tns.end)
690+ redraw();
691+ } else {
692+ xfd = ConnectionNumber(win.env.dpy);
693+ FD_ZERO(&fds);
694+ FD_SET(xfd, &fds);
695+ if (info.fd != -1) {
696+ FD_SET(info.fd, &fds);
697+ xfd = MAX(xfd, info.fd);
698+ }
699+ select(xfd + 1, &fds, 0, 0, to_set ? &timeout : NULL);
700+ if (info.fd != -1 && FD_ISSET(info.fd, &fds))
701+ read_info();
702702 }
703− select(xfd + 1, &fds, 0, 0, to_set ? &timeout : NULL);
704− if (info.fd != -1 && FD_ISSET(info.fd, &fds))
705− read_info();
703+ continue;
706704 }
707705
708706 do {
@@ -882,9 +880,6 @@ int main(int argc, char **argv)
882880 win_open(&win);
883881 win_set_cursor(&win, CURSOR_WATCH);
884882
885− if (mode == MODE_THUMB)
886− tns_render(&tns);
887−
888883 set_timeout(redraw, 25, false);
889884
890885 run();