Exemple #1
0
static unsigned long
compass_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;
  XFillRectangle (st->dpy, st->b, st->erase_gc, 0, 0, st->xgwa.width, st->xgwa.height);

  draw_compass (st);
  draw_pointer (st);

#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
  if (st->backb)
    {
      XdbeSwapInfo info[1];
      info[0].swap_window = st->window;
      info[0].swap_action = XdbeUndefined;
      XdbeSwapBuffers (st->dpy, info, 1);
    }
  else
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
    if (st->dbuf)
      {
        XCopyArea (st->dpy, st->b, st->window, st->erase_gc, 0, 0,
                   st->size2, st->size2,
                   st->xgwa.width/2 - st->x,
                   st->xgwa.height/2 - st->y);
        st->b = (st->b == st->ba ? st->bb : st->ba);
      }

  return st->delay;
}
Exemple #2
0
static unsigned long
deluxe_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;
  int i;
#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
  if (!st->dbeclear_p || !st->backb)
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
    XFillRectangle (st->dpy, st->b, st->erase_gc, 0, 0, st->xgwa.width, st->xgwa.height);

  for (i = 0; i < st->count; i++)
    if (throb (st, st->b, st->throbbers[i]) < 0)
      st->throbbers[i] = make_throbber (st, st->b, st->xgwa.width, st->xgwa.height,
                                    st->colors[random() % st->ncolors].pixel);

#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
  if (st->backb)
    {
      XdbeSwapInfo info[1];
      info[0].swap_window = st->window;
      info[0].swap_action = (st->dbeclear_p ? XdbeBackground : XdbeUndefined);
      XdbeSwapBuffers (st->dpy, info, 1);
    }
  else
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
    if (st->dbuf)
      {
        XCopyArea (st->dpy, st->b, st->window, st->erase_gc, 0, 0,
                   st->xgwa.width, st->xgwa.height, 0, 0);
        st->b = (st->b == st->ba ? st->bb : st->ba);
      }

  return st->delay;
}
Exemple #3
0
static unsigned long
anemone_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;

    XFillRectangle (st->dpy, st->b, st->gcClear, 0, 0, st->scrWidth, st->scrHeight);

    animateAnemone(st, st->b);

#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
    if (st->backb)
      {
	XdbeSwapInfo info[1];
	info[0].swap_window = window;
	info[0].swap_action = XdbeUndefined;
	XdbeSwapBuffers (st->dpy, info, 1);
      }
    else
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
      if (st->dbuf)
	{
	  XCopyArea (st->dpy, st->b, window, st->gcClear, 0, 0,
		     st->scrWidth, st->scrHeight, 0, 0);
	  st->b = (st->b == st->ba ? st->bb : st->ba);
	}

    return st->delay;
}
void rebcmp_blit_region(REBCMP_CTX* ctx, Region reg)
{
	//RL_Print("rebcmp_blit_region, ctx: %x\n", ctx);
	XSetRegion(global_x_info->display, ctx->x_gc, reg);
	/*
	XRectangle rect;
	XClipBox(ctx->Win_Region, &rect);
	RL_Print("Setting window region at: %dx%d, size:%dx%d\n",
			 rect.x, rect.y, rect.width, rect.height);
			 */

#ifdef USE_XSHM
	if (global_x_info->has_xshm) {
		//RL_Print("XshmPutImage\n");
		XShmPutImage(global_x_info->display, 
				ctx->host_window->x_id, 
				ctx->x_gc, 
				ctx->x_image,
				0, 0, 	//src x, y
				0, 0, 	//dest x, y
				ctx->x_image->width, ctx->x_image->height,
				False);
		XFlush(global_x_info->display); //x_image could change if we don't flush here
	} else {
#endif
		Drawable dest = global_x_info->has_double_buffer ? 
			ctx->host_window->x_back_buffer :
			ctx->host_window->x_id;

		if (global_x_info->sys_pixmap_format == pix_format_bgra32){
			XPutImage (global_x_info->display,
					dest,
					ctx->x_gc,
					ctx->x_image,
					0, 0,	//src x, y
					0, 0,	//dest x, y
					ctx->x_image->width, ctx->x_image->height);
		} else {
			put_image(global_x_info->display,
					dest,
					ctx->x_gc,
					ctx->x_image,
					ctx->x_image->width, ctx->x_image->height,
					global_x_info->sys_pixmap_format);
		}

		if (global_x_info->has_double_buffer) {
			//RL_Print("Swapping...\n");
			XdbeSwapInfo swapInfo;
			swapInfo.swap_window = ctx->host_window->x_id;
			swapInfo.swap_action = XdbeUndefined;
			XdbeSwapBuffers(global_x_info->display, &swapInfo, 1);
		}
#ifdef USE_XSHM
	}
#endif

	//RL_Print("rebcmp_blit done\n");
}
Exemple #5
0
static void GGI_DBE_swap(struct ggi_visual *vis)
{
	ggi_x_priv   *priv;
	XdbeSwapInfo swapInfo;

	priv = GGIX_PRIV(vis);

	/* Set swapping informations */
	swapInfo.swap_window = priv->win;
	swapInfo.swap_action = XdbeUndefined;
	
	XdbeSwapBuffers(priv->disp, &swapInfo, 1); /* Swap buffer */
}
Exemple #6
0
static unsigned long
kumppa_draw (Display *d, Window w, void *closure)
{
  struct state *st = (struct state *) closure;
  if (st->cosilines)
    {
      int a;
      st->draw_count++;
      for (a=0;a<8;a++)
        {
          float f=0;
          int b;
          for (b=0;b<3;b++)
            {
              st->acosinus[a][b]+=cosinus[a][b];
              f+=cosinus[a][b+3]*sin((double)st->acosinus[a][b]);
            }
          st->coords[a]=(int)f;
        }
      for (a=0;a<4;a++)
        {
          XDrawLine(st->dpy,st->win[0],(mono_p)?st->fgc[1]:st->fgc[((a<<2)+st->draw_count)&31],st->midx+st->ocoords[a<<1],st->midy+st->ocoords[(a<<1)+1]
                    ,st->midx+st->coords[a<<1],st->midy+st->coords[(a<<1)+1]);
          st->ocoords[a<<1]=st->coords[a<<1];
          st->ocoords[(a<<1)+1]=st->coords[(a<<1)+1];
        }

    } else {
    int e;
    for (e=0;e<8;e++)
      {
        int a=Satnum(50);
        int b;
        if (a>=32) a=32;
        b=Satnum(32)-16+st->midx;
        st->draw_count=Satnum(32)-16+st->midy;
        XFillRectangle(st->dpy,st->win[0],st->fgc[a],b,st->draw_count,2,2);
      }
  }
  XFillRectangle(st->dpy,st->win[0],st->fgc[32],st->midx-2,st->midy-2,4,4);
  rotate(st);
#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
  if (st->usedouble) XdbeSwapBuffers(st->dpy,&st->xdswp,1);
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */

  return st->delay;
}
Exemple #7
0
static unsigned long
popsquares_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;
  int x, y;
  for (y = 0; y < st->gh; y++)
    for (x = 0; x < st->gw; x++) 
      {
        square *s = (square *) &st->squares[st->gw * y + x];
        XSetForeground (st->dpy, st->gc, st->colors[s->color].pixel);
        XFillRectangle (st->dpy, st->b, st->gc, s->x, s->y, 
                        st->border ? s->w - st->border : s->w, 
                        st->border ? s->h - st->border : s->h);
        s->color++;
        if (s->color == st->ncolors)
          {
            if (st->twitch && ((random() % 4) == 0))
              randomize_square_colors (st->squares, st->nsquares, st->ncolors);
            else
              s->color = random() % st->ncolors;
          }
      }
#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
  if (st->backb) 
    {
      XdbeSwapInfo info[1];
      info[0].swap_window = st->window;
      info[0].swap_action = XdbeUndefined;
      XdbeSwapBuffers (st->dpy, info, 1);
    }
  else
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
    if (st->dbuf)
      {
        XCopyArea (st->dpy, st->b, st->window, st->gc, 0, 0, 
                   st->xgwa.width, st->xgwa.height, 0, 0);
        st->b = (st->b == st->ba ? st->bb : st->ba);
      }

  return st->delay;
}
/* Render all the words to the screen, and run the animation one step.
   Clear screen first, swap buffers after.
 */
static unsigned long
fontglide_draw (Display *dpy, Window window, void *closure)
{
  state *s = (state *) closure;
  int i;

  if (s->debug_metrics_p)
    return fontglide_draw_metrics (closure);

  if (s->spawn_p)
    more_sentences (s);

  if (!s->trails_p)
    XFillRectangle (s->dpy, s->b, s->bg_gc,
                    0, 0, s->xgwa.width, s->xgwa.height);

  for (i = 0; i < s->nsentences; i++)
    draw_sentence (s, s->sentences[i]);

#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
  if (s->backb)
    {
      XdbeSwapInfo info[1];
      info[0].swap_window = s->window;
      info[0].swap_action = (s->dbeclear_p ? XdbeBackground : XdbeUndefined);
      XdbeSwapBuffers (s->dpy, info, 1);
    }
  else
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
  if (s->dbuf)
    {
      XCopyArea (s->dpy, s->b, s->window, s->bg_gc,
		 0, 0, s->xgwa.width, s->xgwa.height, 0, 0);
    }

  return s->frame_delay;
}
Exemple #9
0
static unsigned long
whirlygig_draw (Display *dpy, Window window, void *closure)
{
  struct state *st = (struct state *) closure;
  int wcount;  /* wcount is a counter incremented for every whirly take note of
                  internal_time before you mess with it */
  int change_time = 4000;

  if (st->explaining == 1) {
    XClearWindow (st->dpy, st->window);
    draw_explain_string(st, st->xmode, st->info->half_height-100, 
                        st->dpy, st->window, st->fgc);
    st->explaining++;
    return 3000000;
  } else if (st->explaining == 2) {
    XClearWindow (st->dpy, st->window);
    st->explaining = 0;
  }

  if (! strcmp (st->xmode_str, "change") && ! strcmp (st->ymode_str, "change")) {
    if ((st->current_time - st->start_time) > change_time) {
      st->start_time = st->current_time;
      st->xmode = 1 + (random() % 4);
      st->ymode = 1 + (random() % 4);
    }
  }
  else if (! strcmp (st->xmode_str, "change")) {
    if ((st->current_time - st->start_time) > change_time) {
      st->start_time = st->current_time;
      st->xmode = 1 + (random() % 4);
    }
  }
  else if (! strcmp (st->ymode_str, "change")) {
    if ((st->current_time - st->start_time) > change_time) {
      st->start_time = st->current_time;
      st->ymode = 1 + (random() % 3);
      printf("Changing ymode to %d\n", st->ymode);
    }
  }
  if (++st->current_color >= NCOLORS)
    st->current_color = 0;
  for (wcount = 0; wcount < st->info->whirlies; wcount++) {
    int lcount; /* lcount is a counter for every line -- take note of the offsets changing */
    int internal_time = 0;
    int color_offset = (st->current_color + (st->info->color_modifier * wcount)) % NCOLORS;
    if (st->current_time != 0)
      /* I want the distance between whirlies to increase more each whirly */
      internal_time = st->current_time + (10 * wcount) + (wcount * wcount); 
    switch (st->xmode) {
      /* All these functions expect an int time, the struct info,
         a pointer to an array of positions, and the index that the 
         the function will fill of the array */
    case spin_mode:
      spin(st, internal_time, st->info, st->pos, 0);
      break;
    case funky_mode:
      funky(st, internal_time, st->info, st->pos, 0);
      break;
    case circle_mode:
      circle(st, internal_time, st->info, st->pos, 0);
      break;
    case linear_mode:
      linear(st, internal_time, st->info, st->pos, 0);
      break;
    case fun_mode:
      fun(st, internal_time, st->info, st->pos, 0);
      break;
    case test_mode:
      test(st, internal_time, st->info, st->pos, 0);
      break;
    case innie_mode:
      innie(st, internal_time, st->info, st->pos, 0, st->modifier);
      break;
    case lissajous_mode:
      lissajous(st, internal_time, st->info, st->pos, 0);
      break;
    default:
      spin(st, internal_time, st->info, st->pos, 0);
      break;
    }   /* End of the switch for the x position*/
    switch (st->ymode) {
    case spin_mode:
      spin(st, internal_time, st->info, st->pos, 1);
      break;
    case funky_mode:
      funky(st, internal_time, st->info, st->pos, 1);
      break;
    case circle_mode:
      circle(st, internal_time, st->info, st->pos, 1);
      break;
    case linear_mode:
      linear(st, internal_time, st->info, st->pos, 1);
      break;
    case fun_mode:
      fun(st, internal_time, st->info, st->pos, 1);
      break;
    case test_mode:
      test(st, internal_time, st->info, st->pos, 1);
      break;
    case innie_mode:
      innie(st, internal_time, st->info, st->pos, 1, st->modifier);
      break;
    case lissajous_mode:
      lissajous(st, internal_time, st->info, st->pos, 1);
      break;
    default:
      spin(st, internal_time, st->info, st->pos, 1);
      break;
    } /* End of the switch for the y position*/
    for (lcount = 0; lcount < st->info->nlines; lcount++) {
      double arg = (double)((internal_time * st->info->offset_period) / 90.0); 
      double line_offset = 20.0 * (double)lcount * sin(arg); 
      int size;
      size = (int)(15.0 + 5.0 * sin((double)internal_time / 180.0));
      /* First delete the old circle... */
      if (!st->info->trail
#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
          && ( !st->dbeclear_p || !st->backb)
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
          ) {
        XSetForeground(st->dpy, st->bgc, BlackPixel(st->dpy, st->screen));
        XFillArc(st->dpy, st->b, st->bgc, st->last_x[wcount][lcount], st->last_y[wcount][lcount], st->last_size[wcount][lcount], st->last_size[wcount][lcount], START_ARC, END_ARC);
      }
      /* Now, lets draw in the new circle */
      {  /* Starting new scope for local x_pos and y_pos */
        int xpos, ypos;
        if (st->wrap) {
          xpos = preen((int)(st->info->xoffset*line_offset)+st->pos[0], st->info->half_width * 2);
          ypos = preen((int)(st->info->yoffset*line_offset)+st->pos[1], st->info->half_height * 2);
        }
        else {
          xpos = (int)(st->info->xoffset*line_offset)+st->pos[0];
          ypos = (int)(st->info->yoffset*line_offset)+st->pos[1]; 
        }
        if (st->start_time == st->current_time) {
          /* smoothen should move from one mode to another prettily... */

          /* Note: smoothen has not been modified to take the double
             buffering code into account, and needs to be hacked on
             before uncommenting.
          */
          /* 
             smoothen(xpos, last_x[wcount][lcount], ypos, last_y[wcount][lcount], size, color_offset, colors, dpy, window, bgc, screen, info);
          */
        }
        st->last_x[wcount][lcount] = xpos;
        st->last_y[wcount][lcount] = ypos;
        st->last_size[wcount][lcount] = size;
        XSetForeground(st->dpy, st->bgc, st->colors[color_offset].pixel);
        XFillArc(st->dpy, st->b, st->bgc, xpos, ypos, size, size, START_ARC, END_ARC);
      } /* End of my temporary scope for xpos and ypos */
    }  /* End of the for each line in nlines */
  } /* End of the for each whirly in whirlies */


#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
  if (st->backb)
    {
      XdbeSwapInfo info[1];
      info[0].swap_window = st->window;
      info[0].swap_action = (st->dbeclear_p ? XdbeBackground : XdbeUndefined);
      XdbeSwapBuffers (st->dpy, info, 1);
    }
  else
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
    if (st->dbuf)
      {
        XCopyArea (st->dpy, st->b, st->window, st->bgc, 0, 0,
                   st->xgwa.width, st->xgwa.height, 0, 0);
      }

  if (st->current_time == FULL_CYCLE)
    st->current_time = 1;
  else
    st->current_time = st->current_time + st->info->speed;

  return 10000;
}
Exemple #10
0
bool
_pl_y_end_page (S___(Plotter *_plotter))
{
    plColorRecord *cptr;
    plXFontRecord *fptr;
    Pixmap bg_pixmap = (Pixmap)0;
    int window_width, window_height;
    pid_t forkval;

    /* compute rectangle size; note flipped-y convention */
    window_width = (_plotter->data->imax - _plotter->data->imin) + 1;
    window_height = (_plotter->data->jmin - _plotter->data->jmax) + 1;

    /* if either sort of server-supported double buffering is being used,
       create background pixmap for Label widget (it doesn't yet have one) */
    if (_plotter->x_double_buffering == X_DBL_BUF_MBX
            || _plotter->x_double_buffering == X_DBL_BUF_DBE)
    {
        int screen;		/* screen number */
        Screen *screen_struct;	/* screen structure */

        screen = DefaultScreen (_plotter->x_dpy);
        screen_struct = ScreenOfDisplay (_plotter->x_dpy, screen);
        bg_pixmap = XCreatePixmap(_plotter->x_dpy,
                                  _plotter->x_drawable2,
                                  (unsigned int)window_width,
                                  (unsigned int)window_height,
                                  (unsigned int)PlanesOfScreen(screen_struct));

        /* copy from off-screen graphics buffer to pixmap */
        XCopyArea (_plotter->x_dpy, _plotter->x_drawable3, bg_pixmap,
                   _plotter->drawstate->x_gc_bg,
                   0, 0,
                   (unsigned int)window_width, (unsigned int)window_height,
                   0, 0);

        /* pixmap is installed below as background pixmap for Label widget */
    }

    /* If double buffering, must make final frame of graphics visible, by
       copying it from our off-screen graphics buffer `x_drawable3' to window.
       There are several types of double buffering: the two server-supported
       types, and the `by hand' type. */

#ifdef HAVE_X11_EXTENSIONS_XDBE_H
#ifdef HAVE_DBE_SUPPORT
    if (_plotter->x_double_buffering == X_DBL_BUF_DBE)
        /* we're using the X double buffering extension; off-screen graphics
           buffer `x_drawable3' is a back buffer */
    {
        XdbeSwapInfo info;

        /* make final frame of graphics visible by interchanging front and
           back buffers one last time */
        info.swap_window = _plotter->x_drawable2;
        info.swap_action = XdbeUndefined;
        XdbeSwapBuffers (_plotter->x_dpy, &info, 1);

        /* free the back buffer */
        XdbeDeallocateBackBufferName (_plotter->x_dpy, _plotter->x_drawable3);
    }
#endif /* HAVE_DBE_SUPPORT */
#endif /* HAVE_X11_EXTENSIONS_XDBE_H */

#ifdef HAVE_X11_EXTENSIONS_MULTIBUF_H
#ifdef HAVE_MBX_SUPPORT
    if (_plotter->x_double_buffering == X_DBL_BUF_MBX)
        /* we're using the X multibuffering extension; off-screen graphics
           buffer `x_drawable3' is a non-displayed multibuffer */
    {
        /* make final frame of graphics visible by making the multibuffer
        into which we're currently drawing the on-screen multibuffer */
        XmbufDisplayBuffers (_plotter->x_dpy, 1, &(_plotter->x_drawable3), 0, 0);
    }
#endif /* HAVE_MBX_SUPPORT */
#endif /* HAVE_X11_EXTENSIONS_MULTIBUF_H */

    /* if either sort of server-supported double buffering is being used,
       install the above-created pixmap as background pixmap for the Label
       widget to use, once the window has been spun off */
    if (_plotter->x_double_buffering == X_DBL_BUF_MBX
            || _plotter->x_double_buffering == X_DBL_BUF_DBE)
    {
        Arg wargs[2];		/* werewolves */

        /* install pixmap as Label widget's background pixmap */
#ifdef USE_MOTIF
        XtSetArg (wargs[0], XmNlabelPixmap, (Pixmap)bg_pixmap);
        XtSetArg (wargs[1], XmNlabelType, XmPIXMAP);
        XtSetValues (_plotter->y_canvas, wargs, (Cardinal)2);
#else
        XtSetArg (wargs[0], XtNbitmap, (Pixmap)bg_pixmap);
        XtSetValues (_plotter->y_canvas, wargs, (Cardinal)1);
#endif
    }

    if (_plotter->x_double_buffering == X_DBL_BUF_BY_HAND)
        /* we're double buffering _manually_, rather than using either X11
           protocol extension, so our off-screen graphics buffer `x_drawable3' is
           an ordinary pixmap */
    {
        /* make final frame of graphics visible by copying from pixmap to
               window */
        XCopyArea (_plotter->x_dpy, _plotter->x_drawable3, _plotter->x_drawable2,
                   _plotter->drawstate->x_gc_bg,
                   0, 0,
                   (unsigned int)window_width, (unsigned int)window_height,
                   0, 0);
    }

    /* Finally: if we're not double buffering at all, we copy our off-screen
       graphics buffer to the window.  The off-screen graphics buffer is just
       the Label widget's background pixmap, `x_drawable1'. */
    if (_plotter->x_double_buffering == X_DBL_BUF_NONE)
        XCopyArea (_plotter->x_dpy, _plotter->x_drawable1, _plotter->x_drawable2,
                   _plotter->drawstate->x_gc_bg,
                   0, 0,
                   (unsigned int)window_width, (unsigned int)window_height,
                   0, 0);

    /* following two deallocations (of font records and color cell records)
       arrange things so that when drawing the next page of graphics, which
       will require another connection to the X server, the Plotter will
       start with a clean slate */

    /* Free font records from Plotter's cache list.  This involves
       deallocating the font name and also the XFontStruct contained in each
       record, if non-NULL.  (NULL indicates that the font could not be
       retrieved.)  */
    fptr = _plotter->x_fontlist;
    _plotter->x_fontlist = NULL;
    while (fptr)
    {
        plXFontRecord *fptrnext;

        fptrnext = fptr->next;
        free (fptr->x_font_name);
        if (fptr->x_font_struct)
            XFreeFont (_plotter->x_dpy, fptr->x_font_struct);
        free (fptr);
        fptr = fptrnext;
    }

    /* Free cached color cells from Plotter's cache list.  Do _not_ ask the
       server to deallocate the cells themselves, because the child process
       will need them; just free local storage. */
    cptr = _plotter->x_colorlist;
    _plotter->x_colorlist = NULL;
    while (cptr)
    {
        plColorRecord *cptrnext;

        cptrnext = cptr->next;
        free (cptr);
        cptr = cptrnext;
    }

    /* A bit of last-minute cleanup (could be done elsewhere): call waitpid()
       to reclaim resources used by zombie child processes resulting from
       previous closepl()'s, if any.  If this isn't done, the controlling
       process of any previously popped-up window won't fully exit (e.g. when
       `q' is typed in the window): it'll remain in the process table as a
       zombie until the parent process executes. */
#ifdef HAVE_WAITPID
#ifdef HAVE_SYS_WAIT_H
#ifdef WNOHANG
    {
        int i;

        /* iterate over all previously forked-off children (should really keep
           track of which have exited, since once a child has exited, invoking
           waitpid() on it is pointless) */
        for (i = 0; i < _plotter->y_num_pids; i++)
            waitpid (_plotter->y_pids[i], (int *)NULL, WNOHANG);
    }
#endif
#endif
#endif

    /* maybe flush X output buffer and handle X events (a no-op for
       XDrawablePlotters, which is overridden for XPlotters) */
    _maybe_handle_x_events (S___(_plotter));

    /* flush out the X output buffer; wait till all requests have been
       received and processed by server (see x_flushpl.c) */
    _pl_x_flush_output (S___(_plotter));

    /* flush output streams for all Plotters before forking */
    _pl_g_flush_plotter_outstreams (S___(_plotter));

    /* DO IT, MAN! */
    forkval = fork ();
    if ((int)forkval > 0		/* fork succeeded, and we're the parent */
            || (int)forkval < 0)	/* fork failed */
    {
        bool retval = true;

        if ((int)forkval < 0)
            _plotter->error (R___(_plotter) "the process could not be forked");

        /* Close connection to X display associated with window that the
        child process should manage, i.e. with the last openpl() invoked
         on this Plotter. */
        if (close (ConnectionNumber (_plotter->x_dpy)) < 0
                && errno != EINTR)
            /* emphatically shouldn't happen */
        {
            _plotter->error (R___(_plotter) "the connection to the X display could not be closed");
            retval = false;
        }

        if ((int)forkval > 0)
            /* there's a child process, so save its pid */
        {
            if (_plotter->y_num_pids == 0)
                _plotter->y_pids = (pid_t *)_pl_xmalloc (sizeof (pid_t));
            else
                _plotter->y_pids =
                    (pid_t *)_pl_xrealloc (_plotter->y_pids,
                                           ((_plotter->y_num_pids + 1)
                                            * sizeof (pid_t)));
            _plotter->y_pids[_plotter->y_num_pids] = forkval;
            _plotter->y_num_pids++;
        }

        /* do teardown of X-specific elements of the first drawing state on
        the drawing state stack */
        _pl_x_delete_gcs_from_first_drawing_state (S___(_plotter));

        return retval;
    }

    else		/* forkval = 0; fork succeeded, and we're the child */
    {
        bool need_redisplay = false;
        int i;

        /* Alter canvas widget's translation table, so that exit will occur
        when `q' is typed (or mouse is clicked).  See y_openpl.c. */
        _pl_y_set_data_for_quitting (S___(_plotter));

        /* Close all connections to X display other than our own, i.e., close
        all connections that other XPlotters may have been using.  No need
         to lock the global variables _xplotters and _xplotters_len; since
         we've forked and we're the child process, we're the only thread
         left. :-)

         We'll never be accessing those variables again (the only way we
         could would be if we were to call _maybe_handle_x_events(), and
         we aren't going to do that).  So we don't need to worry that they
         may actually be locked.  I.e. there was no need for us to register
         a handler to unlock them immediately after forking, by invoking
         pthread_atfork().  Which is why we didn't do that. */

        for (i = 0; i < _xplotters_len; i++)
            if (_xplotters[i] != NULL
                    && _xplotters[i] != _plotter
                    && _xplotters[i]->data->opened
                    && _xplotters[i]->data->open
                    && close (ConnectionNumber (_xplotters[i]->x_dpy)) < 0
                    && errno != EINTR)
                /* shouldn't happen */
                _plotter->error (R___(_plotter)
                                 "the connection to the X display could not be closed");

        /* Repaint by sending an expose event to ourselves, copying the Label
        widget's background pixmap into its window.  This is a good idea
         because the window could have been resized during the
         openpl..closepl.  We don't do this if not double buffering (and
         presumably animating), unless the window size has changed since
         openpl was invoked (repainting makes the window flash, possibly
         irritating users). */
        if (_plotter->x_double_buffering != X_DBL_BUF_NONE)
            need_redisplay = true;
        else
        {
            Arg wargs[2];		/* werewolves */
            Dimension our_window_height, our_window_width;

#ifdef USE_MOTIF
            XtSetArg (wargs[0], XmNwidth, &our_window_width);
            XtSetArg (wargs[1], XmNheight, &our_window_height);
#else
            XtSetArg (wargs[0], XtNwidth, &our_window_width);
            XtSetArg (wargs[1], XtNheight, &our_window_height);
#endif
            XtGetValues (_plotter->y_canvas, wargs, (Cardinal)2);
            if ((_plotter->data->imax + 1 != (int)our_window_width)
                    || (_plotter->data->jmin + 1 != (int)our_window_height))
                /* window changed size */
                need_redisplay = true;
        }

        /* turn off backing store (if used); when we send the expose event to
        ourselves we want to repaint from the background pixmap, NOT from
         the server's backing store */
        {
            XSetWindowAttributes attributes;
            unsigned long value_mask;

            attributes.backing_store = NotUseful;
            value_mask = CWBackingStore;
            XChangeWindowAttributes (_plotter->x_dpy, (Window)_plotter->x_drawable2,
                                     value_mask, &attributes);
        }

        if (need_redisplay)
            /* send expose event to ourselves */
            XClearArea (_plotter->x_dpy,
                        (Window)_plotter->x_drawable2,
                        0, 0,
                        (unsigned int)0, (unsigned int)0,
                        True);

        _plotter->data->open = false; /* flag Plotter as closed (is this useful,
				       or just pedantic?) */

        /* Manage the window.  We won't get any events associated with other
        windows i.e. with previous invocations of openpl..closepl on this
         Plotter, or with other Plotters, since there's a distinct
         application context for every openpl..closepl. */
        XtAppMainLoop (_plotter->y_app_con); /* shouldn't return */

        /* NOTREACHED */
        exit (EXIT_FAILURE);
    }
}
static void do_inter(struct inter_context* c) 
{
  int i, j, k;
  int result;
  int dist;
  int g;

  int dx, dy;

  for(i = 0; i < c->count; i++) {
    c->source[i].x_theta += (c->speed/1000.0);
    if(c->source[i].x_theta > 2.0*3.14159)
      c->source[i].x_theta -= 2.0*3.14159;
    c->source[i].y_theta += (c->speed/1000.0);
    if(c->source[i].y_theta > 2.0*3.14159)
      c->source[i].y_theta -= 2.0*3.14159;
    c->source[i].x = source_x(c, i);
    c->source[i].y = source_y(c, i);
  }

  g = c->grid_size;

  for(j = 0; j < c->h/g; j++) {
    for(i = 0; i < c->w/g; i++) {
      result = 0;
      for(k = 0; k < c->count; k++) {
	dx = i*g + g/2 - c->source[k].x;
	dy = j*g + g/2 - c->source[k].y;
	dist = sqrt(dx*dx + dy*dy); /* what's the performance penalty here? */
	result += (dist >= c->radius ? 0 : c->wave_height[dist]);
      }
      result %= c->colors;

#ifdef USE_XIMAGE
      /* Fill in these `gridsize' horizontal bits in the scanline */
      for(k = 0; k < g; k++)
	XPutPixel(c->ximage, (g*i)+k, 0, c->pal[result].pixel);

#else  /* !USE_XIMAGE */
      XFillRectangle(c->dpy, TARGET(c), c->gcs[result], g*i, g*j, g, g); 
#endif /* !USE_XIMAGE */
    }

#ifdef USE_XIMAGE

    /* Only the first scanline of the image has been filled in; clone that
       scanline to the rest of the `gridsize' lines in the ximage */
    for(k = 0; k < (g-1); k++)
      memcpy(c->ximage->data + (c->ximage->bytes_per_line * (k + 1)),
	     c->ximage->data + (c->ximage->bytes_per_line * k),
	     c->ximage->bytes_per_line);

    /* Move the bits for this horizontal stripe to the server. */
# ifdef HAVE_XSHM_EXTENSION
    if (c->use_shm)
      XShmPutImage(c->dpy, TARGET(c), c->copy_gc, c->ximage,
		   0, 0, 0, g*j, c->ximage->width, c->ximage->height,
		   False);
    else
# endif /*  HAVE_XSHM_EXTENSION */
      XPutImage(c->dpy, TARGET(c), c->copy_gc, c->ximage,
		0, 0, 0, g*j, c->ximage->width, c->ximage->height);

#endif /* USE_XIMAGE */
  }

#ifdef HAVE_DOUBLE_BUFFER_EXTENSION
  if (c->back_buf)
    {
      XdbeSwapInfo info[1];
      info[0].swap_window = c->win;
      info[0].swap_action = XdbeUndefined;
      XdbeSwapBuffers(c->dpy, info, 1);
    }
  else
#endif /* HAVE_DOUBLE_BUFFER_EXTENSION */
    if (c->pix_buf)
      {
        XCopyArea (c->dpy, c->pix_buf, c->win, c->copy_gc,
                   0, 0, c->w, c->h, 0, 0);
      }
}