diff options
author | Daniel Friesel <derf@finalrewind.org> | 2010-09-10 22:55:29 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2010-09-10 22:55:29 +0200 |
commit | 59742b2e0791402a88d1c1df397a8f843588b452 (patch) | |
tree | 58a2fc5c08921df74275ae78995d4dcccb11cf62 /src | |
parent | f59f4a09c12cc50f11031ed102de1c9b08efdafa (diff) |
Add --info option
Diffstat (limited to 'src')
-rw-r--r-- | src/feh.h | 1 | ||||
-rw-r--r-- | src/imlib.c | 79 | ||||
-rw-r--r-- | src/options.c | 4 | ||||
-rw-r--r-- | src/options.h | 1 | ||||
-rw-r--r-- | src/winwidget.c | 4 |
5 files changed, 89 insertions, 0 deletions
@@ -132,6 +132,7 @@ int feh_load_image_char(Imlib_Image * im, char *filename); void feh_draw_filename(winwidget w); void feh_draw_actions(winwidget w); void feh_draw_caption(winwidget w); +void feh_draw_info(winwidget w); void feh_display_status(char stat); void real_loadables_mode(int loadable); void feh_reload_image(winwidget w, int resize, int force_new); diff --git a/src/imlib.c b/src/imlib.c index 48bc4ea..672d65d 100644 --- a/src/imlib.c +++ b/src/imlib.c @@ -622,6 +622,85 @@ void feh_draw_filename(winwidget w) return; } +void feh_draw_info(winwidget w) +{ + static Imlib_Font fn = NULL; + int tw = 0, th = 0; + int tmp_tw = 0, tmp_th = 0; + Imlib_Image im = NULL; + static DATA8 atab[256]; + int no_lines = 0; + char *info_cmd; + char info_buf[256]; + FILE *info_pipe; + + if ((!w->file) || (!FEH_FILE(w->file->data)) + || (!FEH_FILE(w->file->data)->filename)) + return; + + if (opt.font) + fn = gib_imlib_load_font(opt.font); + + if (!fn) { + if (w->full_screen) + fn = gib_imlib_load_font(DEFAULT_FONT_BIG); + else + fn = gib_imlib_load_font(DEFAULT_FONT); + } + + if (!fn) { + weprintf("Couldn't load font for filename printing"); + return; + } + + info_cmd = feh_printf(opt.info_cmd, FEH_FILE(w->file->data)); + + memset(atab, 0, sizeof(atab)); + + gib_imlib_get_text_size(fn, "w", NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT); + + info_pipe = popen(info_cmd, "r"); + + im = imlib_create_image(290 * tw, 20 * th); + if (!im) + eprintf("Couldn't create image. Out of memory?"); + + gib_imlib_image_set_has_alpha(im, 1); + gib_imlib_apply_color_modifier_to_rectangle(im, 0, 0, 290 * tw, 20 * th, NULL, NULL, NULL, atab); + gib_imlib_image_fill_rectangle(im, 0, 0, 290 * tw, 20 * th, 0, 0, 0, 0); + + if (!info_pipe) { + gib_imlib_text_draw(im, fn, NULL, 2, 2, + "Error runnig info command", IMLIB_TEXT_TO_RIGHT, + 255, 0, 0, 255); + gib_imlib_get_text_size(fn, "Error running info command", NULL, &tw, &th, + IMLIB_TEXT_TO_RIGHT); + no_lines = 1; + } + else { + while ((no_lines < 20) && fgets(info_buf, 256, info_pipe)) { + info_buf[strlen(info_buf)-1] = '\0'; + gib_imlib_get_text_size(fn, "w", NULL, &tw, &th, IMLIB_TEXT_TO_RIGHT); + gib_imlib_text_draw(im, fn, NULL, 2, (no_lines*th)+2, info_buf, + IMLIB_TEXT_TO_RIGHT, 0, 0, 0, 255); + gib_imlib_text_draw(im, fn, NULL, 1, (no_lines*th)+1, info_buf, + IMLIB_TEXT_TO_RIGHT, 255, 255, 255, 255); + no_lines++; + gib_imlib_get_text_size(fn, info_buf, NULL, &tmp_tw, &tmp_th, IMLIB_TEXT_TO_RIGHT); + if (tmp_tw > tw) + tw = tmp_tw; + } + pclose(info_pipe); + } + + + gib_imlib_render_image_on_drawable(w->bg_pmap, im, w->w - tw - 5, w->h - + (th * no_lines) - 5, 1, 1, 0); + + gib_imlib_free_image_and_decache(im); + return; +} + char *build_caption_filename(feh_file * file) { char *caption_filename; diff --git a/src/options.c b/src/options.c index e2ccc74..182f3d8 100644 --- a/src/options.c +++ b/src/options.c @@ -423,6 +423,7 @@ static void feh_parse_option_array(int argc, char **argv) {"index-dim" , 1, 0, 232}, {"thumb-redraw" , 1, 0, 'J'}, {"action-hold-slide", 0, 0, 233}, + {"info" , 1, 0, 234}, {0, 0, 0, 0} }; @@ -772,6 +773,9 @@ static void feh_parse_option_array(int argc, char **argv) case 233: opt.action_hold_slide = 1; break; + case 234: + opt.info_cmd = estrdup(optarg); + break; default: break; } diff --git a/src/options.h b/src/options.h index e9595b7..5a187f4 100644 --- a/src/options.h +++ b/src/options.h @@ -88,6 +88,7 @@ struct __fehoptions { char *menu_style; char *caption_path; char *start_list_at; + char *info_cmd; gib_style *menu_style_l; diff --git a/src/winwidget.c b/src/winwidget.c index 771024b..855e0da 100644 --- a/src/winwidget.c +++ b/src/winwidget.c @@ -539,6 +539,8 @@ void winwidget_render_image(winwidget winwid, int resize, int alias) feh_draw_actions(winwid); if ((opt.mode == MODE_ZOOM) && !alias) feh_draw_zoom(winwid); + if (opt.info_cmd) + feh_draw_info(winwid); XSetWindowBackgroundPixmap(disp, winwid->win, winwid->bg_pmap); XClearWindow(disp, winwid->win); return; @@ -559,6 +561,8 @@ void winwidget_render_image_cached(winwidget winwid) feh_draw_filename(winwid); if (opt.draw_actions) feh_draw_actions(winwid); + if (opt.info_cmd) + feh_draw_info(winwid); XSetWindowBackgroundPixmap(disp, winwid->win, winwid->bg_pmap); XClearWindow(disp, winwid->win); } |