nsxiv802c344
Check file timestamps before loading from cache
+32 −17
4 files changed
| @@ -1,6 +1,6 @@ | |||
| 1 | 1 | all: sxiv | |
| 2 | 2 | ||
| 3 | − | VERSION=git-20110130 | |
| 3 | + | VERSION=git-20110131 | |
| 4 | 4 | ||
| 5 | 5 | CC?=gcc | |
| 6 | 6 | PREFIX?=/usr/local | |
| @@ -52,22 +52,41 @@ void img_free(img_t* img) { | |||
| 52 | 52 | imlib_free_image(); | |
| 53 | 53 | } | |
| 54 | 54 | ||
| 55 | + | int img_check(const char *filename) { | |
| 56 | + | Imlib_Image *im; | |
| 57 | + | ||
| 58 | + | if (!filename) | |
| 59 | + | return 0; | |
| 60 | + | ||
| 61 | + | if (!(im = imlib_load_image(filename))) { | |
| 62 | + | WARN("could not open image: %s", filename); | |
| 63 | + | return 0; | |
| 64 | + | } | |
| 65 | + | ||
| 66 | + | imlib_context_set_image(im); | |
| 67 | + | imlib_image_set_changes_on_disk(); | |
| 68 | + | imlib_free_image(); | |
| 69 | + | ||
| 70 | + | return 1; | |
| 71 | + | } | |
| 72 | + | ||
| 55 | 73 | int img_load(img_t *img, const char *filename) { | |
| 56 | 74 | Imlib_Image *im; | |
| 57 | 75 | ||
| 58 | 76 | if (!img || !filename) | |
| 59 | − | return -1; | |
| 77 | + | return 0; | |
| 60 | 78 | ||
| 61 | 79 | if (imlib_context_get_image()) | |
| 62 | 80 | imlib_free_image(); | |
| 63 | 81 | ||
| 64 | 82 | if (!(im = imlib_load_image(filename))) { | |
| 65 | 83 | WARN("could not open image: %s", filename); | |
| 66 | − | return -1; | |
| 84 | + | return 0; | |
| 67 | 85 | } | |
| 68 | 86 | ||
| 69 | 87 | imlib_context_set_image(im); | |
| 70 | 88 | imlib_context_set_anti_alias(img->aa); | |
| 89 | + | imlib_image_set_changes_on_disk(); | |
| 71 | 90 | ||
| 72 | 91 | img->re = 0; | |
| 73 | 92 | img->checkpan = 0; | |
| @@ -76,7 +95,7 @@ int img_load(img_t *img, const char *filename) { | |||
| 76 | 95 | img->w = imlib_image_get_width(); | |
| 77 | 96 | img->h = imlib_image_get_height(); | |
| 78 | 97 | ||
| 79 | − | return 0; | |
| 98 | + | return 1; | |
| 80 | 99 | } | |
| 81 | 100 | ||
| 82 | 101 | void img_check_pan(img_t *img, win_t *win) { | |
| @@ -49,7 +49,9 @@ typedef struct img_s { | |||
| 49 | 49 | void img_init(img_t*, win_t*); | |
| 50 | 50 | void img_free(img_t*); | |
| 51 | 51 | ||
| 52 | + | int img_check(const char*); | |
| 52 | 53 | int img_load(img_t*, const char*); | |
| 54 | + | ||
| 53 | 55 | void img_render(img_t*, win_t*); | |
| 54 | 56 | ||
| 55 | 57 | int img_fit(img_t*, win_t*); | |
| @@ -102,7 +102,7 @@ int main(int argc, char **argv) { | |||
| 102 | 102 | filecnt = 0; | |
| 103 | 103 | ||
| 104 | 104 | for (i = 0; i < options->filecnt; ++i) { | |
| 105 | − | if (!(img_load(&img, options->filenames[i]) < 0)) | |
| 105 | + | if (img_check(options->filenames[i])) | |
| 106 | 106 | filenames[filecnt++] = options->filenames[i]; | |
| 107 | 107 | } | |
| 108 | 108 | ||
| @@ -157,43 +157,37 @@ void on_keypress(XEvent *ev) { | |||
| 157 | 157 | case XK_n: | |
| 158 | 158 | case XK_space: | |
| 159 | 159 | if (fileidx + 1 < filecnt) { | |
| 160 | − | img_load(&img, filenames[++fileidx]); | |
| 161 | − | changed = 1; | |
| 160 | + | changed = img_load(&img, filenames[++fileidx]); | |
| 162 | 161 | } | |
| 163 | 162 | break; | |
| 164 | 163 | case XK_p: | |
| 165 | 164 | case XK_BackSpace: | |
| 166 | 165 | if (fileidx > 0) { | |
| 167 | − | img_load(&img, filenames[--fileidx]); | |
| 168 | − | changed = 1; | |
| 166 | + | changed = img_load(&img, filenames[--fileidx]); | |
| 169 | 167 | } | |
| 170 | 168 | break; | |
| 171 | 169 | case XK_bracketleft: | |
| 172 | 170 | if (fileidx != 0) { | |
| 173 | 171 | fileidx = MAX(0, fileidx - 10); | |
| 174 | − | img_load(&img, filenames[fileidx]); | |
| 175 | − | changed = 1; | |
| 172 | + | changed = img_load(&img, filenames[fileidx]); | |
| 176 | 173 | } | |
| 177 | 174 | break; | |
| 178 | 175 | case XK_bracketright: | |
| 179 | 176 | if (fileidx != filecnt - 1) { | |
| 180 | 177 | fileidx = MIN(fileidx + 10, filecnt - 1); | |
| 181 | − | img_load(&img, filenames[fileidx]); | |
| 182 | − | changed = 1; | |
| 178 | + | changed = img_load(&img, filenames[fileidx]); | |
| 183 | 179 | } | |
| 184 | 180 | break; | |
| 185 | 181 | case XK_g: | |
| 186 | 182 | if (fileidx != 0) { | |
| 187 | 183 | fileidx = 0; | |
| 188 | − | img_load(&img, filenames[fileidx]); | |
| 189 | − | changed = 1; | |
| 184 | + | changed = img_load(&img, filenames[fileidx]); | |
| 190 | 185 | } | |
| 191 | 186 | break; | |
| 192 | 187 | case XK_G: | |
| 193 | 188 | if (fileidx != filecnt - 1) { | |
| 194 | 189 | fileidx = filecnt - 1; | |
| 195 | − | img_load(&img, filenames[fileidx]); | |
| 196 | − | changed = 1; | |
| 190 | + | changed = img_load(&img, filenames[fileidx]); | |
| 197 | 191 | } | |
| 198 | 192 | break; | |
| 199 | 193 | ||