Refactored main loop; properly fixes startup issue

This commit is contained in:
Bert Münnich 2014-09-26 22:45:01 +02:00
parent c1e084357c
commit 5fce009b73
1 changed files with 27 additions and 32 deletions

23
main.c
View File

@ -668,14 +668,17 @@ void run(void)
int xfd; int xfd;
fd_set fds; fd_set fds;
struct timeval timeout; struct timeval timeout;
bool discard, to_set; bool discard, load_thumb, to_set;
XEvent ev, nextev; XEvent ev, nextev;
while (true) { while (true) {
while (mode == MODE_THUMB && tns.loadnext < tns.end && to_set = check_timeouts(&timeout);
load_thumb = mode == MODE_THUMB && tns.loadnext < tns.end;
if ((load_thumb || to_set || info.fd != -1) &&
XPending(win.env.dpy) == 0) XPending(win.env.dpy) == 0)
{ {
/* load thumbnails */ if (load_thumb) {
set_timeout(redraw, TO_REDRAW_THUMBS, false); set_timeout(redraw, TO_REDRAW_THUMBS, false);
if (!tns_load(&tns, tns.loadnext, false)) { if (!tns_load(&tns, tns.loadnext, false)) {
remove_file(tns.loadnext, false); remove_file(tns.loadnext, false);
@ -685,14 +688,7 @@ void run(void)
tns.loadnext++; tns.loadnext++;
if (tns.loadnext >= tns.end) if (tns.loadnext >= tns.end)
redraw(); redraw();
else } else {
check_timeouts(NULL);
}
while (XPending(win.env.dpy) == 0
&& ((to_set = check_timeouts(&timeout)) || info.fd != -1))
{
/* check for timeouts & input */
xfd = ConnectionNumber(win.env.dpy); xfd = ConnectionNumber(win.env.dpy);
FD_ZERO(&fds); FD_ZERO(&fds);
FD_SET(xfd, &fds); FD_SET(xfd, &fds);
@ -704,6 +700,8 @@ void run(void)
if (info.fd != -1 && FD_ISSET(info.fd, &fds)) if (info.fd != -1 && FD_ISSET(info.fd, &fds))
read_info(); read_info();
} }
continue;
}
do { do {
XNextEvent(win.env.dpy, &ev); XNextEvent(win.env.dpy, &ev);
@ -882,9 +880,6 @@ int main(int argc, char **argv)
win_open(&win); win_open(&win);
win_set_cursor(&win, CURSOR_WATCH); win_set_cursor(&win, CURSOR_WATCH);
if (mode == MODE_THUMB)
tns_render(&tns);
set_timeout(redraw, 25, false); set_timeout(redraw, 25, false);
run(); run();