Krolyxon
Commit b828b55

Branches

Refs →

nsxivb828b55

Immediately respond to events while loading thumbs

Author
Bert
Date
2011-02-17 14:13 +0100
Parent
e2889ab
Commit
b828b554191c761776e4757d1b92156c624c75f6

+20 −4

3 files changed

  1. M main.c +15 −4
  2. M thumbs.c +2 −0
  3. M util.h +3 −0
M main.c View
@@ -22,6 +22,7 @@
2222 #include <dirent.h>
2323 #include <sys/select.h>
2424 #include <sys/stat.h>
25+#include <sys/time.h>
2526
2627 #include <X11/Xlib.h>
2728 #include <X11/Xutil.h>
@@ -469,7 +470,7 @@ void on_motionnotify(XMotionEvent *mev) {
469470 void run() {
470471 int xfd;
471472 fd_set fds;
472− struct timeval t;
473+ struct timeval t, t0;
473474 XEvent ev;
474475
475476 timeout = 0;
@@ -477,12 +478,22 @@ void run() {
477478 while (1) {
478479 if (mode == MODE_THUMBS && tns_loaded < filecnt) {
479480 win_set_cursor(&win, CURSOR_WATCH);
480− tns_load(&tns, &win, filenames[tns_loaded++]);
481− tns_render(&tns, &win);
481+ gettimeofday(&t0, 0);
482+
483+ while (!XPending(win.env.dpy) && tns_loaded < filecnt) {
484+ tns_load(&tns, &win, filenames[tns_loaded++]);
485+ gettimeofday(&t, 0);
486+ if (TV_TO_DOUBLE(t) - TV_TO_DOUBLE(t0) >= 0.25)
487+ break;
488+ }
482489 if (tns_loaded == filecnt)
483490 win_set_cursor(&win, CURSOR_ARROW);
484− else if (!XPending(win.env.dpy))
491+ if (!XPending(win.env.dpy)) {
492+ tns_render(&tns, &win);
485493 continue;
494+ } else {
495+ timeout = 1;
496+ }
486497 } else if (timeout) {
487498 t.tv_sec = 0;
488499 t.tv_usec = 75000;
M thumbs.c View
@@ -84,6 +84,8 @@ void tns_render(tns_t *tns, win_t *win) {
8484
8585 if (!tns || !win)
8686 return;
87+
88+ printf("tns_render()\n");
8789
8890 tns->cols = win->w / thumb_dim;
8991 tns->rows = win->h / thumb_dim;
M util.h View
@@ -27,6 +27,9 @@
2727 #define MAX(a,b) ((a) > (b) ? (a) : (b))
2828 #define LEN(a) (sizeof(a) / sizeof(a[0]))
2929
30+#define TV_TO_DOUBLE(x) ((double) ((x).tv_sec) + 0.000001 * \
31+ (double) ((x).tv_usec))
32+
3033 void* s_malloc(size_t);
3134 void* s_realloc(void*, size_t);
3235