X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=moebius2.git;a=blobdiff_plain;f=view.c;fp=view.c;h=abecc7ca4d5fc206532f00d3f7c33dfe41281b78;hp=1ce6db66d492867a869ed833b2a9e9c6931067a8;hb=134d36d51a86567bba2a9cfe1b209c4bc7d1a7f0;hpb=512fa4d69efa3f71c61a581c137ee6da2a9bf2f9 diff --git a/view.c b/view.c index 1ce6db6..abecc7c 100644 --- a/view.c +++ b/view.c @@ -5,6 +5,10 @@ #include #include +#include +#include +#include + #include "mgraph.h" #define MAXTRIS (N*2) @@ -18,16 +22,21 @@ static Vertices conformation; static double transform[D3][D3]= {{1,0,0}, {0,1,0}, {0,0,1}}; static GSL_MATRIX(transform); -const char *input_filename; +static FILE *input_f; +static struct stat input_stab; +static const char *input_filename; static void read_input(void) { - FILE *f; int r; - f= fopen(input_filename, "rb"); if (!f) diee("input file"); + if (input_f) fclose(input_f); + input_f= fopen(input_filename, "rb"); if (!input_f) diee("input file"); + + if (fstat(fileno(input_f), &input_stab)) diee("fstat input file"); + errno= 0; - r= fread(&conformation,sizeof(conformation),1,f); if (r!=1) diee("fread"); - fclose(f); + r= fread(&conformation,sizeof(conformation),1,input_f); + if (r!=1) diee("fread"); } static void transform_coordinates(void) { @@ -468,9 +477,31 @@ static void event_config(XConfigureEvent *e) { show(); } +static void check_input(void) { + struct stat newstab; + int r; + + r= stat(input_filename, &newstab); + if (r<0) diee("could not check input"); + +#define CI(x) if (newstab.st_##x == input_stab.st_##x) ; else goto changed + CI(dev); + CI(ino); + CI(size); + CI(mtime); +#undef CI + return; + + changed: + show(); +} + int main(int argc, const char *const *argv) { + static const int wantedevents= POLLIN|POLLPRI|POLLERR|POLLHUP; + XEvent event; - int k; + int k, i, r, *xfds, nxfds, polls_alloc=0; + struct pollfd *polls=0; int motion_deferred=0, motion_x=-1, motion_y=-1; if (argc != 2 || argv[1][0]=='-') { @@ -485,16 +516,40 @@ int main(int argc, const char *const *argv) { XMapWindow(display,window); for (;;) { - if (motion_deferred) { - int r= XCheckMaskEvent(display,~0UL,&event); - if (!r) { + + XA( XInternalConnectionNumbers(display, &xfds, &nxfds) ); + if (polls_alloc <= nxfds) { + polls_alloc= nxfds + polls_alloc + 1; + polls= realloc(polls, sizeof(*polls) * polls_alloc); + if (!polls) diee("realloc for pollfds"); + } + for (i=0; i