From 503048c639e1017324e64313c7eb197b20201b40 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Sun, 12 Aug 2012 19:21:07 +0200 Subject: Add %o, %r and %z format specifiers (see #95) --- ChangeLog | 4 +++ man/feh.pre | 12 ++++++++ src/collage.c | 2 +- src/feh.h | 4 +-- src/imlib.c | 2 +- src/index.c | 4 +-- src/list.c | 2 +- src/multiwindow.c | 2 +- src/slideshow.c | 85 ++++++++++++++++++++++++++++++++++--------------------- src/thumbnail.c | 4 +-- 10 files changed, 78 insertions(+), 43 deletions(-) diff --git a/ChangeLog b/ChangeLog index bcde5bc..9cc7838 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,6 +6,10 @@ git HEAD * menu: simpler background, remove drop shadows * Remove --menu-style support (deprecated in 1.12) * Allow --slideshow-delay and --reload to be used together + * New format specifiers: + ** %o x,y image offset relative to top-left window corner + ** %r image rotation + ** %z image zoom Sun, 25 Mar 2012 13:13:26 +0200 Daniel Friesel diff --git a/man/feh.pre b/man/feh.pre index 7254428..a50a66a 100644 --- a/man/feh.pre +++ b/man/feh.pre @@ -817,6 +817,10 @@ Image name . Escaped image name . +.It %o +. +x,y offset of top-left image corner to window corner in pixels +. .It %p . Number of image pixels @@ -826,6 +830,10 @@ Number of image pixels Numbor of image pixels .Pq kilopixels / megapixels . +.It %r +. +Image rotation. A half right turn equals pi. +. .It %s . Image size in bytes @@ -852,6 +860,10 @@ Image width .Nm version . +.It %z +. +current image zoom +. .El . . diff --git a/src/collage.c b/src/collage.c index a7ae44e..711e3a4 100644 --- a/src/collage.c +++ b/src/collage.c @@ -110,7 +110,7 @@ void init_collage_mode(void) if (!opt.title) s = estrdup(PACKAGE " [collage mode]"); else - s = estrdup(feh_printf(opt.title, NULL)); + s = estrdup(feh_printf(opt.title, NULL, NULL)); if (opt.display) { winwid = winwidget_create_from_image(im_main, s, WIN_TYPE_SINGLE); diff --git a/src/feh.h b/src/feh.h index 1d48e53..2b0369f 100644 --- a/src/feh.h +++ b/src/feh.h @@ -132,13 +132,13 @@ int feh_load_image(Imlib_Image * im, feh_file * file); void show_mini_usage(void); void slideshow_change_image(winwidget winwid, int change, int render); void slideshow_pause_toggle(winwidget w); -char *slideshow_create_name(feh_file * file); +char *slideshow_create_name(feh_file * file, winwidget winwid); void init_keyevents(void); void init_buttonbindings(void); void feh_event_handle_keypress(XEvent * ev); void feh_action_run(feh_file * file, char *action); char *format_size(int size); -char *feh_printf(char *str, feh_file * file); +char *feh_printf(char *str, feh_file * file, winwidget winwid); void im_weprintf(winwidget w, char *fmt, ...); void feh_draw_zoom(winwidget w); void feh_draw_checks(winwidget win); diff --git a/src/imlib.c b/src/imlib.c index 4f7ff24..e7dcaeb 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -725,7 +725,7 @@ void feh_draw_info(winwidget w) fn = feh_load_font(w); - info_cmd = feh_printf(opt.info_cmd, FEH_FILE(w->file->data)); + info_cmd = feh_printf(opt.info_cmd, FEH_FILE(w->file->data), w); info_pipe = popen(info_cmd, "r"); diff --git a/src/index.c b/src/index.c index b489c55..023cba0 100644 --- a/src/index.c +++ b/src/index.c @@ -167,7 +167,7 @@ void init_index_mode(void) if (!opt.title) s = estrdup(PACKAGE " [index mode]"); else - s = estrdup(feh_printf(opt.title, NULL)); + s = estrdup(feh_printf(opt.title, NULL, NULL)); if (opt.display) { winwid = winwidget_create_from_image(im_main, s, WIN_TYPE_SINGLE); @@ -465,7 +465,7 @@ void get_index_string_dim(feh_file *file, Imlib_Font fn, int *fw, int *fh) char *create_index_string(feh_file * file) { - return feh_printf(opt.index_info, file); + return feh_printf(opt.index_info, file, NULL); } char *create_index_title_string(int num, int w, int h) diff --git a/src/list.c b/src/list.c index 2affe85..5663ed3 100644 --- a/src/list.c +++ b/src/list.c @@ -43,7 +43,7 @@ void init_list_mode(void) for (l = filelist; l; l = l->next) { file = FEH_FILE(l->data); if (opt.customlist) - printf("%s\n", feh_printf(opt.customlist, file)); + printf("%s\n", feh_printf(opt.customlist, file, NULL)); else { printf("%d\t%s\t%d\t%d\t%s", ++j, file->info->format, file->info->width, diff --git a/src/multiwindow.c b/src/multiwindow.c index 9797fb0..13cff90 100644 --- a/src/multiwindow.c +++ b/src/multiwindow.c @@ -49,7 +49,7 @@ void init_multiwindow_mode(void) s = emalloc(len); snprintf(s, len, PACKAGE " - %s", file->filename); } else { - s = estrdup(feh_printf(opt.title, file)); + s = estrdup(feh_printf(opt.title, file, w)); } if ((w = winwidget_create_from_file(l, s, WIN_TYPE_SINGLE)) != NULL) { diff --git a/src/slideshow.c b/src/slideshow.c index 3ccf2f1..cec146c 100644 --- a/src/slideshow.c +++ b/src/slideshow.c @@ -58,7 +58,7 @@ void init_slideshow_mode(void) last = NULL; } current_file = l; - s = slideshow_create_name(file); + s = slideshow_create_name(file, NULL); if ((w = winwidget_create_from_file(l, s, WIN_TYPE_SLIDESHOW)) != NULL) { free(s); success = 1; @@ -133,7 +133,7 @@ void cb_reload_timer(void *data) /* 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)); + current_filename = slideshow_create_name(FEH_FILE(current_file->data), w); winwidget_rename(w, current_filename); free(current_filename); @@ -321,7 +321,7 @@ void slideshow_change_image(winwidget winwid, int change, int render) if (render) winwidget_render_image(winwid, 1, 0); - s = slideshow_create_name(FEH_FILE(current_file->data)); + s = slideshow_create_name(FEH_FILE(current_file->data), winwid); winwidget_rename(winwid, s); free(s); @@ -351,7 +351,7 @@ void slideshow_pause_toggle(winwidget w) winwidget_rename(w, NULL); } -char *slideshow_create_name(feh_file * file) +char *slideshow_create_name(feh_file * file, winwidget winwid) { char *s = NULL; int len = 0; @@ -362,7 +362,7 @@ char *slideshow_create_name(feh_file * file) snprintf(s, len, PACKAGE " [%d of %d] - %s", gib_list_num(filelist, current_file) + 1, gib_list_length(filelist), file->filename); } else { - s = estrdup(feh_printf(opt.title, file)); + s = estrdup(feh_printf(opt.title, file, winwid)); } return(s); @@ -373,7 +373,7 @@ void feh_action_run(feh_file * file, char *action) if (action) { char *sys; D(("Running action %s\n", action)); - sys = feh_printf(action, file); + sys = feh_printf(action, file, NULL); if (opt.verbose && !opt.list && !opt.customlist) fprintf(stderr, "Running action -->%s<--\n", sys); @@ -418,7 +418,7 @@ char *format_size(int size) return ret; } -char *feh_printf(char *str, feh_file * file) +char *feh_printf(char *str, feh_file * file, winwidget winwid) { char *c; char buf[20]; @@ -438,6 +438,19 @@ char *feh_printf(char *str, feh_file * file) if (file) strcat(ret, shell_escape(file->filename)); break; + case 'h': + if (file && (file->info || !feh_file_info_load(file, NULL))) { + snprintf(buf, sizeof(buf), "%d", file->info->height); + strcat(ret, buf); + } + break; + case 'l': + snprintf(buf, sizeof(buf), "%d", gib_list_length(filelist)); + strcat(ret, buf); + break; + case 'm': + strcat(ret, mode); + break; case 'n': if (file) strcat(ret, file->name); @@ -446,38 +459,39 @@ char *feh_printf(char *str, feh_file * file) if (file) strcat(ret, shell_escape(file->name)); break; - case 'w': - if (file && (file->info || !feh_file_info_load(file, NULL))) { - snprintf(buf, sizeof(buf), "%d", file->info->width); + case 'o': + if (winwid) { + snprintf(buf, sizeof(buf), "%d,%d", winwid->im_x, + winwid->im_y); strcat(ret, buf); } break; - case 'h': + case 'p': if (file && (file->info || !feh_file_info_load(file, NULL))) { - snprintf(buf, sizeof(buf), "%d", file->info->height); + snprintf(buf, sizeof(buf), "%d", file->info->pixels); strcat(ret, buf); } break; - case 's': + case 'P': if (file && (file->info || !feh_file_info_load(file, NULL))) { - snprintf(buf, sizeof(buf), "%d", file->info->size); - strcat(ret, buf); + strcat(ret, format_size(file->info->pixels)); } break; - case 'S': - if (file && (file->info || !feh_file_info_load(file, NULL))) { - strcat(ret, format_size(file->info->size)); + case 'r': + if (winwid) { + snprintf(buf, sizeof(buf), "%.1f", winwid->im_angle); + strcat(ret, buf); } break; - case 'p': + case 's': if (file && (file->info || !feh_file_info_load(file, NULL))) { - snprintf(buf, sizeof(buf), "%d", file->info->pixels); + snprintf(buf, sizeof(buf), "%d", file->info->size); strcat(ret, buf); } break; - case 'P': + case 'S': if (file && (file->info || !feh_file_info_load(file, NULL))) { - strcat(ret, format_size(file->info->pixels)); + strcat(ret, format_size(file->info->size)); } break; case 't': @@ -485,22 +499,27 @@ char *feh_printf(char *str, feh_file * file) strcat(ret, file->info->format); } break; - case 'v': - strcat(ret, VERSION); - break; - case 'm': - strcat(ret, mode); - break; - case 'l': - snprintf(buf, sizeof(buf), "%d", gib_list_length(filelist)); - strcat(ret, buf); - break; case 'u': snprintf(buf, sizeof(buf), "%d", current_file != NULL ? gib_list_num(filelist, current_file) + 1 : 0); strcat(ret, buf); break; + case 'v': + strcat(ret, VERSION); + break; + case 'w': + if (file && (file->info || !feh_file_info_load(file, NULL))) { + snprintf(buf, sizeof(buf), "%d", file->info->width); + strcat(ret, buf); + } + break; + case 'z': + if (winwid) { + snprintf(buf, sizeof(buf), "%.2f", winwid->zoom); + strcat(ret, buf); + } + break; case '%': strcat(ret, "%"); break; @@ -542,7 +561,7 @@ void feh_filelist_image_remove(winwidget winwid, char do_delete) winwidget_destroy(winwid); return; } - s = slideshow_create_name(FEH_FILE(winwid->file->data)); + s = slideshow_create_name(FEH_FILE(winwid->file->data), winwid); winwidget_rename(winwid, s); free(s); winwidget_render_image(winwid, 1, 0); diff --git a/src/thumbnail.c b/src/thumbnail.c index f276592..b26dc7f 100644 --- a/src/thumbnail.c +++ b/src/thumbnail.c @@ -169,7 +169,7 @@ void init_thumbnail_mode(void) if (!opt.title) s = estrdup(PACKAGE " [thumbnail mode]"); else - s = estrdup(feh_printf(opt.title, NULL)); + s = estrdup(feh_printf(opt.title, NULL, NULL)); if (opt.display) { winwid = winwidget_create_from_image(td.im_main, s, WIN_TYPE_THUMBNAIL); @@ -717,7 +717,7 @@ void feh_thumbnail_show_fullsize(feh_file *thumbfile) if (!opt.thumb_title) s = thumbfile->name; else - s = feh_printf(opt.thumb_title, thumbfile); + s = feh_printf(opt.thumb_title, thumbfile, NULL); thumbwin = winwidget_get_first_window_of_type(WIN_TYPE_THUMBNAIL_VIEWER); if (!thumbwin) { -- cgit v1.2.3