aboutsummaryrefslogtreecommitdiffstats
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c71
1 files changed, 53 insertions, 18 deletions
diff --git a/main.c b/main.c
index bbbeb59..80d69b6 100644
--- a/main.c
+++ b/main.c
@@ -29,15 +29,23 @@
#include "image.h"
#include "options.h"
+#include "thumbs.h"
#include "util.h"
#include "window.h"
+typedef enum appmode_e {
+ MODE_NORMAL = 0,
+ MODE_THUMBS
+} appmode_t;
+
void update_title();
int check_append(const char*);
void read_dir_rec(const char*);
void run();
+appmode_t mode;
img_t img;
+tns_t tns;
win_t win;
#define DNAME_CNT 512
@@ -46,6 +54,8 @@ const char **filenames;
int filecnt, fileidx;
size_t filesize;
+int tns_loaded;
+
#define TITLE_LEN 256
char win_title[TITLE_LEN];
@@ -54,6 +64,7 @@ void cleanup() {
if (!in++) {
img_free(&img);
+ tns_free(&tns, &win);
win_close(&win);
}
}
@@ -119,12 +130,21 @@ int main(int argc, char **argv) {
win_open(&win);
img_init(&img, &win);
- load_image();
- img_render(&img, &win);
- update_title();
+ if (options->thumbnails) {
+ tns_loaded = 0;
+ tns_init(&tns, filecnt);
+ }
- run();
+ if (options->thumbnails == 2) {
+ mode = MODE_THUMBS;
+ } else {
+ mode = MODE_NORMAL;
+ load_image();
+ img_render(&img, &win);
+ }
+ update_title();
+ run();
cleanup();
return 0;
@@ -233,6 +253,15 @@ void read_dir_rec(const char *dirname) {
unsigned char timeout;
int mox, moy;
+void redraw() {
+ if (mode == MODE_NORMAL)
+ img_render(&img, &win);
+ else
+ tns_render(&tns, &win);
+ update_title();
+ timeout = 0;
+}
+
void on_keypress(XKeyEvent *kev) {
int x, y;
unsigned int w, h;
@@ -364,11 +393,8 @@ void on_keypress(XKeyEvent *kev) {
break;
}
- if (changed) {
- img_render(&img, &win);
- update_title();
- timeout = 0;
- }
+ if (changed)
+ redraw();
}
void on_buttonpress(XButtonEvent *bev) {
@@ -423,11 +449,8 @@ void on_buttonpress(XButtonEvent *bev) {
break;
}
- if (changed) {
- img_render(&img, &win);
- update_title();
- timeout = 0;
- }
+ if (changed)
+ redraw();
}
void on_motionnotify(XMotionEvent *mev) {
@@ -452,16 +475,27 @@ void run() {
timeout = 0;
while (1) {
- if (timeout) {
+ if (mode == MODE_THUMBS && tns_loaded < filecnt) {
+ win_set_cursor(&win, CURSOR_WATCH);
+ tns_load(&tns, &win, filenames[tns_loaded++]);
+ tns_render(&tns, &win);
+ if (tns_loaded == filecnt)
+ win_set_cursor(&win, CURSOR_ARROW);
+ else if (!XPending(win.env.dpy))
+ continue;
+ } else if (timeout) {
t.tv_sec = 0;
t.tv_usec = 75000;
xfd = ConnectionNumber(win.env.dpy);
FD_ZERO(&fds);
FD_SET(xfd, &fds);
-
+
if (!XPending(win.env.dpy) && !select(xfd + 1, &fds, 0, 0, &t)) {
- img_render(&img, &win);
timeout = 0;
+ if (mode == MODE_NORMAL)
+ img_render(&img, &win);
+ else
+ tns_render(&tns, &win);
}
}
@@ -482,8 +516,9 @@ void run() {
break;
case ConfigureNotify:
if (win_configure(&win, &ev.xconfigure)) {
- img.checkpan = 1;
timeout = 1;
+ if (mode == MODE_NORMAL)
+ img.checkpan = 1;
}
break;
case ClientMessage: