gib_list *feh_list_jump(gib_list * root, gib_list * l, int direction, int num) { int i; gib_list *ret = NULL; if (!root) return (NULL); if (!l) return (root); ret = l; for (i = 0; i < num; i++) { if (direction == FORWARD) { if (ret->next) { ret = ret->next; } else { if (opt.cycle_once) { exit(0); } ret = root; } } else { if (ret->prev) ret = ret->prev; else ret = gib_list_last(ret); } } return (ret); }
void cb_reload_timer(void *data) { gib_list *l; char *current_filename; winwidget w = (winwidget) data; /* save the current filename for refinding it in new list */ current_filename = estrdup(FEH_FILE(current_file->data)->filename); for (l = filelist; l; l = l->next) { feh_file_free(l->data); l->data = NULL; } gib_list_free_and_data(filelist); filelist = NULL; filelist_len = 0; current_file = NULL; /* rebuild filelist from original_file_items */ if (gib_list_length(original_file_items) > 0) for (l = gib_list_last(original_file_items); l; l = l->prev) add_file_to_filelist_recursively(l->data, FILELIST_FIRST); else if (!opt.filelistfile && !opt.bgmode) add_file_to_filelist_recursively(".", FILELIST_FIRST); if (!(filelist_len = gib_list_length(filelist))) { eprintf("No files found to reload."); } /* find the previously current file */ for (l = filelist; l; l = l->next) if (strcmp(FEH_FILE(l->data)->filename, current_filename) == 0) { current_file = l; break; } free(current_filename); filelist = gib_list_first(gib_list_reverse(filelist)); if (!current_file) current_file = filelist; w->file = current_file; /* reset window name in case of current file order, * filename, or filelist_length has changed. */ current_filename = slideshow_create_name(FEH_FILE(current_file->data), w); winwidget_rename(w, current_filename); free(current_filename); feh_reload_image(w, 1, 0); if (opt.reload) feh_add_unique_timer(cb_reload_timer, w, opt.reload); return; }
void gib_hash_set(gib_hash *hash, char *key, void *data) { gib_list *l; gib_hash_node *n; n = GIB_HASH_NODE(gib_list_find(GIB_LIST(hash->base), gib_hash_find_callback, key)); if (n) { GIB_LIST(n)->data = data; } else { /* not using gib_list_add_end here as that would nest the data one level, doing manual insert instead */ n = gib_hash_node_new(key,data); l = gib_list_last(GIB_LIST(hash->base)); GIB_LIST(n)->next = NULL; GIB_LIST(n)->prev = l; if (l) l->next = GIB_LIST(n); } }
gib_list *feh_list_jump(gib_list * root, gib_list * l, int direction, int num) { int i; gib_list *ret = NULL; if (!root) return (NULL); if (!l) return (root); ret = l; for (i = 0; i < num; i++) { if (direction == FORWARD) { if (ret->next) { ret = ret->next; } else { if (opt.cycle_once) { exit(0); } if (opt.randomize) { /* Randomize the filename order */ filelist = gib_list_randomize(filelist); ret = filelist; } else { ret = root; } } } else { if (ret->prev) ret = ret->prev; else ret = gib_list_last(ret); } } return (ret); }
void slideshow_change_image(winwidget winwid, int change, int render) { gib_list *last = NULL; int i = 0; int jmp = 1; /* We can't use filelist_len in the for loop, since that changes when we * encounter invalid images. */ int our_filelist_len = filelist_len; char *s; unsigned char tmode =0; int tim_x =0; int tim_y =0; double tzoom =0; /* Without this, clicking a one-image slideshow reloads it. Not very * intelligent behaviour :-) */ if (filelist_len < 2 && opt.cycle_once == 0) return; /* Ok. I do this in such an odd way to ensure that if the last or first * image is not loadable, it will go through in the right direction to * find the correct one. Otherwise SLIDE_LAST would try the last file, * then loop forward to find a loadable one. */ if (change == SLIDE_FIRST) { current_file = gib_list_last(filelist); change = SLIDE_NEXT; } else if (change == SLIDE_LAST) { current_file = filelist; change = SLIDE_PREV; } /* The for loop prevents us looping infinitely */ for (i = 0; i < our_filelist_len; i++) { winwidget_free_image(winwid); switch (change) { case SLIDE_NEXT: current_file = feh_list_jump(filelist, current_file, FORWARD, 1); break; case SLIDE_PREV: current_file = feh_list_jump(filelist, current_file, BACK, 1); break; case SLIDE_RAND: if (filelist_len > 1) { current_file = feh_list_jump(filelist, current_file, FORWARD, (rand() % (filelist_len - 1)) + 1); change = SLIDE_NEXT; } break; case SLIDE_JUMP_FWD: if (filelist_len < 5) jmp = 1; else if (filelist_len < 40) jmp = 2; else jmp = filelist_len / 20; if (!jmp) jmp = 2; current_file = feh_list_jump(filelist, current_file, FORWARD, jmp); /* important. if the load fails, we only want to step on ONCE to try the next file, not another jmp */ change = SLIDE_NEXT; break; case SLIDE_JUMP_BACK: if (filelist_len < 5) jmp = 1; else if (filelist_len < 40) jmp = 2; else jmp = filelist_len / 20; if (!jmp) jmp = 2; current_file = feh_list_jump(filelist, current_file, BACK, jmp); /* important. if the load fails, we only want to step back ONCE to try the previous file, not another jmp */ change = SLIDE_NEXT; break; default: eprintf("BUG!\n"); break; } if (last) { filelist = feh_file_remove_from_list(filelist, last); last = NULL; } if (opt.keep_zoom_vp) { /* pre loadimage - record settings */ tmode = winwid->mode; tim_x = winwid->im_x; tim_y = winwid->im_y; tzoom = winwid->zoom; } if ((winwidget_loadimage(winwid, FEH_FILE(current_file->data))) != 0) { winwid->mode = MODE_NORMAL; winwid->file = current_file; if ((winwid->im_w != gib_imlib_image_get_width(winwid->im)) || (winwid->im_h != gib_imlib_image_get_height(winwid->im))) winwid->had_resize = 1; winwidget_reset_image(winwid); winwid->im_w = gib_imlib_image_get_width(winwid->im); winwid->im_h = gib_imlib_image_get_height(winwid->im); if (opt.keep_zoom_vp) { /* put back in: */ winwid->mode = tmode; winwid->im_x = tim_x; winwid->im_y = tim_y; winwid->zoom = tzoom; } if (render) { if (opt.keep_zoom_vp) { winwidget_render_image(winwid, 0, 0); } else { winwidget_render_image(winwid, 1, 0); } } s = slideshow_create_name(FEH_FILE(current_file->data), winwid); winwidget_rename(winwid, s); free(s); break; } else last = current_file; } if (last) filelist = feh_file_remove_from_list(filelist, last); if (filelist_len == 0) eprintf("No more slides in show"); if (opt.slideshow_delay > 0.0) feh_add_timer(cb_slide_timer, winwid, opt.slideshow_delay, "SLIDE_CHANGE"); return; }
void slideshow_change_image(winwidget winwid, int change, int render) { gib_list *last = NULL; gib_list *previous_file = current_file; int i = 0; int jmp = 1; /* We can't use filelist_len in the for loop, since that changes when we * encounter invalid images. */ int our_filelist_len = filelist_len; if (opt.slideshow_delay > 0.0) feh_add_timer(cb_slide_timer, winwid, opt.slideshow_delay, "SLIDE_CHANGE"); /* Without this, clicking a one-image slideshow reloads it. Not very * intelligent behaviour :-) */ if (filelist_len < 2 && opt.on_last_slide != ON_LAST_SLIDE_QUIT) return; /* Ok. I do this in such an odd way to ensure that if the last or first * image is not loadable, it will go through in the right direction to * find the correct one. Otherwise SLIDE_LAST would try the last file, * then loop forward to find a loadable one. */ if (change == SLIDE_FIRST) { current_file = gib_list_last(filelist); change = SLIDE_NEXT; previous_file = NULL; } else if (change == SLIDE_LAST) { current_file = filelist; change = SLIDE_PREV; previous_file = NULL; } /* The for loop prevents us looping infinitely */ for (i = 0; i < our_filelist_len; i++) { winwidget_free_image(winwid); switch (change) { case SLIDE_NEXT: current_file = feh_list_jump(filelist, current_file, FORWARD, 1); break; case SLIDE_PREV: current_file = feh_list_jump(filelist, current_file, BACK, 1); break; case SLIDE_RAND: if (filelist_len > 1) { current_file = feh_list_jump(filelist, current_file, FORWARD, (random() % (filelist_len - 1)) + 1); change = SLIDE_NEXT; } break; case SLIDE_JUMP_FWD: if (filelist_len < 5) jmp = 1; else if (filelist_len < 40) jmp = 2; else jmp = filelist_len / 20; if (!jmp) jmp = 2; current_file = feh_list_jump(filelist, current_file, FORWARD, jmp); /* important. if the load fails, we only want to step on ONCE to try the next file, not another jmp */ change = SLIDE_NEXT; break; case SLIDE_JUMP_BACK: if (filelist_len < 5) jmp = 1; else if (filelist_len < 40) jmp = 2; else jmp = filelist_len / 20; if (!jmp) jmp = 2; current_file = feh_list_jump(filelist, current_file, BACK, jmp); /* important. if the load fails, we only want to step back ONCE to try the previous file, not another jmp */ change = SLIDE_NEXT; break; case SLIDE_JUMP_NEXT_DIR: { char old_dir[PATH_MAX], new_dir[PATH_MAX]; int j; feh_file_dirname(old_dir, FEH_FILE(current_file->data), PATH_MAX); for (j = 0; j < our_filelist_len; j++) { current_file = feh_list_jump(filelist, current_file, FORWARD, 1); feh_file_dirname(new_dir, FEH_FILE(current_file->data), PATH_MAX); if (strcmp(old_dir, new_dir) != 0) break; } } change = SLIDE_NEXT; break; case SLIDE_JUMP_PREV_DIR: { char old_dir[PATH_MAX], new_dir[PATH_MAX]; int j; /* Start the search from the previous file in case we are on the first file of a directory */ current_file = feh_list_jump(filelist, current_file, BACK, 1); feh_file_dirname(old_dir, FEH_FILE(current_file->data), PATH_MAX); for (j = 0; j < our_filelist_len; j++) { current_file = feh_list_jump(filelist, current_file, BACK, 1); feh_file_dirname(new_dir, FEH_FILE(current_file->data), PATH_MAX); if (strcmp(old_dir, new_dir) != 0) break; } /* Next file is the first entry of prev_dir */ current_file = feh_list_jump(filelist, current_file, FORWARD, 1); } change = SLIDE_NEXT; break; default: eprintf("BUG!\n"); break; } if (last) { filelist = feh_file_remove_from_list(filelist, last); last = NULL; } if (opt.on_last_slide == ON_LAST_SLIDE_HOLD && previous_file && ((current_file == filelist && change == SLIDE_NEXT) || (previous_file == filelist && change == SLIDE_PREV))) { current_file = previous_file; } if (winwidget_loadimage(winwid, FEH_FILE(current_file->data))) { int w = gib_imlib_image_get_width(winwid->im); int h = gib_imlib_image_get_height(winwid->im); if (feh_should_ignore_image(winwid->im)) { last = current_file; continue; } winwid->mode = MODE_NORMAL; winwid->file = current_file; if ((winwid->im_w != w) || (winwid->im_h != h)) winwid->had_resize = 1; winwidget_reset_image(winwid); winwid->im_w = w; winwid->im_h = h; if (render) { winwidget_render_image(winwid, 1, 0); } break; } else last = current_file; } if (last) filelist = feh_file_remove_from_list(filelist, last); if (filelist_len == 0) eprintf("No more slides in show"); return; }