diff options
author | Sebastian Rasmussen <sebras@gmail.com> | 2011-09-04 04:35:47 +0200 |
---|---|---|
committer | Sebastian Rasmussen <sebras@gmail.com> | 2011-09-04 12:35:23 +0200 |
commit | 4c43949022e7282964a1e3d1b462ebe8664a9eb8 (patch) | |
tree | 8797df85e0cbd40bfc6577cff2d3c2196ff0eac8 /apps | |
parent | 1a33244d367cfbc21d005c068f468ea18fd1b28b (diff) | |
download | mupdf-4c43949022e7282964a1e3d1b462ebe8664a9eb8.tar.xz |
Reload file in X11 viewer upon SIGHUP.
Diffstat (limited to 'apps')
-rw-r--r-- | apps/x11_main.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/apps/x11_main.c b/apps/x11_main.c index 2a42124b..c2aef917 100644 --- a/apps/x11_main.c +++ b/apps/x11_main.c @@ -12,6 +12,7 @@ #include <sys/time.h> #include <sys/types.h> #include <unistd.h> +#include <signal.h> #define mupdf_icon_bitmap_16_width 16 #define mupdf_icon_bitmap_16_height 16 @@ -88,6 +89,7 @@ static char *filename; static pdfapp_t gapp; static int closing = 0; +static int reloading = 0; /* * Dialog boxes @@ -521,6 +523,12 @@ static void onmouse(int x, int y, int btn, int modifiers, int state) pdfapp_onmouse(&gapp, x, y, btn, modifiers, state); } +static void signal_handler(int signal) +{ + if (signal == SIGHUP) + reloading = 1; +} + static void usage(void) { fprintf(stderr, "usage: mupdf [options] file.pdf [page]\n"); @@ -543,6 +551,7 @@ int main(int argc, char **argv) int pageno = 1; int accelerate = 1; int fd; + fd_set fds; int width = -1; int height = -1; @@ -588,7 +597,11 @@ int main(int argc, char **argv) pdfapp_open(&gapp, filename, fd, 0); - closing = 0; + FD_ZERO(&fds); + FD_SET(x11fd, &fds); + + signal(SIGHUP, signal_handler); + while (!closing) { do @@ -701,6 +714,18 @@ int main(int argc, char **argv) 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); |