ClDisplay.c revision 1ab64890
1/* $Xorg: ClDisplay.c,v 1.4 2001/02/09 02:03:31 xorgcvs Exp $ */
2
3/*
4
5Copyright 1985, 1990, 1998  The Open Group
6
7Permission to use, copy, modify, distribute, and sell this software and its
8documentation for any purpose is hereby granted without fee, provided that
9the above copyright notice appear in all copies and that both that
10copyright notice and this permission notice appear in supporting
11documentation.
12
13The above copyright notice and this permission notice shall be included
14in all copies or substantial portions of the Software.
15
16THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
20OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22OTHER DEALINGS IN THE SOFTWARE.
23
24Except as contained in this notice, the name of The Open Group shall
25not be used in advertising or otherwise to promote the sale, use or
26other dealings in this Software without prior written authorization
27from The Open Group.
28
29*/
30/* $XFree86: xc/lib/X11/ClDisplay.c,v 1.4 2001/12/14 19:53:58 dawes Exp $ */
31
32#ifdef HAVE_CONFIG_H
33#include <config.h>
34#endif
35#if USE_XCB
36#include "Xxcbint.h"
37#else /* !USE_XCB */
38#include <X11/Xtrans/Xtrans.h>
39#endif /* USE_XCB */
40#include "Xlib.h"
41#include "Xlibint.h"
42#include "Xintconn.h"
43
44/*
45 * XCloseDisplay - XSync the connection to the X Server, close the connection,
46 * and free all associated storage.  Extension close procs should only free
47 * memory and must be careful about the types of requests they generate.
48 */
49
50int
51XCloseDisplay (
52	register Display *dpy)
53{
54	register _XExtension *ext;
55	register int i;
56
57	if (!(dpy->flags & XlibDisplayClosing))
58	{
59	    dpy->flags |= XlibDisplayClosing;
60	    for (i = 0; i < dpy->nscreens; i++) {
61		    register Screen *sp = &dpy->screens[i];
62		    XFreeGC (dpy, sp->default_gc);
63	    }
64	    if (dpy->cursor_font != None) {
65		XUnloadFont (dpy, dpy->cursor_font);
66	    }
67	    XSync(dpy, 1);  /* throw away pending events, catch errors */
68	    /* call out to any extensions interested */
69	    for (ext = dpy->ext_procs; ext; ext = ext->next) {
70		if (ext->close_display)
71		    (*ext->close_display)(dpy, &ext->codes);
72	    }
73	    /* if the closes generated more protocol, sync them up */
74	    if (dpy->request != dpy->last_request_read)
75		XSync(dpy, 1);
76	}
77#if USE_XCB
78	xcb_disconnect(dpy->xcb->connection);
79#else /* !USE_XCB */
80	_XDisconnectDisplay(dpy->trans_conn);
81#endif /* USE_XCB */
82	_XFreeDisplayStructure (dpy);
83	return 0;
84}
85