/* Coopyright 1989 Massachusetts Institute of Technology */
#ifndef _XMU_DISPLAYQUE_H_
#define _XMU_DISPLAYQUE_H_

#ifndef _XMU_CLOSEHOOK_H_
#include "CloseHook.h"
#endif

/*
 *			      Public Entry Points
 * 
 * 
 * XmuDisplayQueue *XmuDQCreate (closefunc, freefunc, data)
 *     int (*closefunc)();
 *     int (*freefunc)();
 *     caddr_t data;
 * 
 *         Creates and returns a queue into which displays may be placed.  When
 *         the display is closed, the closefunc (if non-NULL) is upcalled with
 *         as follows:
 *
 *                 (*closefunc) (queue, entry)
 *
 *         The freeproc, if non-NULL, is called whenever the last display is
 *         closed, notifying the creator that display queue may be released
 *         using XmuDQDestroy.
 *
 *
 * Bool XmuDQDestroy (q, docallbacks)
 *     XmuDisplayQueue *q;
 *     Bool docallbacks;
 * 
 *         Releases all memory for the indicated display queue.  If docallbacks
 *         is true, then the closefunc (if non-NULL) is called for each 
 *         display.
 * 
 * 
 * XmuDisplayQueueEntry *XmuDQLookupDisplay (q, dpy)
 *     XmuDisplayQueue *q;
 *     Display *dpy;
 *
 *         Returns the queue entry for the specified display or NULL if the
 *         display is not in the queue.
 *
 * 
 * XmuDisplayQueueEntry *XmuDQAddDisplay (q, dpy, data)
 *     XmuDisplayQueue *q;
 *     Display *dpy;
 *     caddr_t data;
 *
 *         Adds the indicated display to the end of the queue or NULL if it
 *         is unable to allocate memory.  The data field may be used by the
 *         caller to attach arbitrary data to this display in this queue.  The
 *         caller should use XmuDQLookupDisplay to make sure that the display
 *         hasn't already been added.
 * 
 * 
 * Bool XmuDQRemoveDisplay (q, dpy)
 *     XmuDisplayQueue *q;
 *     Display *dpy;
 *
 *         Removes the specified display from the given queue.  If the 
 *         indicated display is not found on this queue, False is returned,
 *         otherwise True is returned.
 */

typedef struct _XmuDisplayQueueEntry {
    struct _XmuDisplayQueueEntry *prev, *next;
    Display *display;
    CloseHook closehook;
    caddr_t data;
} XmuDisplayQueueEntry;

typedef struct _XmuDisplayQueue {
    int nentries;
    XmuDisplayQueueEntry *head, *tail;
    int (*closefunc)(struct _XmuDisplayQueue *, XmuDisplayQueueEntry *);
    int (*freefunc)(struct _XmuDisplayQueue *);
    caddr_t data;
} XmuDisplayQueue;


extern XmuDisplayQueue *XmuDQCreate (
	int (*closefunc)(XmuDisplayQueue *, XmuDisplayQueueEntry*),
	int (*freefunc)(XmuDisplayQueue *),
	caddr_t data
);
extern Bool XmuDQDestroy (XmuDisplayQueue *display, Bool docallbacks);
extern XmuDisplayQueueEntry *XmuDQLookupDisplay (XmuDisplayQueue *, Display *);
extern XmuDisplayQueueEntry *XmuDQAddDisplay (XmuDisplayQueue *, Display *, caddr_t);
extern Bool XmuDQRemoveDisplay (XmuDisplayQueue *, Display *);


#define XmuDQNDisplays(q) ((q)->nentries)

#endif
