From 5e4ab352ecb523002221624ed71fb6bf4366c862 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Thu, 8 Sep 2011 00:23:02 +0200 Subject: Show page number in X11 viewer upon 'P' keypress. --- apps/x11_main.c | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 62 insertions(+), 6 deletions(-) (limited to 'apps/x11_main.c') diff --git a/apps/x11_main.c b/apps/x11_main.c index c2aef917..1b45c5ec 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -61,6 +61,8 @@ extern void ximage_blit(Drawable d, GC gc, int dstx, int dsty, unsigned char *srcdata, int srcx, int srcy, int srcw, int srch, int srcstride); +void windrawstringxor(pdfapp_t *app, int x, int y, char *s); + static Display *xdpy; static Atom XA_TARGETS; static Atom XA_TIMESTAMP; @@ -90,6 +92,7 @@ static char *filename; static pdfapp_t gapp; static int closing = 0; static int reloading = 0; +static int showingpage = 0; /* * Dialog boxes @@ -358,6 +361,13 @@ static void winblit(pdfapp_t *app) } winblitsearch(app); + + if (showingpage) + { + char buf[42]; + snprintf(buf, sizeof buf, "Page %d/%d", gapp.pageno, gapp.pagecount); + windrawstringxor(&gapp, 10, 20, buf); + } } void winrepaint(pdfapp_t *app) @@ -388,8 +398,6 @@ void windrawstringxor(pdfapp_t *app, int x, int y, char *s) XGetGCValues(xdpy, xgc, GCFunction, &xgcv); xgcv.function = prevfunction; XChangeGC(xdpy, xgc, GCFunction, &xgcv); - - printf("drawstring '%s'\n", s); } void windrawstring(pdfapp_t *app, int x, int y, char *s) @@ -509,6 +517,13 @@ static void onkey(int c) winrepaint(&gapp); } + if (c == 'P') + { + showingpage = 1; + winrepaint(&gapp); + return; + } + pdfapp_onkey(&gapp, c); } @@ -554,6 +569,10 @@ int main(int argc, char **argv) fd_set fds; int width = -1; int height = -1; + struct timeval tmo_at; + struct timeval now; + struct timeval tmo; + struct timeval *timeout; while ((c = fz_getopt(argc, argv, "p:r:b:A")) != -1) { @@ -598,13 +617,15 @@ int main(int argc, char **argv) pdfapp_open(&gapp, filename, fd, 0); FD_ZERO(&fds); - FD_SET(x11fd, &fds); signal(SIGHUP, signal_handler); + tmo_at.tv_sec = 0; + tmo_at.tv_usec = 0; + while (!closing) { - do + while (!closing && XPending(xdpy)) { XNextEvent(xdpy, &xevt); @@ -693,7 +714,6 @@ int main(int argc, char **argv) break; } } - while (!closing && XPending(xdpy)); if (closing) continue; @@ -715,10 +735,38 @@ int main(int argc, char **argv) dirtysearch = 0; } + 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)) continue; - if (select(x11fd + 1, &fds, NULL, NULL, NULL) < 0) + 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; + } + + FD_SET(x11fd, &fds); + if (select(x11fd + 1, &fds, NULL, NULL, timeout) < 0) { if (reloading) { @@ -726,6 +774,14 @@ int main(int argc, char **argv) reloading = 0; } } + if (!FD_ISSET(x11fd, &fds)) + { + tmo_at.tv_sec = 0; + tmo_at.tv_usec = 0; + timeout = NULL; + showingpage = 0; + winrepaint(&gapp); + } } pdfapp_close(&gapp); -- cgit v1.2.3 From 0d82bc58cd51f92c3806f9cfdf0d601f9e1a42e7 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 2 Oct 2011 13:52:21 +0200 Subject: Ask for screen resolution in X11 viewer. Based on a patch by Zhihao Yuan . --- apps/x11_main.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'apps/x11_main.c') diff --git a/apps/x11_main.c b/apps/x11_main.c index 1b45c5ec..b8f041cf 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -214,6 +214,12 @@ void winclose(pdfapp_t *app) closing = 1; } +static int winresolution() +{ + return DisplayWidth(xdpy, xscr) * 25.4 / + DisplayWidthMM(xdpy, xscr) + 0.5; +} + void wincursor(pdfapp_t *app, int curs) { if (curs == ARROW) @@ -562,7 +568,7 @@ int main(int argc, char **argv) KeySym keysym; int oldx = 0; int oldy = 0; - int resolution = 72; + int resolution = -1; int pageno = 1; int accelerate = 1; int fd; @@ -586,11 +592,6 @@ int main(int argc, char **argv) } } - if (resolution < MINRES) - resolution = MINRES; - if (resolution > MAXRES) - resolution = MAXRES; - if (argc - fz_optind == 0) usage(); @@ -604,6 +605,13 @@ int main(int argc, char **argv) winopen(); + if (resolution == -1) + resolution = winresolution(); + if (resolution < MINRES) + resolution = MINRES; + if (resolution > MAXRES) + resolution = MAXRES; + pdfapp_init(&gapp); gapp.scrw = DisplayWidth(xdpy, xscr); gapp.scrh = DisplayHeight(xdpy, xscr); -- cgit v1.2.3 From 4ff408357b4584a84bc450a765fe11e7a52e8f00 Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Sun, 2 Oct 2011 14:11:59 +0200 Subject: Default to opening URIs with xdg-open instead of open in X11 viewer. Based on a patch by Zhihao Yuan . --- apps/x11_main.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'apps/x11_main.c') diff --git a/apps/x11_main.c b/apps/x11_main.c index b8f041cf..6d8e789e 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -510,7 +510,13 @@ void winopenuri(pdfapp_t *app, char *buf) { char *browser = getenv("BROWSER"); if (!browser) + { +#ifdef __APPLE__ browser = "open"; +#else + browser = "xdg-open"; +#endif + } if (fork() == 0) execlp(browser, browser, buf, (char*)0); } -- cgit v1.2.3 From 8be6412105a3c0b9a255b6a89ae164c91d3519de Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Mon, 3 Oct 2011 00:34:27 +0200 Subject: Make entering search terms not interfere with page number drawing. --- apps/x11_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'apps/x11_main.c') diff --git a/apps/x11_main.c b/apps/x11_main.c index 6d8e789e..a2d36ac5 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -529,7 +529,7 @@ static void onkey(int c) winrepaint(&gapp); } - if (c == 'P') + if (!gapp.isediting && c == 'P') { showingpage = 1; winrepaint(&gapp); -- cgit v1.2.3