/*
 * -- $Header: /cec/src/nestor/servers/R3/shXlib/XSync.c,v 1.1.1.1 90/04/23
 * 10:07:51 spanachi Exp $
 */
#include "copyright.h"

/* $XConsortium: XSync.c,v 11.14 88/10/15 12:42:34 jim Exp $ */
/* Copyright    Massachusetts Institute of Technology    1986	 */
/* -- MULTIPLEX Extension -- */

#define NEED_REPLIES
#define NEED_EVENTS
#include "Xlibint.h"

/* -- additional includes -- */
#include "utils.h"

extern _XQEvent *_qfree;

/* Synchronize with errors and events, optionally discarding pending events */

XSync (calling_dpy, discard)
/* -- must rename or else macro GetReq will fail -- */
  register Display *calling_dpy;
  Bool discard;
{
  xGetInputFocusReply rep;
  register xReq *req;

  register Display *dpy;
  register int i;

  /* -- flush default dpy's queue to keep buffers aligned -- */
  XmuXFlushDefault (calling_dpy);

  for (i = 0; (dpy = XmuXGetDisplay (calling_dpy, i)) != NULL; i++) {
    LockDisplay (dpy);
    GetEmptyReq (GetInputFocus, req);
    (void) _XReply (dpy, (xReply *) & rep, 0, xTrue);

    if (discard && dpy->head) {
      ((_XQEvent *) dpy->tail)->next = _qfree;
      _qfree = (_XQEvent *) dpy->head;
      dpy->head = dpy->tail = NULL;
      dpy->qlen = 0;
    }
    UnlockDisplay (dpy);
  }
}
