#include <stdio.h>#include <X11/Xos.h>#include <X11/Xlib.h>#include <X11/Xmu/CloseHook.h>#include <stdlib.h>Include dependency graph for CloseHook.c:

Go to the source code of this file.
Data Structures | |
| struct | _CallbackRec |
| struct | _DisplayEntry |
Typedefs | |
| typedef _CallbackRec | CallbackRec |
| typedef _DisplayEntry | DisplayEntry |
Functions | |
| static DisplayEntry * | _FindDisplayEntry (Display *, DisplayEntry **) |
| static Bool | _MakeExtension (Display *, int *) |
| CloseHook | XmuAddCloseDisplayHook (Display *dpy, XmuCloseHookProc func, XPointer arg) |
| Bool | XmuRemoveCloseDisplayHook (Display *dpy, CloseHook handle, XmuCloseHookProc func, XPointer arg) |
| Bool | XmuLookupCloseDisplayHook (Display *dpy, CloseHook handle, XmuCloseHookProc func, XPointer arg) |
| static DisplayEntry * | _FindDisplayEntry (register Display *dpy, DisplayEntry **prevp) |
| static int | _DoCallbacks (Display *dpy, XExtCodes *codes) |
Variables | |
| static DisplayEntry * | elist = NULL |
| typedef struct _CallbackRec CallbackRec |
| typedef struct _DisplayEntry DisplayEntry |
| static int _DoCallbacks | ( | Display * | dpy, | |
| XExtCodes * | codes | |||
| ) | [static] |
Definition at line 250 of file CloseHook.c.
References _FindDisplayEntry(), _DisplayEntry::calling, elist, free(), h, _DisplayEntry::next, NULL, and _DisplayEntry::start.
Referenced by _MakeExtension().
00251 { 00252 register CallbackRec *h; 00253 DisplayEntry *prev; 00254 DisplayEntry *de = _FindDisplayEntry (dpy, &prev); 00255 00256 if (!de) return 0; 00257 00258 /* walk the list doing the callbacks and freeing callback record */ 00259 for (h = de->start; h;) { 00260 register CallbackRec *nexth = h->next; 00261 de->calling = h; /* let remove know we'll free it */ 00262 (*(h->func)) (dpy, h->arg); 00263 de->calling = NULL; 00264 free ((char *) h); 00265 h = nexth; 00266 } 00267 00268 /* unlink this display from chain */ 00269 if (elist == de) { 00270 elist = de->next; 00271 } else { 00272 prev->next = de->next; 00273 } 00274 free ((char *) de); 00275 return 1; 00276 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static DisplayEntry* _FindDisplayEntry | ( | register Display * | dpy, | |
| DisplayEntry ** | prevp | |||
| ) | [static] |
Definition at line 228 of file CloseHook.c.
References _DisplayEntry::dpy, elist, _DisplayEntry::next, and NULL.
00229 { 00230 register DisplayEntry *d, *prev; 00231 00232 for (d = elist, prev = NULL; d; d = d->next) { 00233 if (d->dpy == dpy) { 00234 if (prevp) *prevp = prev; 00235 return d; 00236 } 00237 prev = d; 00238 } 00239 return NULL; 00240 }
| static DisplayEntry* _FindDisplayEntry | ( | Display * | , | |
| DisplayEntry ** | ||||
| ) | [static] |
Referenced by _DoCallbacks(), XmuAddCloseDisplayHook(), XmuLookupCloseDisplayHook(), and XmuRemoveCloseDisplayHook().
Here is the caller graph for this function:

| static Bool _MakeExtension | ( | Display * | , | |
| int * | ||||
| ) | [static] |
Definition at line 283 of file CloseHook.c.
References _DoCallbacks(), and void().
Referenced by XmuAddCloseDisplayHook().
00284 { 00285 XExtCodes *codes; 00286 00287 codes = XAddExtension (dpy); 00288 if (!codes) return False; 00289 00290 (void) XESetCloseDisplay (dpy, codes->extension, _DoCallbacks); 00291 00292 *extensionp = codes->extension; 00293 return True; 00294 }
Here is the call graph for this function:

Here is the caller graph for this function:

| CloseHook XmuAddCloseDisplayHook | ( | Display * | dpy, | |
| XmuCloseHookProc | func, | |||
| XPointer | arg | |||
| ) |
Definition at line 114 of file CloseHook.c.
References _FindDisplayEntry(), _MakeExtension(), _CallbackRec::arg, _DisplayEntry::calling, _DisplayEntry::dpy, elist, _DisplayEntry::end, _DisplayEntry::extension, free(), _CallbackRec::func, malloc(), _DisplayEntry::next, _CallbackRec::next, NULL, and _DisplayEntry::start.
Referenced by XmuDQAddDisplay().
00115 { 00116 DisplayEntry *de; 00117 CallbackRec *cb; 00118 00119 /* allocate ahead of time so that we can fail atomically */ 00120 cb = (CallbackRec *) malloc (sizeof (CallbackRec)); 00121 if (!cb) return ((XPointer) NULL); 00122 00123 de = _FindDisplayEntry (dpy, NULL); 00124 if (!de) { 00125 if ((de = (DisplayEntry *) malloc (sizeof (DisplayEntry))) == NULL || 00126 !_MakeExtension (dpy, &de->extension)) { 00127 free ((char *) cb); 00128 if (de) free ((char *) de); 00129 return ((CloseHook) NULL); 00130 } 00131 de->dpy = dpy; 00132 de->start = de->end = NULL; 00133 de->calling = NULL; 00134 de->next = elist; 00135 elist = de; 00136 } 00137 00138 /* add to end of list of callback recordss */ 00139 cb->func = func; 00140 cb->arg = arg; 00141 cb->next = NULL; 00142 if (de->end) { 00143 de->end->next = cb; 00144 } else { 00145 de->start = cb; 00146 } 00147 de->end = cb; 00148 00149 return ((CloseHook) cb); 00150 }
Here is the call graph for this function:

Here is the caller graph for this function:

| Bool XmuLookupCloseDisplayHook | ( | Display * | dpy, | |
| CloseHook | handle, | |||
| XmuCloseHookProc | func, | |||
| XPointer | arg | |||
| ) |
Definition at line 196 of file CloseHook.c.
References _FindDisplayEntry(), h, NULL, and _DisplayEntry::start.
00198 { 00199 DisplayEntry *de = _FindDisplayEntry (dpy, NULL); 00200 register CallbackRec *h; 00201 00202 if (!de) return False; 00203 00204 for (h = de->start; h; h = h->next) { 00205 if (handle) { 00206 if (h == (CallbackRec *) handle) break; 00207 } else { 00208 if (h->func == func && h->arg == arg) break; 00209 } 00210 } 00211 return (h ? True : False); 00212 }
Here is the call graph for this function:

| Bool XmuRemoveCloseDisplayHook | ( | Display * | dpy, | |
| CloseHook | handle, | |||
| XmuCloseHookProc | func, | |||
| XPointer | arg | |||
| ) |
Definition at line 158 of file CloseHook.c.
References _FindDisplayEntry(), _DisplayEntry::calling, _DisplayEntry::end, free(), h, _CallbackRec::next, NULL, and _DisplayEntry::start.
Referenced by XmuDQRemoveDisplay().
00160 { 00161 DisplayEntry *de = _FindDisplayEntry (dpy, NULL); 00162 register CallbackRec *h, *prev; 00163 00164 if (!de) return False; 00165 00166 /* look for handle or function/argument pair */ 00167 for (h = de->start, prev = NULL; h; h = h->next) { 00168 if (handle) { 00169 if (h == (CallbackRec *) handle) break; 00170 } else { 00171 if (h->func == func && h->arg == arg) break; 00172 } 00173 prev = h; 00174 } 00175 if (!h) return False; 00176 00177 00178 /* remove from list, watch head and tail */ 00179 if (de->start == h) { 00180 de->start = h->next; 00181 } else { 00182 prev->next = h->next; 00183 } 00184 if (de->end == h) de->end = prev; 00185 if (de->calling != h) free ((char *) h); 00186 return True; 00187 }
Here is the call graph for this function:

Here is the caller graph for this function:

DisplayEntry* elist = NULL [static] |
Definition at line 91 of file CloseHook.c.
Referenced by _DoCallbacks(), _FindDisplayEntry(), and XmuAddCloseDisplayHook().
1.5.1