int main(int argc, char **argv) { int c; int len; char buf[128]; KeySym keysym; int oldx = 0; int oldy = 0; int resolution = -1; int pageno = 1; fd_set fds; int width = -1; int height = -1; fz_context *ctx; struct timeval tmo_at; struct timeval now; struct timeval tmo; struct timeval *timeout; struct timeval tmo_advance_delay; ctx = fz_new_context(NULL, NULL, FZ_STORE_DEFAULT); if (!ctx) { fprintf(stderr, "cannot initialise context\n"); exit(1); } while ((c = fz_getopt(argc, argv, "p:r:b:")) != -1) { switch (c) { case 'p': password = fz_optarg; break; case 'r': resolution = atoi(fz_optarg); break; case 'b': fz_set_aa_level(ctx, atoi(fz_optarg)); break; default: usage(); } } if (argc - fz_optind == 0) usage(); filename = argv[fz_optind++]; if (argc - fz_optind == 1) pageno = atoi(argv[fz_optind++]); pdfapp_init(ctx, &gapp); winopen(); if (resolution == -1) resolution = winresolution(); if (resolution < MINRES) resolution = MINRES; if (resolution > MAXRES) resolution = MAXRES; gapp.transitions_enabled = 1; gapp.scrw = DisplayWidth(xdpy, xscr); gapp.scrh = DisplayHeight(xdpy, xscr); gapp.resolution = resolution; gapp.pageno = pageno; pdfapp_open(&gapp, filename, 0); FD_ZERO(&fds); signal(SIGHUP, signal_handler); tmo_at.tv_sec = 0; tmo_at.tv_usec = 0; while (!closing) { while (!closing && XPending(xdpy) && !transition_dirty) { XNextEvent(xdpy, &xevt); switch (xevt.type) { case Expose: dirty = 1; break; case ConfigureNotify: if (gapp.image) { if (xevt.xconfigure.width != reqw || xevt.xconfigure.height != reqh) gapp.shrinkwrap = 0; } width = xevt.xconfigure.width; height = xevt.xconfigure.height; break; case KeyPress: len = XLookupString(&xevt.xkey, buf, sizeof buf, &keysym, NULL); if (!gapp.isediting) switch (keysym) { case XK_Escape: len = 1; buf[0] = '\033'; break; case XK_Up: len = 1; buf[0] = 'k'; break; case XK_Down: len = 1; buf[0] = 'j'; break; case XK_Left: len = 1; buf[0] = 'b'; break; case XK_Right: len = 1; buf[0] = ' '; break; case XK_Page_Up: len = 1; buf[0] = ','; break; case XK_Page_Down: len = 1; buf[0] = '.'; break; } if (xevt.xkey.state & ControlMask && keysym == XK_c) docopy(&gapp, XA_CLIPBOARD); else if (len) onkey(buf[0]); onmouse(oldx, oldy, 0, 0, 0); break; case MotionNotify: oldx = xevt.xmotion.x; oldy = xevt.xmotion.y; onmouse(xevt.xmotion.x, xevt.xmotion.y, 0, xevt.xmotion.state, 0); break; case ButtonPress: onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 1); break; case ButtonRelease: copytime = xevt.xbutton.time; onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, -1); break; case SelectionRequest: onselreq(xevt.xselectionrequest.requestor, xevt.xselectionrequest.selection, xevt.xselectionrequest.target, xevt.xselectionrequest.property, xevt.xselectionrequest.time); break; case ClientMessage: if (xevt.xclient.format == 32 && xevt.xclient.data.l[0] == WM_DELETE_WINDOW) closing = 1; break; } } if (closing) continue; if (width != -1 || height != -1) { pdfapp_onresize(&gapp, width, height); width = -1; height = -1; } if (dirty || dirtysearch) { if (dirty) winblit(&gapp); else if (dirtysearch) winblitsearch(&gapp); dirty = 0; transition_dirty = 0; dirtysearch = 0; pdfapp_postblit(&gapp); } if (showingpage && !tmo_at.tv_sec && !tmo_at.tv_usec) { tmo.tv_sec = 2; tmo.tv_usec = 0; gettimeofday(&now, NULL); timeradd(&now, &tmo, &tmo_at); } if (XPending(xdpy) || transition_dirty) continue; timeout = NULL; if (tmo_at.tv_sec || tmo_at.tv_usec) { gettimeofday(&now, NULL); timersub(&tmo_at, &now, &tmo); if (tmo.tv_sec <= 0) { tmo_at.tv_sec = 0; tmo_at.tv_usec = 0; timeout = NULL; showingpage = 0; winrepaint(&gapp); } else timeout = &tmo; } if (advance_scheduled) { gettimeofday(&now, NULL); timersub(&tmo_advance, &now, &tmo_advance_delay); if (tmo_advance_delay.tv_sec <= 0) { /* Too late already */ onkey(' '); onmouse(oldx, oldy, 0, 0, 0); advance_scheduled = 0; } else if (timeout == NULL) { timeout = &tmo_advance_delay; } else { struct timeval tmp; timersub(&tmo_advance_delay, timeout, &tmp); if (tmp.tv_sec < 0) { timeout = &tmo_advance_delay; } } } FD_SET(x11fd, &fds); if (select(x11fd + 1, &fds, NULL, NULL, timeout) < 0) { if (reloading) { winreloadfile(&gapp); reloading = 0; } } if (!FD_ISSET(x11fd, &fds)) { if (timeout == &tmo_advance_delay) { onkey(' '); onmouse(oldx, oldy, 0, 0, 0); advance_scheduled = 0; } else { tmo_at.tv_sec = 0; tmo_at.tv_usec = 0; timeout = NULL; showingpage = 0; winrepaint(&gapp); } } } cleanup(&gapp); return 0; }
int main(int argc, char **argv) { char *filename; int c; int len; unsigned char buf[128]; KeySym keysym; int oldx = 0; int oldy = 0; double zoom = 1.0; int pageno = 1; while ((c = getopt(argc, argv, "d:z:p:")) != -1) { switch (c) { case 'd': password = optarg; break; case 'z': zoom = atof(optarg); break; case 'p': pageno = atoi(optarg); break; default: usage(); } } if (argc - optind == 0) usage(); filename = argv[optind++]; fz_cpudetect(); fz_accelerate(); winopen(); pdfapp_init(&gapp); gapp.scrw = DisplayWidth(xdpy, xscr); gapp.scrh = DisplayHeight(xdpy, xscr); gapp.zoom = zoom; gapp.pageno = pageno; pdfapp_open(&gapp, filename); while (1) { do { XNextEvent(xdpy, &xevt); switch (xevt.type) { case Expose: dirty = 1; break; case ConfigureNotify: if (gapp.image) { if (xevt.xconfigure.width != reqw || xevt.xconfigure.height != reqh) gapp.shrinkwrap = 0; } pdfapp_onresize(&gapp, xevt.xconfigure.width, xevt.xconfigure.height); break; case KeyPress: len = XLookupString(&xevt.xkey, buf, sizeof buf, &keysym, 0); if (len) onkey(buf[0]); onmouse(oldx, oldy, 0, 0, 0); if (dirty) { winblit(&gapp); dirty = 0; } break; case MotionNotify: oldx = xevt.xbutton.x; oldy = xevt.xbutton.y; onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 0); break; case ButtonPress: onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 1); break; case ButtonRelease: copytime = xevt.xbutton.time; onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, -1); break; case SelectionRequest: onselreq(xevt.xselectionrequest.requestor, xevt.xselectionrequest.selection, xevt.xselectionrequest.target, xevt.xselectionrequest.property, xevt.xselectionrequest.time); break; } } while (XPending(xdpy)); if (dirty) { winblit(&gapp); dirty = 0; } } pdfapp_close(&gapp); return 0; }
int main(int argc, char **argv) { char *filename; int c; int len; char buf[128]; KeySym keysym; int oldx = 0; int oldy = 0; int zoom = 100; int pageno = 1; int wasshowingpage; struct timeval tmo, tmo_at; while ((c = fz_getopt(argc, argv, "d:z:p:")) != -1) { switch (c) { case 'd': password = fz_optarg; break; case 'z': zoom = atoi(fz_optarg); break; case 'p': pageno = atoi(fz_optarg); break; default: usage(); } } if (zoom < 100) zoom = 100; if (zoom > 300) zoom = 300; if (argc - fz_optind == 0) usage(); filename = argv[fz_optind++]; fz_cpudetect(); fz_accelerate(); winopen(); pdfapp_init(&gapp); gapp.scrw = DisplayWidth(xdpy, xscr); gapp.scrh = DisplayHeight(xdpy, xscr); gapp.zoom = zoom / 100.0; gapp.pageno = pageno; pdfapp_open(&gapp, filename); winresettmo(&tmo, &tmo_at); while (1) { do { winawaitevent(&tmo, &tmo_at); if (tmo_at.tv_sec != 0 && tmo_at.tv_usec != 0 && tmo.tv_sec == 0 && tmo.tv_usec == 0) { /* redraw page */ winblit(&gapp); isshowingpage = 0; winresettmo(&tmo, &tmo_at); continue; } switch (xevt.type) { case Expose: dirty = 1; break; case ConfigureNotify: if (gapp.image) { if (xevt.xconfigure.width != reqw || xevt.xconfigure.height != reqh) gapp.shrinkwrap = 0; } pdfapp_onresize(&gapp, xevt.xconfigure.width, xevt.xconfigure.height); break; case KeyPress: wasshowingpage = isshowingpage; len = XLookupString(&xevt.xkey, buf, sizeof buf, &keysym, nil); if (len) onkey(buf[0]); onmouse(oldx, oldy, 0, 0, 0); if (dirty) { winblit(&gapp); dirty = 0; if (isshowingpage) { isshowingpage = 0; winresettmo(&tmo, &tmo_at); } } if (!wasshowingpage && isshowingpage) winsettmo(&tmo, &tmo_at); break; case MotionNotify: oldx = xevt.xbutton.x; oldy = xevt.xbutton.y; onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 0); break; case ButtonPress: onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 1); break; case ButtonRelease: copytime = xevt.xbutton.time; onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, -1); break; case SelectionRequest: onselreq(xevt.xselectionrequest.requestor, xevt.xselectionrequest.selection, xevt.xselectionrequest.target, xevt.xselectionrequest.property, xevt.xselectionrequest.time); break; } } while (XPending(xdpy)); if (dirty) { winblit(&gapp); dirty = 0; if (isshowingpage) { isshowingpage = 0; winresettmo(&tmo, &tmo_at); } } } pdfapp_close(&gapp); return 0; }
int main(int argc, char **argv) { int c; int len; char buf[128]; KeySym keysym; int oldx = 0; int oldy = 0; int resolution = 72; int pageno = 1; int pagemark = 0; int accelerate = 1; int fd; fd_set fds; int width = -1; int height = -1; while ((c = fz_getopt(argc, argv, "p:r:b:A")) != -1) { switch (c) { case 'p': password = fz_optarg; break; case 'r': resolution = atoi(fz_optarg); break; case 'A': accelerate = 0; break; case 'b': fz_set_aa_level(atoi(fz_optarg)); break; default: usage(); } } if (resolution < MINRES) resolution = MINRES; if (resolution > MAXRES) resolution = MAXRES; if (argc - fz_optind == 0) usage(); if (accelerate) fz_accelerate(); filename = argv[fz_optind++]; winopen(); pdfapp_init(&gapp); gapp.scrw = DisplayWidth(xdpy, xscr); gapp.scrh = DisplayHeight(xdpy, xscr); gapp.resolution = resolution; if (argc - fz_optind > 1) pageno = atoi(argv[fz_optind++]); gapp.pageno = pageno; fd = open(filename, O_BINARY | O_RDONLY, 0666); if (fd < 0) winerror(&gapp, fz_throw("cannot open file '%s'", filename)); pdfapp_open(&gapp, filename, fd, 0); if (pdfapp_calcfilehash(&gapp, fd)) { pdfapp_getmarkfile(&gapp); pagemark = pdfapp_getpgmark(&gapp); if (pagemark > 0) { if (pagemark <= gapp.pagecount) { gapp.pageno = pagemark; pdfapp_showpage(&gapp, 1, 1, 1); } else pdfapp_closemarkfile(&gapp); } } FD_ZERO(&fds); FD_SET(x11fd, &fds); signal(SIGHUP, signal_handler); atexit(exit_cb); while (!closing) { do { XNextEvent(xdpy, &xevt); switch (xevt.type) { case Expose: dirty = 1; break; case ConfigureNotify: if (gapp.image) { if (xevt.xconfigure.width != reqw || xevt.xconfigure.height != reqh) gapp.shrinkwrap = 0; } width = xevt.xconfigure.width; height = xevt.xconfigure.height; break; case KeyPress: len = XLookupString(&xevt.xkey, buf, sizeof buf, &keysym, NULL); if (!gapp.isediting) switch (keysym) { case XK_Escape: len = 1; buf[0] = '\033'; break; case XK_Up: len = 1; buf[0] = 'k'; break; case XK_Down: len = 1; buf[0] = 'j'; break; case XK_Left: len = 1; buf[0] = 'b'; break; case XK_Right: len = 1; buf[0] = ' '; break; case XK_Page_Up: len = 1; buf[0] = ','; break; case XK_Page_Down: len = 1; buf[0] = '.'; break; } if (len) onkey(buf[0]); onmouse(oldx, oldy, 0, 0, 0); break; case MotionNotify: oldx = xevt.xbutton.x; oldy = xevt.xbutton.y; onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 0); break; case ButtonPress: onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, 1); break; case ButtonRelease: copytime = xevt.xbutton.time; onmouse(xevt.xbutton.x, xevt.xbutton.y, xevt.xbutton.button, xevt.xbutton.state, -1); break; case SelectionRequest: onselreq(xevt.xselectionrequest.requestor, xevt.xselectionrequest.selection, xevt.xselectionrequest.target, xevt.xselectionrequest.property, xevt.xselectionrequest.time); break; case ClientMessage: if (xevt.xclient.format == 32 && xevt.xclient.data.l[0] == WM_DELETE_WINDOW) closing = 1; break; } } while (!closing && XPending(xdpy)); if (closing) continue; if (width != -1 || height != -1) { pdfapp_onresize(&gapp, width, height); width = -1; height = -1; } if (dirty || dirtysearch) { if (dirty) winblit(&gapp); else if (dirtysearch) winblitsearch(&gapp); dirty = 0; dirtysearch = 0; } if (XPending(xdpy)) continue; if (select(x11fd + 1, &fds, NULL, NULL, NULL) < 0) { if (reloading) { winreloadfile(&gapp); reloading = 0; } } } pdfapp_close(&gapp); XDestroyWindow(xdpy, xwin); XFreePixmap(xdpy, xicon); XFreeCursor(xdpy, xcwait); XFreeCursor(xdpy, xchand); XFreeCursor(xdpy, xcarrow); XFreeGC(xdpy, xgc); XCloseDisplay(xdpy); return 0; }