3 Copyright 1989, 1998 The Open Group
5 Permission to use, copy, modify, distribute, and sell this software and its
6 documentation for any purpose is hereby granted without fee, provided that
7 the above copyright notice appear in all copies and that both that
8 copyright notice and this permission notice appear in supporting
11 The above copyright notice and this permission notice shall be included in
12 all copies or substantial portions of the Software.
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18 AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 Except as contained in this notice, the name of The Open Group shall not be
22 used in advertising or otherwise to promote the sale, use or other dealings
23 in this Software without prior written authorization from The Open Group.
28 * Author: Jim Fulton, MIT X Consortium
37 #include <X11/Xmu/DisplayQue.h>
42 static int _DQCloseDisplay(Display*, XPointer);
44 #define CallCloseCallback(q,e) (void) (*((q)->closefunc)) ((q), (e))
45 #define CallFreeCallback(q) (void) (*((q)->freefunc)) ((q))
48 * XmuDQCreate - create a display queue
51 XmuDQCreate(XmuCloseDisplayQueueProc closefunc,
52 XmuFreeDisplayQueueProc freefunc,
55 XmuDisplayQueue *q = (XmuDisplayQueue *) malloc (sizeof (XmuDisplayQueue));
58 q->head = q->tail = NULL;
59 q->closefunc = closefunc;
60 q->freefunc = freefunc;
68 * XmuDQDestroy - free all storage associated with this display queue,
69 * optionally invoking the close callbacks.
73 XmuDQDestroy(XmuDisplayQueue *q, Bool docallbacks)
75 XmuDisplayQueueEntry *e = q->head;
78 XmuDisplayQueueEntry *nexte = e->next;
79 if (docallbacks && q->closefunc) CallCloseCallback (q, e);
89 * XmuDQLookupDisplay - finds the indicated display on the given queue
91 XmuDisplayQueueEntry *
92 XmuDQLookupDisplay(XmuDisplayQueue *q, Display *dpy)
94 XmuDisplayQueueEntry *e;
96 for (e = q->head; e; e = e->next) {
97 if (e->display == dpy) return e;
104 * XmuDQAddDisplay - add the specified display to the queue; set data as a
105 * convenience. Does not ensure that dpy hasn't already been added.
107 XmuDisplayQueueEntry *
108 XmuDQAddDisplay(XmuDisplayQueue *q, Display *dpy, XPointer data)
110 XmuDisplayQueueEntry *e;
112 if (!(e = (XmuDisplayQueueEntry *) malloc (sizeof (XmuDisplayQueueEntry)))) {
115 if (!(e->closehook = XmuAddCloseDisplayHook (dpy, _DQCloseDisplay,
139 * XmuDQRemoveDisplay - remove the specified display from the queue
142 XmuDQRemoveDisplay(XmuDisplayQueue *q, Display *dpy)
144 XmuDisplayQueueEntry *e;
146 for (e = q->head; e; e = e->next) {
147 if (e->display == dpy) {
149 q->head = e->next; /* if at head, then bump head */
151 e->prev->next = e->next; /* else splice out */
153 q->tail = e->prev; /* if at tail, then bump tail */
155 e->next->prev = e->prev; /* else splice out */
156 (void) XmuRemoveCloseDisplayHook (dpy, e->closehook,
157 _DQCloseDisplay, (XPointer) q);
167 /*****************************************************************************
168 * private functions *
169 *****************************************************************************/
172 * _DQCloseDisplay - upcalled from CloseHook to notify this queue; remove the
173 * display when finished
176 _DQCloseDisplay(Display *dpy, XPointer arg)
178 XmuDisplayQueue *q = (XmuDisplayQueue *) arg;
179 XmuDisplayQueueEntry *e;
181 for (e = q->head; e; e = e->next) {
182 if (e->display == dpy) {
183 if (q->closefunc) CallCloseCallback (q, e);
184 (void) XmuDQRemoveDisplay (q, dpy);
185 if (q->nentries == 0 && q->freefunc) CallFreeCallback (q);