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