void feh_event_invoke_action(winwidget winwid, unsigned char action) { if (opt.actions[action]) { if (opt.slideshow) { feh_action_run(FEH_FILE(winwid->file->data), opt.actions[action]); if (opt.hold_actions[action]) feh_reload_image(winwid, 1, 1); else slideshow_change_image(winwid, SLIDE_NEXT, 1); } else if ((winwid->type == WIN_TYPE_SINGLE) || (winwid->type == WIN_TYPE_THUMBNAIL_VIEWER)) { feh_action_run(FEH_FILE(winwid->file->data), opt.actions[action]); if (opt.hold_actions[action]) feh_reload_image(winwid, 1, 1); else winwidget_destroy(winwid); } else if (winwid->type == WIN_TYPE_THUMBNAIL) { feh_file *thumbfile; thumbfile = feh_thumbnail_get_selected_file(); if (thumbfile) { feh_action_run(thumbfile, opt.actions[action]); if (!opt.hold_actions[action]) feh_thumbnail_mark_removed(thumbfile, 0); } } } return; }
void feh_draw_filename(winwidget w) { static Imlib_Font fn = NULL; int tw = 0, th = 0, nw = 0; Imlib_Image im = NULL; char *s = NULL; int len = 0; if ((!w->file) || (!FEH_FILE(w->file->data)) || (!FEH_FILE(w->file->data)->filename)) return; fn = feh_load_font(w); /* Work out how high the font is */ gib_imlib_get_text_size(fn, FEH_FILE(w->file->data)->filename, NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT); if (gib_list_length(filelist) > 1) { len = snprintf(NULL, 0, "%d of %d", gib_list_length(filelist), gib_list_length(filelist)) + 1; s = emalloc(len); if (w->file) snprintf(s, len, "%d of %d", gib_list_num(filelist, w->file) + 1, gib_list_length(filelist)); else snprintf(s, len, "%d of %d", gib_list_num(filelist, current_file) + 1, gib_list_length(filelist)); gib_imlib_get_text_size(fn, s, NULL, &nw, NULL, IMLIB_TEXT_TO_RIGHT); if (nw > tw) tw = nw; } tw += 3; th += 3; im = imlib_create_image(tw, 2 * th); if (!im) eprintf("Couldn't create image. Out of memory?"); feh_imlib_image_fill_text_bg(im, tw, 2 * th); gib_imlib_text_draw(im, fn, NULL, 2, 2, FEH_FILE(w->file->data)->filename, IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255); gib_imlib_text_draw(im, fn, NULL, 1, 1, FEH_FILE(w->file->data)->filename, IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); if (s) { gib_imlib_text_draw(im, fn, NULL, 2, th + 1, s, IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255); gib_imlib_text_draw(im, fn, NULL, 1, th, s, IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); free(s); } gib_imlib_render_image_on_drawable(w->bg_pmap, im, 0, 0, 1, 1, 0); gib_imlib_free_image_and_decache(im); return; }
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 feh_filelist_image_remove(winwidget winwid, char do_delete) { if (winwid->type == WIN_TYPE_SLIDESHOW) { char *s; gib_list *doomed; doomed = current_file; slideshow_change_image(winwid, SLIDE_NEXT, 0); if (do_delete) filelist = feh_file_rm_and_free(filelist, doomed); else filelist = feh_file_remove_from_list(filelist, doomed); if (!filelist) { /* No more images. Game over ;-) */ winwidget_destroy(winwid); return; } s = slideshow_create_name(FEH_FILE(winwid->file->data), winwid); winwidget_rename(winwid, s); free(s); winwidget_render_image(winwid, 1, 0); } else if ((winwid->type == WIN_TYPE_SINGLE) || (winwid->type == WIN_TYPE_THUMBNAIL_VIEWER)) { if (do_delete) filelist = feh_file_rm_and_free(filelist, winwid->file); else filelist = feh_file_remove_from_list(filelist, winwid->file); winwidget_destroy(winwid); } }
gib_list *feh_file_remove_from_list(gib_list * list, gib_list * l) { feh_file_free(FEH_FILE(l->data)); D(("filelist_len %d -> %d\n", filelist_len, filelist_len - 1)); filelist_len--; return(gib_list_remove(list, l)); }
static feh_menu *feh_menu_func_gen_info(feh_menu * m) { Imlib_Image im; feh_menu *mm; feh_file *file; char buffer[400]; if (!m->fehwin->file) return(NULL); file = FEH_FILE(m->fehwin->file->data); im = m->fehwin->im; if (!im) return(NULL); mm = feh_menu_new(); mm->name = estrdup("INFO"); snprintf(buffer, sizeof(buffer), "Filename: %s", file->name); feh_menu_add_entry(mm, buffer, NULL, NULL, 0, NULL, NULL); if (!file->info) feh_file_info_load(file, im); if (file->info) { snprintf(buffer, sizeof(buffer), "Size: %dKb", file->info->size / 1024); feh_menu_add_entry(mm, buffer, NULL, NULL, 0, NULL, NULL); snprintf(buffer, sizeof(buffer), "Dimensions: %dx%d", file->info->width, file->info->height); feh_menu_add_entry(mm, buffer, NULL, NULL, 0, NULL, NULL); snprintf(buffer, sizeof(buffer), "Type: %s", file->info->format); feh_menu_add_entry(mm, buffer, NULL, NULL, 0, NULL, NULL); } mm->func_free = feh_menu_func_free_info; return(mm); }
winwidget winwidget_create_from_file(gib_list * list, char *name, char type) { winwidget ret = NULL; feh_file *file = FEH_FILE(list->data); if (!file || !file->filename) return(NULL); ret = winwidget_allocate(); ret->file = list; ret->type = type; if (name) ret->name = estrdup(name); else ret->name = estrdup(file->filename); if (winwidget_loadimage(ret, file) == 0) { winwidget_destroy(ret); return(NULL); } if (!ret->win) { ret->w = ret->im_w = gib_imlib_image_get_width(ret->im); ret->h = ret->im_h = gib_imlib_image_get_height(ret->im); D(("image is %dx%d pixels, format %s\n", ret->w, ret->h, gib_imlib_image_format(ret->im))); if (opt.full_screen) ret->full_screen = True; winwidget_create_window(ret, ret->w, ret->h); winwidget_render_image(ret, 1, 0); } return(ret); }
void slideshow_save_image(winwidget win) { char *tmpname; Imlib_Load_Error err; if (win->file) { tmpname = feh_unique_filename("", FEH_FILE(win->file->data)->name); } else if (mode) { char *tmp; tmp = estrjoin(".", mode, "png", NULL); tmpname = feh_unique_filename("", tmp); free(tmp); } else { tmpname = feh_unique_filename("", "noname.png"); } if (opt.verbose) fprintf(stderr, "saving image to filename '%s'\n", tmpname); ungib_imlib_save_image_with_error_return(win->im, tmpname, &err); if (err) feh_imlib_print_load_error(tmpname, win, err); free(tmpname); return; }
gib_list *feh_file_info_preload(gib_list * list) { gib_list *l; feh_file *file = NULL; gib_list *remove_list = NULL; if (opt.verbose) fprintf(stdout, PACKAGE " - preloading...\n"); for (l = list; l; l = l->next) { file = FEH_FILE(l->data); D(5, ("file %p, file->next %p, file->name %s\n", l, l->next, file->name)); if (feh_file_info_load(file, NULL)) { D(3, ("Failed to load file %p\n", file)); remove_list = gib_list_add_front(remove_list, l); if (opt.verbose) feh_display_status('x'); } else if (opt.verbose) feh_display_status('.'); } if (opt.verbose) fprintf(stdout, "\n"); if (remove_list) { for (l = remove_list; l; l = l->next) filelist = list = gib_list_remove(list, (gib_list *) l->data); gib_list_free(remove_list); } return(list); }
void slideshow_save_image(winwidget win) { char *tmpname; Imlib_Load_Error err; if (win->file) { tmpname = feh_unique_filename("", FEH_FILE(win->file->data)->name); } else if (mode) { char *tmp; tmp = estrjoin(".", mode, "png", NULL); tmpname = feh_unique_filename("", tmp); free(tmp); } else { tmpname = feh_unique_filename("", "noname.png"); } if (opt.verbose) printf("saving image to filename '%s'\n", tmpname); /* XXX gib_imlib_save_image_with_error_return breaks with *.XXX and * similar because it tries to set the image format, which only works * with .xxx . * So we leave that part out. */ imlib_context_set_image(win->im); imlib_save_image_with_error_return(tmpname, &err); if (err) im_weprintf(win, "Can't save image %s:", tmpname); free(tmpname); return; }
void init_slideshow_mode(void) { winwidget w = NULL; int success = 0; char *s = NULL; gib_list *l = filelist, *last = NULL; feh_file *file = NULL; for (; l && opt.start_list_at; l = l->next) { if (!strcmp(opt.start_list_at, FEH_FILE(l->data)->filename)) { opt.start_list_at = NULL; break; } } if (opt.start_list_at) eprintf("--start-at %s: File not found in filelist", opt.start_list_at); mode = "slideshow"; for (; l; l = l->next) { file = FEH_FILE(l->data); if (last) { filelist = feh_file_remove_from_list(filelist, last); last = NULL; } current_file = l; s = slideshow_create_name(file, NULL); if ((w = winwidget_create_from_file(l, s, WIN_TYPE_SLIDESHOW)) != NULL) { free(s); success = 1; winwidget_show(w); if (opt.slideshow_delay > 0.0) feh_add_timer(cb_slide_timer, w, opt.slideshow_delay, "SLIDE_CHANGE"); if (opt.reload > 0) feh_add_unique_timer(cb_reload_timer, w, opt.reload); break; } else { free(s); last = l; } } if (!success) show_mini_usage(); return; }
void delete_rm_files(void) { gib_list *l; for (l = rm_filelist; l; l = l->next) unlink(FEH_FILE(l->data)->filename); return; }
void feh_event_invoke_action(winwidget winwid, char *action) { D_ENTER(4); D(4, ("action is '%s'\n", action)); D(4, ("winwid is '%p'\n", winwid)); if (action) { if (opt.slideshow) { feh_action_run(FEH_FILE(winwid->file->data), action); slideshow_change_image(winwid, SLIDE_NEXT); } else if ((winwid->type == WIN_TYPE_SINGLE) || (winwid->type == WIN_TYPE_THUMBNAIL_VIEWER)) { feh_action_run(FEH_FILE(winwid->file->data), action); winwidget_destroy(winwid); } else if (winwid->type == WIN_TYPE_THUMBNAIL) { printf("actions from the main thumb window aren't currentl supported!\n"); printf("For now, open the image to perform the action on it.\n"); } } D_RETURN_(4); }
void feh_edit_inplace(winwidget w, int op) { int tmp; Imlib_Image old = NULL; Imlib_Load_Error err = IMLIB_LOAD_ERROR_NONE; if (!w->file || !w->file->data || !FEH_FILE(w->file->data)->filename) return; if (!strcmp(gib_imlib_image_format(w->im), "jpeg") && !path_is_url(FEH_FILE(w->file->data)->filename)) { feh_edit_inplace_lossless(w, op); feh_reload_image(w, 1, 1); return; } old = imlib_load_image_with_error_return(FEH_FILE(w->file->data)->filename, &err); if ((old != NULL) && (err == IMLIB_LOAD_ERROR_NONE)) { imlib_context_set_image(old); if (op == INPLACE_EDIT_FLIP) imlib_image_flip_vertical(); else if (op == INPLACE_EDIT_MIRROR) imlib_image_flip_horizontal(); else imlib_image_orientate(op); gib_imlib_save_image_with_error_return(old, FEH_FILE(w->file->data)->filename, &err); gib_imlib_free_image(old); if (err) feh_imlib_print_load_error(FEH_FILE(w->file->data)->filename, w, err); feh_reload_image(w, 1, 1); } else { /* * Image was opened using curl/magick or has been deleted after * opening it */ imlib_context_set_image(w->im); if (op == INPLACE_EDIT_FLIP) imlib_image_flip_vertical(); else if (op == INPLACE_EDIT_MIRROR) imlib_image_flip_horizontal(); else { imlib_image_orientate(op); tmp = w->im_w; FEH_FILE(w->file->data)->info->width = w->im_w = w->im_h; FEH_FILE(w->file->data)->info->height = w->im_h = tmp; } im_weprintf(w, "unable to edit in place. Changes have not been saved."); winwidget_render_image(w, 1, 0); } return; }
void feh_edit_inplace(winwidget w, int op) { int ret; Imlib_Image old; Imlib_Load_Error err; if (!w->file || !w->file->data || !FEH_FILE(w->file->data)->filename) return; if (!strcmp(gib_imlib_image_format(w->im), "jpeg")) { feh_edit_inplace_lossless(w, op); feh_reload_image(w, 1, 1); return; } ret = feh_load_image(&old, FEH_FILE(w->file->data)); if (ret) { if (op == INPLACE_EDIT_FLIP) { imlib_context_set_image(old); imlib_image_flip_vertical(); } else if (op == INPLACE_EDIT_MIRROR) { imlib_context_set_image(old); imlib_image_flip_horizontal(); } else gib_imlib_image_orientate(old, op); ungib_imlib_save_image_with_error_return(old, FEH_FILE(w->file->data)->filename, &err); gib_imlib_free_image(old); if (err) feh_imlib_print_load_error(FEH_FILE(w->file->data)->filename, w, err); feh_reload_image(w, 1, 1); } else { im_weprintf(w, "failed to load image from disk to edit it in place"); } return; }
void feh_edit_inplace_lossless(winwidget w, int op) { char *filename = FEH_FILE(w->file->data)->filename; int len = strlen(filename) + 1; char *file_str = emalloc(len); int pid, status; int devnull = -1; char op_name[] = "rotate"; /* message */ char op_op[] = "-rotate"; /* jpegtran option */ char op_value[] = "horizontal"; /* jpegtran option's value */ if (op == INPLACE_EDIT_FLIP) { sprintf(op_name, "flip"); sprintf(op_op, "-flip"); sprintf(op_value, "vertical"); } else if (op == INPLACE_EDIT_MIRROR) { sprintf(op_name, "mirror"); sprintf(op_op, "-flip"); } else snprintf(op_value, 4, "%d", 90 * op); snprintf(file_str, len, "%s", filename); if ((pid = fork()) < 0) { im_weprintf(w, "lossless %s: fork failed:", op_name); free(file_str); return; } else if (pid == 0) { execlp("jpegtran", "jpegtran", "-copy", "all", op_op, op_value, "-outfile", file_str, file_str, NULL); weprintf("lossless %s: Is 'jpegtran' installed? Failed to exec:", op_name); _exit(1); } else { waitpid(pid, &status, 0); if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) { im_weprintf(w, "lossless %s: Got exitcode %d from jpegtran." " Commandline was: " "jpegtran -copy all %s %s -outfile %s %s", op_name, status >> 8, op_op, op_value, file_str, file_str); free(file_str); return; } }
void feh_filelist_image_remove(winwidget winwid, char do_delete) { if (winwid->type == WIN_TYPE_SLIDESHOW) { char *s; gib_list *doomed; doomed = current_file; /* * work around feh_list_jump exiting if cycle_once is enabled * and no further files are left (we need to delete first) */ if (opt.cycle_once && ! doomed->next && do_delete) { feh_file_rm_and_free(filelist, doomed); exit(0); } if (doomed->next) { slideshow_change_image(winwid, SLIDE_NEXT, 0); } else { slideshow_change_image(winwid, SLIDE_PREV, 0); } if (do_delete) filelist = feh_file_rm_and_free(filelist, doomed); else filelist = feh_file_remove_from_list(filelist, doomed); if (!filelist) { /* No more images. Game over ;-) */ winwidget_destroy(winwid); return; } s = slideshow_create_name(FEH_FILE(winwid->file->data), winwid); winwidget_rename(winwid, s); free(s); winwidget_render_image(winwid, 1, 0); } else if ((winwid->type == WIN_TYPE_SINGLE) || (winwid->type == WIN_TYPE_THUMBNAIL_VIEWER)) { if (do_delete) filelist = feh_file_rm_and_free(filelist, winwid->file); else filelist = feh_file_remove_from_list(filelist, winwid->file); winwidget_destroy(winwid); } }
int feh_write_filelist(gib_list * list, char *filename) { FILE *fp; gib_list *l; if (!list || !filename) return(0); errno = 0; if ((fp = fopen(filename, "w")) == NULL) { weprintf("can't write filelist %s:", filename); return(0); } for (l = list; l; l = l->next) fprintf(fp, "%s\n", (FEH_FILE(l->data)->filename)); fclose(fp); return(1); }
void init_collage_mode(void) { Imlib_Image im_main; Imlib_Image im_temp; int ww, hh, www, hhh, xxx, yyy; int w = 800, h = 600; int bg_w = 0, bg_h = 0; winwidget winwid = NULL; Imlib_Image bg_im = NULL, im_thumb = NULL; feh_file *file = NULL; unsigned char trans_bg = 0; gib_list *l, *last = NULL; char *s; D_ENTER(4); mode = "collage"; /* Use bg image dimensions for default size */ if (opt.bg && opt.bg_file) { if (!strcmp(opt.bg_file, "trans")) trans_bg = 1; else { D(4, ("Time to apply a background to blend onto\n")); if (feh_load_image_char(&bg_im, opt.bg_file) != 0) { bg_w = gib_imlib_image_get_width(bg_im); bg_h = gib_imlib_image_get_height(bg_im); } } } if (!opt.limit_w || !opt.limit_h) { if (bg_im) { if (opt.verbose) fprintf(stdout, PACKAGE " - No size restriction specified for collage.\n" " You did specify a background however, so the\n" " collage size has defaulted to the size of the image\n"); opt.limit_w = bg_w; opt.limit_h = bg_h; } else { if (opt.verbose) fprintf(stdout, PACKAGE " - No size restriction specified for collage.\n" " - For collage mode, you need to specify width and height.\n" " Using defaults (width 800, height 600)\n"); opt.limit_w = 800; opt.limit_h = 600; } } w = opt.limit_w; h = opt.limit_h; D(4, ("Limiting width to %d and height to %d\n", w, h)); im_main = imlib_create_image(w, h); if (!im_main) eprintf("Imlib error creating image"); if (bg_im) gib_imlib_blend_image_onto_image(im_main, bg_im, gib_imlib_image_has_alpha(bg_im), 0, 0, bg_w, bg_h, 0, 0, w, h, 1, 0, 0); else if (trans_bg) { gib_imlib_image_fill_rectangle(im_main, 0, 0, w, h, 0, 0, 0, 0); gib_imlib_image_set_has_alpha(im_main, 1); } else { /* Colour the background */ gib_imlib_image_fill_rectangle(im_main, 0, 0, w, h, 0, 0, 0, 255); } /* Create the title string */ if (!opt.title) s = estrdup(PACKAGE " [collage mode]"); else s = estrdup(feh_printf(opt.title, NULL)); if (opt.display) { winwid = winwidget_create_from_image(im_main, s, WIN_TYPE_SINGLE); winwidget_show(winwid); } for (l = filelist; l; l = l->next) { file = FEH_FILE(l->data); if (last) { filelist = feh_file_remove_from_list(filelist, last); filelist_len--; last = NULL; } D(3, ("About to load image %s\n", file->filename)); if (feh_load_image(&im_temp, file) != 0) { D(3, ("Successfully loaded %s\n", file->filename)); if (opt.verbose) feh_display_status('.'); www = opt.thumb_w; hhh = opt.thumb_h; ww = gib_imlib_image_get_width(im_temp); hh = gib_imlib_image_get_height(im_temp); if (opt.aspect) { double ratio = 0.0; /* Keep the aspect ratio for the thumbnail */ ratio = ((double) ww / hh) / ((double) www / hhh); if (ratio > 1.0) hhh = opt.thumb_h / ratio; else if (ratio != 1.0) www = opt.thumb_w * ratio; } if ((!opt.stretch) && ((www > ww) || (hhh > hh))) { /* Don't make the image larger unless stretch is specified */ www = ww; hhh = hh; } /* pick random coords for thumbnail */ xxx = ((w - www) * ((double) rand() / RAND_MAX)); yyy = ((h - hhh) * ((double) rand() / RAND_MAX)); D(5, ("image going on at x=%d, y=%d\n", xxx, yyy)); im_thumb = gib_imlib_create_cropped_scaled_image(im_temp, 0, 0, ww, hh, www, hhh, 1); gib_imlib_free_image_and_decache(im_temp); if (opt.alpha) { DATA8 atab[256]; D(4, ("Applying alpha options\n")); gib_imlib_image_set_has_alpha(im_thumb, 1); memset(atab, opt.alpha_level, sizeof(atab)); gib_imlib_apply_color_modifier_to_rectangle(im_thumb, 0, 0, www, hhh, NULL, NULL, NULL, atab); } gib_imlib_blend_image_onto_image(im_main, im_thumb, gib_imlib_image_has_alpha(im_thumb), 0, 0, www, hhh, xxx, yyy,www, hhh, 1, gib_imlib_image_has_alpha(im_thumb), 0); gib_imlib_free_image_and_decache(im_thumb); } else { last = l; if (opt.verbose) feh_display_status('x'); } if (opt.display) { winwidget_render_image(winwid, 0, 0); if (!feh_main_iteration(0)) exit(0); } } if (opt.verbose) fprintf(stdout, "\n"); if (opt.output && opt.output_file) { char output_buf[1024]; if (opt.output_dir) snprintf(output_buf, 1024, "%s/%s", opt.output_dir, opt.output_file); else strncpy(output_buf, opt.output_file, 1024); gib_imlib_save_image(im_main, output_buf); if (opt.verbose) { int tw, th; tw = gib_imlib_image_get_width(im_main); th = gib_imlib_image_get_height(im_main); fprintf(stdout, PACKAGE " - File saved as %s\n", output_buf); fprintf(stdout, " - Image is %dx%d pixels and contains %d thumbnails\n", tw, th, (tw / opt.thumb_w) * (th / opt.thumb_h)); } } if (!opt.display) gib_imlib_free_image_and_decache(im_main); free(s); D_RETURN_(4); }
gib_list *feh_file_rm_and_free(gib_list * list, gib_list * l) { unlink(FEH_FILE(l->data)->filename); return(feh_file_remove_from_list(list, l)); }
int feh_cmp_pixels(void *file1, void *file2) { return((FEH_FILE(file1)->info->pixels - FEH_FILE(file2)->info->pixels)); }
/* TODO s/bit/lot */ void init_thumbnail_mode(void) { /* moved to thumbnail_data: Imlib_Image im_main; Imlib_Image bg_im = NULL; Imlib_Font fn = NULL; Imlib_Font title_fn = NULL; int w = 800, h = 600; int bg_w = 0, bg_h = 0; int text_area_w, text_area_h; int max_column_w = 0; */ Imlib_Image im_temp; int ww = 0, hh = 0, www, hhh, xxx, yyy; int x = 0, y = 0; winwidget winwid = NULL; Imlib_Image im_thumb = NULL; unsigned char trans_bg = 0; int title_area_h = 0; int tw = 0, th = 0; int fw_name, fw_size, fw_dim, fh; int thumbnailcount = 0; feh_file *file = NULL; gib_list *l, *last = NULL; int lines; int index_image_width, index_image_height; int x_offset_name = 0, x_offset_dim = 0, x_offset_size = 0; char *s; unsigned int thumb_counter = 0; /* initialize thumbnail mode data */ td.im_main = NULL; td.im_bg = NULL; td.font_main = NULL; td.font_title = NULL; td.w = 640; td.h = 480; td.bg_w = 0; td.bg_h = 0; td.thumb_tot_h = 0; td.text_area_w = 0; td.text_area_h = 0; td.vertical = 0; td.max_column_w = 0; mode = "thumbnail"; if (opt.font) td.font_main = gib_imlib_load_font(opt.font); if (!td.font_main) td.font_main = gib_imlib_load_font(DEFAULT_FONT); if (opt.title_font) { int fh, fw; td.font_title = gib_imlib_load_font(opt.title_font); gib_imlib_get_text_size(td.font_title, "W", NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT); title_area_h = fh + 4; } else td.font_title = imlib_load_font(DEFAULT_FONT_TITLE); if ((!td.font_main) || (!td.font_title)) eprintf("Error loading fonts"); /* Work out how tall the font is */ gib_imlib_get_text_size(td.font_main, "W", NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT); /* For now, allow room for the right number of lines with small gaps */ td.text_area_h = ((th + 2) * (opt.index_show_name + opt.index_show_size + opt.index_show_dim)) + 5; /* This includes the text area for index data */ td.thumb_tot_h = opt.thumb_h + td.text_area_h; /* Use bg image dimensions for default size */ if (opt.bg && opt.bg_file) { if (!strcmp(opt.bg_file, "trans")) trans_bg = 1; else { D(3, ("Time to apply a background to blend onto\n")); if (feh_load_image_char(&td.im_bg, opt.bg_file) != 0) { td.bg_w = gib_imlib_image_get_width(td.im_bg); td.bg_h = gib_imlib_image_get_height(td.im_bg); } } } /* figure out geometry for the main window and entries */ feh_thumbnail_calculate_geometry(); index_image_width = td.w; index_image_height = td.h + title_area_h; td.im_main = imlib_create_image(index_image_width, index_image_height); gib_imlib_image_set_has_alpha(td.im_main, 1); if (!td.im_main) eprintf("Imlib error creating index image, are you low on RAM?"); if (td.im_bg) gib_imlib_blend_image_onto_image(td.im_main, td.im_bg, gib_imlib_image_has_alpha (td.im_bg), 0, 0, td.bg_w, td.bg_h, 0, 0, td.w, td.h, 1, 0, 0); else if (trans_bg) { gib_imlib_image_fill_rectangle(td.im_main, 0, 0, td.w, td.h + title_area_h, 0, 0, 0, 0); gib_imlib_image_set_has_alpha(td.im_main, 1); } else { /* Colour the background */ gib_imlib_image_fill_rectangle(td.im_main, 0, 0, td.w, td.h + title_area_h, 0, 0, 0, 255); } /* Create title now */ if (!opt.title) s = estrdup(PACKAGE " [thumbnail mode]"); else s = estrdup(feh_printf(opt.title, NULL)); if (opt.display) { winwid = winwidget_create_from_image(td.im_main, s, WIN_TYPE_THUMBNAIL); winwidget_show(winwid); } /* make sure we have an ~/.thumbnails/normal directory for storing permanent thumbnails */ td.cache_thumbnails = opt.cache_thumbnails; if (td.cache_thumbnails) { if (opt.thumb_w > opt.thumb_h) td.cache_dim = opt.thumb_w; else td.cache_dim = opt.thumb_h; if (td.cache_dim > 256) { /* No caching as specified by standard. Sort of. */ td.cache_thumbnails = 0; } else if (td.cache_dim > 128) { td.cache_dim = 256; td.cache_dir = estrdup("large"); } else { td.cache_dim = 128; td.cache_dir = estrdup("normal"); } feh_thumbnail_setup_thumbnail_dir(); } for (l = filelist; l; l = l->next) { file = FEH_FILE(l->data); if (last) { filelist = feh_file_remove_from_list(filelist, last); last = NULL; } D(4, ("About to load image %s\n", file->filename)); /* if (feh_load_image(&im_temp, file) != 0) */ if (feh_thumbnail_get_thumbnail(&im_temp, file) != 0) { if (opt.verbose) feh_display_status('.'); D(4, ("Successfully loaded %s\n", file->filename)); www = opt.thumb_w; hhh = opt.thumb_h; ww = gib_imlib_image_get_width(im_temp); hh = gib_imlib_image_get_height(im_temp); thumbnailcount++; if (gib_imlib_image_has_alpha(im_temp)) imlib_context_set_blend(1); else imlib_context_set_blend(0); if (opt.aspect) { double ratio = 0.0; /* Keep the aspect ratio for the thumbnail */ ratio = ((double) ww / hh) / ((double) www / hhh); if (ratio > 1.0) hhh = opt.thumb_h / ratio; else if (ratio != 1.0) www = opt.thumb_w * ratio; } if ((!opt.stretch) && ((www > ww) || (hhh > hh))) { /* Don't make the image larger unless stretch is specified */ www = ww; hhh = hh; } im_thumb = gib_imlib_create_cropped_scaled_image(im_temp, 0, 0, ww, hh, www, hhh, 1); gib_imlib_free_image_and_decache(im_temp); if (opt.alpha) { DATA8 atab[256]; D(3, ("Applying alpha options\n")); gib_imlib_image_set_has_alpha(im_thumb, 1); memset(atab, opt.alpha_level, sizeof(atab)); gib_imlib_apply_color_modifier_to_rectangle (im_thumb, 0, 0, www, hhh, NULL, NULL, NULL, atab); } td.text_area_w = opt.thumb_w; /* Now draw on the info text */ if (opt.index_show_name) { gib_imlib_get_text_size(td.font_main, file->name, NULL, &fw_name, &fh, IMLIB_TEXT_TO_RIGHT); if (fw_name > td.text_area_w) td.text_area_w = fw_name; } if (opt.index_show_dim) { gib_imlib_get_text_size(td.font_main, create_index_dimension_string(ww, hh), NULL, &fw_dim, &fh, IMLIB_TEXT_TO_RIGHT); if (fw_dim > td.text_area_w) td.text_area_w = fw_dim; } if (opt.index_show_size) { gib_imlib_get_text_size(td.font_main, create_index_size_string(file->filename), NULL, &fw_size, &fh, IMLIB_TEXT_TO_RIGHT); if (fw_size > td.text_area_w) td.text_area_w = fw_size; } if (td.text_area_w > opt.thumb_w) td.text_area_w += 5; /* offsets for centering text */ x_offset_name = (td.text_area_w - fw_name) / 2; x_offset_dim = (td.text_area_w - fw_dim) / 2; x_offset_size = (td.text_area_w - fw_size) / 2; if (td.vertical) { if (td.text_area_w > td.max_column_w) td.max_column_w = td.text_area_w; if (y > td.h - td.thumb_tot_h) { y = 0; x += td.max_column_w; td.max_column_w = 0; } if (x > td.w - td.text_area_w) break; } else { if (x > td.w - td.text_area_w) { x = 0; y += td.thumb_tot_h; } if (y > td.h - td.thumb_tot_h) break; } /* center image relative to the text below it (if any) */ xxx = x + ((td.text_area_w - www) / 2); yyy = y; if (opt.aspect) yyy += (opt.thumb_h - hhh) / 2; /* Draw now */ gib_imlib_blend_image_onto_image(td.im_main, im_thumb, gib_imlib_image_has_alpha (im_thumb), 0, 0, www, hhh, xxx, yyy, www, hhh, 1, gib_imlib_image_has_alpha(im_thumb), 0); thumbnails = gib_list_add_front(thumbnails, feh_thumbnail_new(file, xxx, yyy, www, hhh)); gib_imlib_free_image_and_decache(im_thumb); lines = 0; if (opt.index_show_name) gib_imlib_text_draw(td.im_main, td.font_main, NULL, x + x_offset_name, y + opt.thumb_h + (lines++ * (th + 2)) + 2, file->name, IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); if (opt.index_show_dim) gib_imlib_text_draw(td.im_main, td.font_main, NULL, x + x_offset_dim, y + opt.thumb_h + (lines++ * (th + 2)) + 2, create_index_dimension_string(ww, hh), IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); if (opt.index_show_size) gib_imlib_text_draw(td.im_main, td.font_main, NULL, x + x_offset_size, y + opt.thumb_h + (lines++ * (th + 2)) + 2, create_index_size_string(file->filename), IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); if (td.vertical) y += td.thumb_tot_h; else x += td.text_area_w; } else { if (opt.verbose) feh_display_status('x'); last = l; } if (opt.display) { /* thumb_counter is unsigned, so no need to catch overflows */ if (++thumb_counter == opt.thumb_redraw) { winwidget_render_image(winwid, 0, 0); thumb_counter = 0; } if (!feh_main_iteration(0)) exit(0); } } if (thumb_counter != 0) winwidget_render_image(winwid, 0, 0); if (opt.verbose) fprintf(stdout, "\n"); if (opt.title_font) { int fw, fh, fx, fy; char *s; s = create_index_title_string(thumbnailcount, td.w, td.h); gib_imlib_get_text_size(td.font_title, s, NULL, &fw, &fh, IMLIB_TEXT_TO_RIGHT); fx = (index_image_width - fw) >> 1; fy = index_image_height - fh - 2; gib_imlib_text_draw(td.im_main, td.font_title, NULL, fx, fy, s, IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); }
void feh_draw_caption(winwidget w) { static Imlib_Font fn = NULL; int tw = 0, th = 0, ww, hh; int x, y; Imlib_Image im = NULL; char *p; gib_list *lines, *l; static gib_style *caption_style = NULL; feh_file *file; if (!w->file) { return; } file = FEH_FILE(w->file->data); if (!file->filename) { return; } if (!file->caption) { char *caption_filename; caption_filename = build_caption_filename(file, 0); if (caption_filename) /* read caption from file */ file->caption = ereadfile(caption_filename); else file->caption = estrdup(""); free(caption_filename); } if (file->caption == NULL) { /* caption file is not there, we want to cache that, otherwise we'll stat * the damn file every time we render the image. Reloading an image will * always cause the caption to be reread though so we're safe to do so. * (Before this bit was added, when zooming a captionless image with * captions enabled, the captions file would be stat()d like 30 times a * second) - don't forget this function is called from * winwidget_render_image(). */ file->caption = estrdup(""); } if (*(file->caption) == '\0' && !w->caption_entry) return; caption_style = gib_style_new("caption"); caption_style->bits = gib_list_add_front(caption_style->bits, gib_style_bit_new(0, 0, 0, 0, 0, 0)); caption_style->bits = gib_list_add_front(caption_style->bits, gib_style_bit_new(1, 1, 0, 0, 0, 255)); fn = feh_load_font(w); if (*(file->caption) == '\0') { p = estrdup("Caption entry mode - Hit ESC to cancel"); lines = feh_wrap_string(p, w->w, fn, NULL); free(p); } else lines = feh_wrap_string(file->caption, w->w, fn, NULL); if (!lines) return; /* Work out how high/wide the caption is */ l = lines; while (l) { p = (char *) l->data; gib_imlib_get_text_size(fn, p, caption_style, &ww, &hh, IMLIB_TEXT_TO_RIGHT); if (ww > tw) tw = ww; th += hh; if (l->next) th += 1; /* line spacing */ l = l->next; } /* we don't want the caption overlay larger than our window */ if (th > w->h) th = w->h; if (tw > w->w) tw = w->w; im = imlib_create_image(tw, th); if (!im) eprintf("Couldn't create image. Out of memory?"); feh_imlib_image_fill_text_bg(im, tw, th); l = lines; x = 0; y = 0; while (l) { p = (char *) l->data; gib_imlib_get_text_size(fn, p, caption_style, &ww, &hh, IMLIB_TEXT_TO_RIGHT); x = (tw - ww) / 2; if (w->caption_entry && (*(file->caption) == '\0')) gib_imlib_text_draw(im, fn, caption_style, x, y, p, IMLIB_TEXT_TO_RIGHT, 255, 255, 127, 255); else if (w->caption_entry) gib_imlib_text_draw(im, fn, caption_style, x, y, p, IMLIB_TEXT_TO_RIGHT, 255, 255, 0, 255); else gib_imlib_text_draw(im, fn, caption_style, x, y, p, IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); y += hh + 1; /* line spacing */ l = l->next; } gib_imlib_render_image_on_drawable(w->bg_pmap, im, (w->w - tw) / 2, w->h - th, 1, 1, 0); gib_imlib_free_image_and_decache(im); gib_list_free_and_data(lines); return; }
void feh_draw_info(winwidget w) { static Imlib_Font fn = NULL; int width = 0, height = 0, line_width = 0, line_height = 0; Imlib_Image im = NULL; int no_lines = 0, i; char *info_cmd; char info_line[256]; char *info_buf[128]; FILE *info_pipe; if ((!w->file) || (!FEH_FILE(w->file->data)) || (!FEH_FILE(w->file->data)->filename)) return; fn = feh_load_font(w); info_cmd = feh_printf(opt.info_cmd, FEH_FILE(w->file->data), w); info_pipe = popen(info_cmd, "r"); if (!info_pipe) { info_buf[0] = estrdup("Failed to run info command"); gib_imlib_get_text_size(fn, info_buf[0], NULL, &width, &height, IMLIB_TEXT_TO_RIGHT); no_lines = 1; } else { while ((no_lines < 128) && fgets(info_line, 256, info_pipe)) { if (info_line[strlen(info_line)-1] == '\n') info_line[strlen(info_line)-1] = '\0'; gib_imlib_get_text_size(fn, info_line, NULL, &line_width, &line_height, IMLIB_TEXT_TO_RIGHT); if (line_height > height) height = line_height; if (line_width > width) width = line_width; info_buf[no_lines] = estrdup(info_line); no_lines++; } pclose(info_pipe); } if (no_lines == 0) return; height *= no_lines; width += 4; im = imlib_create_image(width, height); if (!im) eprintf("Couldn't create image. Out of memory?"); feh_imlib_image_fill_text_bg(im, width, height); for (i = 0; i < no_lines; i++) { gib_imlib_text_draw(im, fn, NULL, 2, (i * line_height) + 2, info_buf[i], IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255); gib_imlib_text_draw(im, fn, NULL, 1, (i * line_height) + 1, info_buf[i], IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); free(info_buf[i]); } gib_imlib_render_image_on_drawable(w->bg_pmap, im, 0, w->h - height, 1, 1, 0); gib_imlib_free_image_and_decache(im); return; }
void feh_draw_exif(winwidget w) { static Imlib_Font fn = NULL; int width = 0, height = 0, line_width = 0, line_height = 0; Imlib_Image im = NULL; int no_lines = 0, i; int pos = 0; int pos2 = 0; char info_line[256]; char *info_buf[128]; char buffer[EXIF_MAX_DATA]; if ( (!w->file) || (!FEH_FILE(w->file->data)) || (!FEH_FILE(w->file->data)->filename) ) { return; } buffer[0] = '\0'; exif_get_info(FEH_FILE(w->file->data)->ed, buffer, EXIF_MAX_DATA); fn = feh_load_font(w); if (buffer == NULL) { snprintf(buffer, EXIF_MAX_DATA, "%s", estrdup("Failed to run exif command")); gib_imlib_get_text_size(fn, &buffer[0], NULL, &width, &height, IMLIB_TEXT_TO_RIGHT); no_lines = 1; } else { while ( (no_lines < 128) && (pos < EXIF_MAX_DATA) ) { /* max 128 lines */ pos2 = 0; while ( pos2 < 256 ) /* max 256 chars per line */ { if ( (buffer[pos] != '\n') && (buffer[pos] != '\0') ) { info_line[pos2] = buffer[pos]; } else if ( buffer[pos] == '\0' ) { pos = EXIF_MAX_DATA; /* all data seen */ info_line[pos2] = '\0'; } else { info_line[pos2] = '\0'; /* line finished, continue with next line*/ pos++; break; } pos++; pos2++; } gib_imlib_get_text_size(fn, info_line, NULL, &line_width, &line_height, IMLIB_TEXT_TO_RIGHT); if (line_height > height) height = line_height; if (line_width > width) width = line_width; info_buf[no_lines] = estrdup(info_line); no_lines++; } } if (no_lines == 0) return; height *= no_lines; width += 4; im = imlib_create_image(width, height); if (!im) { eprintf("Couldn't create image. Out of memory?"); } feh_imlib_image_fill_text_bg(im, width, height); for (i = 0; i < no_lines; i++) { gib_imlib_text_draw(im, fn, NULL, 2, (i * line_height) + 2, info_buf[i], IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255); gib_imlib_text_draw(im, fn, NULL, 1, (i * line_height) + 1, info_buf[i], IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); } gib_imlib_render_image_on_drawable(w->bg_pmap, im, 0, w->h - height, 1, 1, 0); gib_imlib_free_image_and_decache(im); return; }
int feh_cmp_size(void *file1, void *file2) { return((FEH_FILE(file1)->info->size - FEH_FILE(file2)->info->size)); }
int feh_cmp_format(void *file1, void *file2) { return(strcmp(FEH_FILE(file1)->info->format, FEH_FILE(file2)->info->format)); }
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 feh_reload_image(winwidget w, int resize, int force_new) { char *title, *new_title; int len; Imlib_Image tmp; int old_w, old_h; unsigned char tmode =0; int tim_x =0; int tim_y =0; double tzoom =0; tmode = w->mode; tim_x = w->im_x; tim_y = w->im_y; tzoom = w->zoom; if (!w->file) { im_weprintf(w, "couldn't reload, this image has no file associated with it."); winwidget_render_image(w, 0, 0); return; } D(("resize %d, force_new %d\n", resize, force_new)); free(FEH_FILE(w->file->data)->caption); FEH_FILE(w->file->data)->caption = NULL; len = strlen(w->name) + sizeof("Reloading: ") + 1; new_title = emalloc(len); snprintf(new_title, len, "Reloading: %s", w->name); title = estrdup(w->name); winwidget_rename(w, new_title); old_w = gib_imlib_image_get_width(w->im); old_h = gib_imlib_image_get_height(w->im); /* * If we don't free the old image before loading the new one, Imlib2's * caching will get in our way. * However, if --reload is used (force_new == 0), we want to continue if * the new image cannot be loaded, so we must not free the old image yet. */ if (force_new) winwidget_free_image(w); if ((feh_load_image(&tmp, FEH_FILE(w->file->data))) == 0) { if (force_new) eprintf("failed to reload image\n"); else { im_weprintf(w, "Couldn't reload image. Is it still there?"); winwidget_render_image(w, 0, 0); } winwidget_rename(w, title); free(title); free(new_title); return; } if (!resize && ((old_w != gib_imlib_image_get_width(tmp)) || (old_h != gib_imlib_image_get_height(tmp)))) resize = 1; if (!force_new) winwidget_free_image(w); w->im = tmp; winwidget_reset_image(w); w->mode = MODE_NORMAL; if ((w->im_w != gib_imlib_image_get_width(w->im)) || (w->im_h != gib_imlib_image_get_height(w->im))) w->had_resize = 1; if (w->has_rotated) { Imlib_Image temp; temp = gib_imlib_create_rotated_image(w->im, 0.0); w->im_w = gib_imlib_image_get_width(temp); w->im_h = gib_imlib_image_get_height(temp); gib_imlib_free_image_and_decache(temp); } else { w->im_w = gib_imlib_image_get_width(w->im); w->im_h = gib_imlib_image_get_height(w->im); } if (opt.keep_zoom_vp) { /* put back in: */ w->mode = tmode; w->im_x = tim_x; w->im_y = tim_y; w->zoom = tzoom; winwidget_render_image(w, 0, 0); } else { winwidget_render_image(w, resize, 0); } winwidget_rename(w, title); free(title); free(new_title); return; }
void feh_menu_cb(feh_menu * m, feh_menu_item * i, int action, void *data) { char *path; Imlib_Image im; winwidget winwid; switch (action) { case CB_BG_TILED: path = feh_absolute_path(FEH_FILE(m->fehwin->file->data)->filename); feh_wm_set_bg(path, m->fehwin->im, 0, 0, 0, (int) data, 1); free(path); break; case CB_BG_SCALED: path = feh_absolute_path(FEH_FILE(m->fehwin->file->data)->filename); feh_wm_set_bg(path, m->fehwin->im, 0, 1, 0, (int) data, 1); free(path); break; case CB_BG_CENTERED: path = feh_absolute_path(FEH_FILE(m->fehwin->file->data)->filename); feh_wm_set_bg(path, m->fehwin->im, 1, 0, 0, (int) data, 1); free(path); break; case CB_BG_FILLED: path = feh_absolute_path(FEH_FILE(m->fehwin->file->data)->filename); feh_wm_set_bg(path, m->fehwin->im, 0, 0, 1, (int) data, 1); free(path); break; case CB_BG_TILED_NOFILE: feh_wm_set_bg(NULL, m->fehwin->im, 0, 0, 0, (int) data, 1); break; case CB_BG_SCALED_NOFILE: feh_wm_set_bg(NULL, m->fehwin->im, 0, 1, 0, (int) data, 1); break; case CB_BG_CENTERED_NOFILE: feh_wm_set_bg(NULL, m->fehwin->im, 1, 0, 0, (int) data, 1); break; case CB_BG_FILLED_NOFILE: feh_wm_set_bg(NULL, m->fehwin->im, 0, 0, 1, (int) data, 1); break; case CB_ABOUT: if (feh_load_image_char(&im, PREFIX "/share/feh/images/about.png") != 0) { winwid = winwidget_create_from_image(im, "About " PACKAGE, WIN_TYPE_ABOUT); winwid->file = gib_list_add_front(NULL, feh_file_new(PREFIX "/share/feh/images/about.png")); winwidget_show(winwid); } break; case CB_CLOSE: winwidget_destroy(m->fehwin); break; case CB_EXIT: winwidget_destroy_all(); break; case CB_RESET: if (m->fehwin->has_rotated) { m->fehwin->im_w = gib_imlib_image_get_width(m->fehwin->im); m->fehwin->im_h = gib_imlib_image_get_height(m->fehwin->im); winwidget_resize(m->fehwin, m->fehwin->im_w, m->fehwin->im_h); } winwidget_reset_image(m->fehwin); winwidget_render_image(m->fehwin, 1, 1); break; case CB_RELOAD: feh_reload_image(m->fehwin, 0, 0); break; case CB_REMOVE: feh_filelist_image_remove(m->fehwin, 0); break; case CB_DELETE: feh_filelist_image_remove(m->fehwin, 1); break; case CB_REMOVE_THUMB: feh_thumbnail_mark_removed(FEH_FILE(m->fehwin->file->data), 0); feh_filelist_image_remove(m->fehwin, 0); break; case CB_DELETE_THUMB: feh_thumbnail_mark_removed(FEH_FILE(m->fehwin->file->data), 1); feh_filelist_image_remove(m->fehwin, 1); break; case CB_SORT_FILENAME: filelist = gib_list_sort(filelist, feh_cmp_filename); if (opt.jump_on_resort) { slideshow_change_image(m->fehwin, SLIDE_FIRST); } break; case CB_SORT_IMAGENAME: filelist = gib_list_sort(filelist, feh_cmp_name); if (opt.jump_on_resort) { slideshow_change_image(m->fehwin, SLIDE_FIRST); } break; case CB_SORT_FILESIZE: filelist = gib_list_sort(filelist, feh_cmp_size); if (opt.jump_on_resort) { slideshow_change_image(m->fehwin, SLIDE_FIRST); } break; case CB_SORT_RANDOMIZE: filelist = gib_list_randomize(filelist); if (opt.jump_on_resort) { slideshow_change_image(m->fehwin, SLIDE_FIRST); } break; case CB_FIT: winwidget_size_to_image(m->fehwin); break; case CB_EDIT_ROTATE: feh_edit_inplace_orient(m->fehwin, (int) data); break; case CB_SAVE_IMAGE: slideshow_save_image(m->fehwin); break; case CB_SAVE_FILELIST: feh_save_filelist(); break; case CB_OPT_DRAW_FILENAME: MENU_ITEM_TOGGLE(i); if (MENU_ITEM_IS_ON(i)) opt.draw_filename = TRUE; else opt.draw_filename = FALSE; winwidget_rerender_all(0, 1); break; case CB_OPT_DRAW_ACTIONS: MENU_ITEM_TOGGLE(i); if (MENU_ITEM_IS_ON(i)) opt.draw_actions = TRUE; else opt.draw_actions = FALSE; winwidget_rerender_all(0, 1); break; case CB_OPT_KEEP_HTTP: MENU_ITEM_TOGGLE(i); if (MENU_ITEM_IS_ON(i)) opt.keep_http = TRUE; else opt.keep_http = FALSE; break; case CB_OPT_FREEZE_WINDOW: MENU_ITEM_TOGGLE(i); if (MENU_ITEM_IS_ON(i)) { opt.geom_flags = (WidthValue | HeightValue); opt.geom_w = m->fehwin->w; opt.geom_h = m->fehwin->h; } else { opt.geom_flags = 0; } break; case CB_OPT_FULLSCREEN: feh_menu_cb_opt_fullscreen(m, i); break; case CB_OPT_AUTO_ZOOM: MENU_ITEM_TOGGLE(i); if (MENU_ITEM_IS_ON(i)) opt.zoom_mode = ZOOM_MODE_FILL; else opt.zoom_mode = 0; winwidget_rerender_all(1, 1); break; } return; }