diff options
Diffstat (limited to 'main.c')
-rw-r--r-- | main.c | 68 |
1 files changed, 40 insertions, 28 deletions
@@ -69,11 +69,10 @@ void cleanup() { } } -int load_image(int new) { +int load_image() { struct stat fstats; img_close(&img); - fileidx = new; if (!stat(filenames[fileidx], &fstats)) filesize = fstats.st_size; @@ -141,7 +140,7 @@ int main(int argc, char **argv) { } else { mode = MODE_NORMAL; tns.thumbs = NULL; - load_image(fileidx); + load_image(); img_render(&img, &win); } @@ -308,29 +307,41 @@ void on_keypress(XKeyEvent *kev) { /* navigate image list */ case XK_n: case XK_space: - if (fileidx + 1 < filecnt) - changed = load_image(fileidx + 1); + if (fileidx + 1 < filecnt) { + ++fileidx; + changed = load_image(); + } break; case XK_p: case XK_BackSpace: - if (fileidx > 0) - changed = load_image(fileidx - 1); + if (fileidx > 0) { + --fileidx; + changed = load_image(); + } break; case XK_bracketleft: - if (fileidx != 0) - changed = load_image(MAX(0, fileidx - 10)); + if (fileidx != 0) { + fileidx = MAX(0, fileidx - 10); + changed = load_image(); + } break; case XK_bracketright: - if (fileidx != filecnt - 1) - changed = load_image(MIN(fileidx + 10, filecnt - 1)); + if (fileidx != filecnt - 1) { + fileidx = MIN(fileidx + 10, filecnt - 1); + changed = load_image(); + } break; case XK_g: - if (fileidx != 0) - changed = load_image(0); + if (fileidx != 0) { + fileidx = 0; + changed = load_image(); + } break; case XK_G: - if (fileidx != filecnt - 1) - changed = load_image(filecnt - 1); + if (fileidx != filecnt - 1) { + fileidx = filecnt - 1; + changed = load_image(); + } break; /* zooming */ @@ -407,11 +418,7 @@ void on_keypress(XKeyEvent *kev) { changed = 1; break; case XK_r: - changed = load_image(fileidx); - break; - case XK_S: - if (img_save(&img)) - tns_load(&tns, &win, fileidx, filenames[fileidx]); + changed = load_image(); break; } } else { @@ -419,7 +426,8 @@ void on_keypress(XKeyEvent *kev) { switch (ksym) { /* open selected image */ case XK_Return: - load_image(tns.sel); + fileidx = tns.sel; + load_image(); mode = MODE_NORMAL; win_set_cursor(&win, CURSOR_NONE); changed = 1; @@ -488,8 +496,10 @@ void on_buttonpress(XButtonEvent *bev) { if (mode == MODE_NORMAL) { switch (bev->button) { case Button1: - if (fileidx + 1 < filecnt) - changed = load_image(fileidx + 1); + if (fileidx + 1 < filecnt) { + ++fileidx; + changed = load_image(); + } break; case Button2: mox = bev->x; @@ -499,8 +509,10 @@ void on_buttonpress(XButtonEvent *bev) { drag = 1; break; case Button3: - if (fileidx > 0) - changed = load_image(fileidx - 1); + if (fileidx > 0) { + --fileidx; + changed = load_image(); + } break; case Button4: if (mask == ControlMask) @@ -531,7 +543,8 @@ void on_buttonpress(XButtonEvent *bev) { case Button1: if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) { if (sel == tns.sel) { - load_image(tns.sel); + fileidx = tns.sel; + load_image(); mode = MODE_NORMAL; timo_cursor = TO_CURSOR_HIDE; } else { @@ -587,8 +600,7 @@ void run() { gettimeofday(&t0, 0); while (!XPending(win.env.dpy) && tns.cnt < filecnt) { - /* tns.cnt is increased inside tns_load */ - tns_load(&tns, &win, tns.cnt, filenames[tns.cnt]); + tns_load(&tns, &win, filenames[tns.cnt]); gettimeofday(&t1, 0); if (TV_TO_DOUBLE(t1) - TV_TO_DOUBLE(t0) >= 0.25) break; |