diff options
author | Gerd Hoffmann <kraxel@redhat.com> | 2016-03-30 17:00:15 +0200 |
---|---|---|
committer | Gerd Hoffmann <kraxel@redhat.com> | 2016-03-30 17:00:15 +0200 |
commit | 5afc00bbda22ee56de460a8a7e530c50110b8ab2 (patch) | |
tree | 730ee4b33e5f38a41ed589e8f55b5077aa17125a | |
parent | 6b54359f371edab9f6165757aabcfe823b77ccd4 (diff) | |
download | fbida-5afc00bbda22ee56de460a8a7e530c50110b8ab2.tar.gz |
cmd line args
-rw-r--r-- | GNUmakefile | 3 | ||||
-rw-r--r-- | drmtools.c | 2 | ||||
-rw-r--r-- | fbiconfig.c | 59 | ||||
-rw-r--r-- | fbiconfig.h | 2 | ||||
-rw-r--r-- | fbpdf.c | 110 |
5 files changed, 163 insertions, 13 deletions
diff --git a/GNUmakefile b/GNUmakefile index a6ba6b6..abfaded 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -192,7 +192,8 @@ fbi: $(OBJS_FBI) $(OBJS_READER) # object files OBJS_FBPDF := \ - fbpdf.o vt.o kbd.o fbtools.o drmtools.o + fbpdf.o vt.o kbd.o fbtools.o drmtools.o \ + fbiconfig.o parseconfig.o # font + drm + jpeg/exif libs fbpdf : CFLAGS += $(shell $(PKG_CONFIG) --cflags libdrm poppler-glib) @@ -255,6 +255,8 @@ gfxstate *drm_init(const char *device, const char *output, bool pageflip) if (pageflip) { if (drm_init_fb(&fb2) == 0) { gfx->mem2 = fb2.mem; + } else { + fprintf(stderr, "drm: can't alloc two fbs, pageflip disabled.\n"); } } return gfx; diff --git a/fbiconfig.c b/fbiconfig.c index f67850b..460c46a 100644 --- a/fbiconfig.c +++ b/fbiconfig.c @@ -68,6 +68,7 @@ struct cfg_cmdline fbi_cfg[] = { .yesno = 1, .desc = " like the above, but downscale only", },{ + .letter = 'w', .cmdline = "fitwidth", .option = { O_FIT_WIDTH }, .yesno = 1, @@ -184,12 +185,68 @@ struct cfg_cmdline fbi_cfg[] = { /* ------------------------------------------------------------------------ */ +struct cfg_cmdline fbpdf_cmd[] = { + { + .letter = 'h', + .cmdline = "help", + .option = { O_HELP }, + .value = "1", + .desc = "print this help text", + },{ + .letter = 'V', + .cmdline = "version", + .option = { O_VERSION }, + .value = "1", + .desc = "print fbi version number", + },{ + .letter = 'i', + .cmdline = "info", + .option = { O_DEVICE_INFO }, + .value = "1", + .desc = "print device info", + },{ + /* end of list */ + } +}; + +struct cfg_cmdline fbpdf_cfg[] = { + { + .letter = 'w', + .cmdline = "fitwidth", + .option = { O_FIT_WIDTH }, + .yesno = 1, + .desc = "fit page width on screen", + },{ + .letter = 'd', + .cmdline = "device", + .option = { O_DEVICE }, + .needsarg = 1, + .desc = "use framebuffer/drm device <arg>", + },{ + .letter = 'o', + .cmdline = "output", + .option = { O_OUTPUT }, + .needsarg = 1, + .desc = "use drm output <arg> (try -info for a list)", + },{ + .letter = 'm', + .cmdline = "mode", + .option = { O_VIDEO_MODE }, + .needsarg = 1, + .desc = "use video mode <arg> (from /etc/fb.modes)", + },{ + /* end of list */ + } +}; + +/* ------------------------------------------------------------------------ */ + static char *fbi_config = NULL; static void init_config(void) { char *home; - + home = getenv("HOME"); if (NULL == home) return; diff --git a/fbiconfig.h b/fbiconfig.h index 9a8c058..f5e0c03 100644 --- a/fbiconfig.h +++ b/fbiconfig.h @@ -67,6 +67,8 @@ extern struct cfg_cmdline fbi_cmd[]; extern struct cfg_cmdline fbi_cfg[]; +extern struct cfg_cmdline fbpdf_cmd[]; +extern struct cfg_cmdline fbpdf_cfg[]; void fbi_read_config(void); void fbi_write_config(void); @@ -36,15 +36,24 @@ #include "kbd.h" #include "fbtools.h" #include "drmtools.h" +#include "fbiconfig.h" /* ---------------------------------------------------------------------- */ +/* options */ +int fitwidth; +char *device; +char *output; +char *mode; + +/* gfx output state */ gfxstate *gfx; int debug; PopplerDocument *doc; cairo_surface_t *surface1; cairo_surface_t *surface2; +/* pdf render state */ PopplerPage *page; double pw, ph; /* pdf page size */ double scale; @@ -192,32 +201,110 @@ static void console_switch_redraw(void) gfx->restore_display(); } +static void +version(void) +{ + fprintf(stdout, + "fbpdf version " VERSION "\n" + "(c) 1998-2016 Gerd Hoffmann <gerd@kraxel.org>\n"); +} + +static void +usage(FILE *fp, char *name) +{ + char *h; + + if (NULL != (h = strrchr(name, '/'))) + name = h+1; + fprintf(fp, + "\n" + "This program displays pfd files using the Linux fbdev or drm device.\n" + "\n" + "usage: %s [ options ] pdf-file\n" + "\n", + name); + + cfg_help_cmdline(fp,fbpdf_cmd,4,20,0); + cfg_help_cmdline(fp,fbpdf_cfg,4,20,40); + + fprintf(fp, + "\n"); +} + int main(int argc, char *argv[]) { GError *err = NULL; bool framebuffer = false; bool quit, newpage; + char cwd[1024]; + char uri[1024]; char key[32]; uint32_t keycode, keymod; int index = 0; setlocale(LC_ALL,""); - if (argc < 2) { - fprintf(stderr, "usage: %s <pdf-file>\n", argv[0]); + fbi_read_config(); + cfg_parse_cmdline(&argc,argv,fbi_cmd); + cfg_parse_cmdline(&argc,argv,fbi_cfg); + + if (GET_HELP()) { + usage(stdout, argv[0]); + exit(0); + } + if (GET_VERSION()) { + version(); + exit(0); + } + if (GET_DEVICE_INFO()) { + drm_info(cfg_get_str(O_DEVICE)); + exit(0); + } + + if (optind+1 != argc ) { + fprintf(stderr, "usage: %s [ options ] <pdf-file>\n", argv[0]); exit(1); } - doc = poppler_document_new_from_file(argv[1], NULL, &err); + + /* filename -> uri */ + if (strncmp(argv[optind], "file:/", 6) == 0) { + /* is uri already */ + snprintf(uri, sizeof(uri), "%s", argv[optind]); + } else if (strncmp(argv[optind], "/", 1) == 0) { + /* absolute path */ + snprintf(uri, sizeof(uri), "file:%s", argv[optind]); + } else { + /* relative path */ + getcwd(cwd, sizeof(cwd)); + snprintf(uri, sizeof(uri), "file:%s/%s", cwd, argv[optind]); + } + doc = poppler_document_new_from_file(uri, NULL, &err); if (!doc) { - fprintf(stderr, "loading %s failed: %s\n", argv[1], err->message); + fprintf(stderr, "loading %s failed: %s\n", uri, err->message); exit(1); } /* gfx init */ - gfx = drm_init(NULL, NULL, true); - if (!gfx) { - framebuffer = true; - gfx = fb_init(NULL, NULL, 0); + device = cfg_get_str(O_DEVICE); + output = cfg_get_str(O_OUTPUT); + mode = cfg_get_str(O_VIDEO_MODE); + fitwidth = GET_FIT_WIDTH(); + + if (device) { + /* device specified */ + if (strncmp(device, "/dev/d", 6) == 0) { + gfx = drm_init(device, output, true); + } else { + framebuffer = true; + gfx = fb_init(device, mode, GET_VT()); + } + } else { + /* try drm first, failing that fb */ + gfx = drm_init(NULL, output, true); + if (!gfx) { + framebuffer = true; + gfx = fb_init(NULL, mode, GET_VT()); + } } if (!gfx) { fprintf(stderr, "graphics init failed\n"); @@ -255,10 +342,11 @@ int main(int argc, char *argv[]) for (quit = false; !quit;) { if (newpage) { page = poppler_document_get_page(doc, index); - if (0) - page_fit(); - if (1) + if (fitwidth) { page_fit_width(); + } else { + page_fit(); + } newpage = false; } page_render(); |