Check file timestamps before loading from cache
This commit is contained in:
parent
16cc96eff5
commit
802c344879
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
||||
all: sxiv
|
||||
|
||||
VERSION=git-20110130
|
||||
VERSION=git-20110131
|
||||
|
||||
CC?=gcc
|
||||
PREFIX?=/usr/local
|
||||
|
25
image.c
25
image.c
@ -52,22 +52,41 @@ void img_free(img_t* img) {
|
||||
imlib_free_image();
|
||||
}
|
||||
|
||||
int img_check(const char *filename) {
|
||||
Imlib_Image *im;
|
||||
|
||||
if (!filename)
|
||||
return 0;
|
||||
|
||||
if (!(im = imlib_load_image(filename))) {
|
||||
WARN("could not open image: %s", filename);
|
||||
return 0;
|
||||
}
|
||||
|
||||
imlib_context_set_image(im);
|
||||
imlib_image_set_changes_on_disk();
|
||||
imlib_free_image();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int img_load(img_t *img, const char *filename) {
|
||||
Imlib_Image *im;
|
||||
|
||||
if (!img || !filename)
|
||||
return -1;
|
||||
return 0;
|
||||
|
||||
if (imlib_context_get_image())
|
||||
imlib_free_image();
|
||||
|
||||
if (!(im = imlib_load_image(filename))) {
|
||||
WARN("could not open image: %s", filename);
|
||||
return -1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
imlib_context_set_image(im);
|
||||
imlib_context_set_anti_alias(img->aa);
|
||||
imlib_image_set_changes_on_disk();
|
||||
|
||||
img->re = 0;
|
||||
img->checkpan = 0;
|
||||
@ -76,7 +95,7 @@ int img_load(img_t *img, const char *filename) {
|
||||
img->w = imlib_image_get_width();
|
||||
img->h = imlib_image_get_height();
|
||||
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void img_check_pan(img_t *img, win_t *win) {
|
||||
|
2
image.h
2
image.h
@ -49,7 +49,9 @@ typedef struct img_s {
|
||||
void img_init(img_t*, win_t*);
|
||||
void img_free(img_t*);
|
||||
|
||||
int img_check(const char*);
|
||||
int img_load(img_t*, const char*);
|
||||
|
||||
void img_render(img_t*, win_t*);
|
||||
|
||||
int img_fit(img_t*, win_t*);
|
||||
|
20
main.c
20
main.c
@ -102,7 +102,7 @@ int main(int argc, char **argv) {
|
||||
filecnt = 0;
|
||||
|
||||
for (i = 0; i < options->filecnt; ++i) {
|
||||
if (!(img_load(&img, options->filenames[i]) < 0))
|
||||
if (img_check(options->filenames[i]))
|
||||
filenames[filecnt++] = options->filenames[i];
|
||||
}
|
||||
|
||||
@ -157,43 +157,37 @@ void on_keypress(XEvent *ev) {
|
||||
case XK_n:
|
||||
case XK_space:
|
||||
if (fileidx + 1 < filecnt) {
|
||||
img_load(&img, filenames[++fileidx]);
|
||||
changed = 1;
|
||||
changed = img_load(&img, filenames[++fileidx]);
|
||||
}
|
||||
break;
|
||||
case XK_p:
|
||||
case XK_BackSpace:
|
||||
if (fileidx > 0) {
|
||||
img_load(&img, filenames[--fileidx]);
|
||||
changed = 1;
|
||||
changed = img_load(&img, filenames[--fileidx]);
|
||||
}
|
||||
break;
|
||||
case XK_bracketleft:
|
||||
if (fileidx != 0) {
|
||||
fileidx = MAX(0, fileidx - 10);
|
||||
img_load(&img, filenames[fileidx]);
|
||||
changed = 1;
|
||||
changed = img_load(&img, filenames[fileidx]);
|
||||
}
|
||||
break;
|
||||
case XK_bracketright:
|
||||
if (fileidx != filecnt - 1) {
|
||||
fileidx = MIN(fileidx + 10, filecnt - 1);
|
||||
img_load(&img, filenames[fileidx]);
|
||||
changed = 1;
|
||||
changed = img_load(&img, filenames[fileidx]);
|
||||
}
|
||||
break;
|
||||
case XK_g:
|
||||
if (fileidx != 0) {
|
||||
fileidx = 0;
|
||||
img_load(&img, filenames[fileidx]);
|
||||
changed = 1;
|
||||
changed = img_load(&img, filenames[fileidx]);
|
||||
}
|
||||
break;
|
||||
case XK_G:
|
||||
if (fileidx != filecnt - 1) {
|
||||
fileidx = filecnt - 1;
|
||||
img_load(&img, filenames[fileidx]);
|
||||
changed = 1;
|
||||
changed = img_load(&img, filenames[fileidx]);
|
||||
}
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user