InitExt.c revision eb411b4b
11ab64890Smrg/* 21ab64890Smrg 31ab64890SmrgCopyright 1987, 1998 The Open Group 41ab64890Smrg 51ab64890SmrgPermission to use, copy, modify, distribute, and sell this software and its 61ab64890Smrgdocumentation for any purpose is hereby granted without fee, provided that 71ab64890Smrgthe above copyright notice appear in all copies and that both that 81ab64890Smrgcopyright notice and this permission notice appear in supporting 91ab64890Smrgdocumentation. 101ab64890Smrg 111ab64890SmrgThe above copyright notice and this permission notice shall be included 121ab64890Smrgin all copies or substantial portions of the Software. 131ab64890Smrg 141ab64890SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 151ab64890SmrgOR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 161ab64890SmrgMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 171ab64890SmrgIN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR 181ab64890SmrgOTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 191ab64890SmrgARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 201ab64890SmrgOTHER DEALINGS IN THE SOFTWARE. 211ab64890Smrg 221ab64890SmrgExcept as contained in this notice, the name of The Open Group shall 231ab64890Smrgnot be used in advertising or otherwise to promote the sale, use or 241ab64890Smrgother dealings in this Software without prior written authorization 251ab64890Smrgfrom The Open Group. 261ab64890Smrg 271ab64890Smrg*/ 281ab64890Smrg 291ab64890Smrg#ifdef HAVE_CONFIG_H 301ab64890Smrg#include <config.h> 311ab64890Smrg#endif 321ab64890Smrg#include <X11/Xlibint.h> 331ab64890Smrg#include <X11/Xos.h> 341ab64890Smrg#include <stdio.h> 351ab64890Smrg 361ab64890Smrg/* 371ab64890Smrg * This routine is used to link a extension in so it will be called 381ab64890Smrg * at appropriate times. 391ab64890Smrg */ 401ab64890Smrg 411ab64890SmrgXExtCodes *XInitExtension ( 421ab64890Smrg Display *dpy, 431ab64890Smrg _Xconst char *name) 441ab64890Smrg{ 451ab64890Smrg XExtCodes codes; /* temp. place for extension information. */ 461ab64890Smrg register _XExtension *ext;/* need a place to build it all */ 4761b2299dSmrg if (!XQueryExtension(dpy, name, 481ab64890Smrg &codes.major_opcode, &codes.first_event, 491ab64890Smrg &codes.first_error)) return (NULL); 501ab64890Smrg 511ab64890Smrg LockDisplay (dpy); 52eb411b4bSmrg if (! (ext = Xcalloc (1, sizeof (_XExtension))) || 536cc2b21fSmrg ! (ext->name = strdup(name))) { 541ab64890Smrg if (ext) Xfree((char *) ext); 551ab64890Smrg UnlockDisplay(dpy); 561ab64890Smrg return (XExtCodes *) NULL; 571ab64890Smrg } 581ab64890Smrg codes.extension = dpy->ext_number++; 591ab64890Smrg ext->codes = codes; 601ab64890Smrg 6161b2299dSmrg /* chain it onto the display list */ 621ab64890Smrg ext->next = dpy->ext_procs; 631ab64890Smrg dpy->ext_procs = ext; 641ab64890Smrg UnlockDisplay (dpy); 651ab64890Smrg 661ab64890Smrg return (&ext->codes); /* tell him which extension */ 671ab64890Smrg} 681ab64890Smrg 691ab64890SmrgXExtCodes *XAddExtension (Display *dpy) 701ab64890Smrg{ 711ab64890Smrg register _XExtension *ext; 721ab64890Smrg 731ab64890Smrg LockDisplay (dpy); 74eb411b4bSmrg if (! (ext = Xcalloc (1, sizeof (_XExtension)))) { 751ab64890Smrg UnlockDisplay(dpy); 761ab64890Smrg return (XExtCodes *) NULL; 771ab64890Smrg } 781ab64890Smrg ext->codes.extension = dpy->ext_number++; 791ab64890Smrg 801ab64890Smrg /* chain it onto the display list */ 811ab64890Smrg ext->next = dpy->ext_procs; 821ab64890Smrg dpy->ext_procs = ext; 831ab64890Smrg UnlockDisplay (dpy); 841ab64890Smrg 851ab64890Smrg return (&ext->codes); /* tell him which extension */ 861ab64890Smrg} 871ab64890Smrg 881ab64890Smrgstatic _XExtension *XLookupExtension ( 891ab64890Smrg register Display *dpy, /* display */ 901ab64890Smrg register int extension) /* extension number */ 911ab64890Smrg{ 921ab64890Smrg register _XExtension *ext; 931ab64890Smrg for (ext = dpy->ext_procs; ext; ext = ext->next) 941ab64890Smrg if (ext->codes.extension == extension) return (ext); 951ab64890Smrg return (NULL); 961ab64890Smrg} 971ab64890Smrg 981ab64890SmrgXExtData **XEHeadOfExtensionList(XEDataObject object) 991ab64890Smrg{ 1001ab64890Smrg return *(XExtData ***)&object; 1011ab64890Smrg} 1021ab64890Smrg 1031ab64890Smrgint 1041ab64890SmrgXAddToExtensionList( 1051ab64890Smrg XExtData **structure, 1061ab64890Smrg XExtData *ext_data) 1071ab64890Smrg{ 1081ab64890Smrg ext_data->next = *structure; 1091ab64890Smrg *structure = ext_data; 1101ab64890Smrg return 1; 1111ab64890Smrg} 1121ab64890Smrg 1131ab64890SmrgXExtData *XFindOnExtensionList( 1141ab64890Smrg XExtData **structure, 1151ab64890Smrg int number) 1161ab64890Smrg{ 1171ab64890Smrg XExtData *ext; 1181ab64890Smrg 1191ab64890Smrg ext = *structure; 1201ab64890Smrg while (ext && (ext->number != number)) 1211ab64890Smrg ext = ext->next; 1221ab64890Smrg return ext; 1231ab64890Smrg} 1241ab64890Smrg 1251ab64890Smrg/* 1261ab64890Smrg * Routines to hang procs on the extension structure. 1271ab64890Smrg */ 1281ab64890SmrgCreateGCType XESetCreateGC( 1291ab64890Smrg Display *dpy, /* display */ 1301ab64890Smrg int extension, /* extension number */ 1311ab64890Smrg CreateGCType proc) /* routine to call when GC created */ 1321ab64890Smrg{ 1331ab64890Smrg register _XExtension *e; /* for lookup of extension */ 1341ab64890Smrg register CreateGCType oldproc; 1351ab64890Smrg if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL); 1361ab64890Smrg LockDisplay(dpy); 1371ab64890Smrg oldproc = e->create_GC; 1381ab64890Smrg e->create_GC = proc; 1391ab64890Smrg UnlockDisplay(dpy); 1401ab64890Smrg return (CreateGCType)oldproc; 1411ab64890Smrg} 1421ab64890Smrg 1431ab64890SmrgCopyGCType XESetCopyGC( 1441ab64890Smrg Display *dpy, /* display */ 1451ab64890Smrg int extension, /* extension number */ 1461ab64890Smrg CopyGCType proc) /* routine to call when GC copied */ 1471ab64890Smrg{ 1481ab64890Smrg register _XExtension *e; /* for lookup of extension */ 1491ab64890Smrg register CopyGCType oldproc; 1501ab64890Smrg if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL); 1511ab64890Smrg LockDisplay(dpy); 1521ab64890Smrg oldproc = e->copy_GC; 1531ab64890Smrg e->copy_GC = proc; 1541ab64890Smrg UnlockDisplay(dpy); 1551ab64890Smrg return (CopyGCType)oldproc; 1561ab64890Smrg} 1571ab64890Smrg 1581ab64890SmrgFlushGCType XESetFlushGC( 1591ab64890Smrg Display *dpy, /* display */ 1601ab64890Smrg int extension, /* extension number */ 1611ab64890Smrg FlushGCType proc) /* routine to call when GC copied */ 1621ab64890Smrg{ 1631ab64890Smrg register _XExtension *e; /* for lookup of extension */ 1641ab64890Smrg register FlushGCType oldproc; 1651ab64890Smrg if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL); 1661ab64890Smrg LockDisplay(dpy); 1671ab64890Smrg oldproc = e->flush_GC; 1681ab64890Smrg e->flush_GC = proc; 1691ab64890Smrg UnlockDisplay(dpy); 1701ab64890Smrg return (FlushGCType)oldproc; 1711ab64890Smrg} 1721ab64890Smrg 1731ab64890SmrgFreeGCType XESetFreeGC( 1741ab64890Smrg Display *dpy, /* display */ 1751ab64890Smrg int extension, /* extension number */ 1761ab64890Smrg FreeGCType proc) /* routine to call when GC freed */ 1771ab64890Smrg{ 1781ab64890Smrg register _XExtension *e; /* for lookup of extension */ 1791ab64890Smrg register FreeGCType oldproc; 1801ab64890Smrg if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL); 1811ab64890Smrg LockDisplay(dpy); 1821ab64890Smrg oldproc = e->free_GC; 1831ab64890Smrg e->free_GC = proc; 1841ab64890Smrg UnlockDisplay(dpy); 1851ab64890Smrg return (FreeGCType)oldproc; 1861ab64890Smrg} 1871ab64890Smrg 1881ab64890SmrgCreateFontType XESetCreateFont( 1891ab64890Smrg Display *dpy, /* display */ 1901ab64890Smrg int extension, /* extension number */ 1911ab64890Smrg CreateFontType proc) /* routine to call when font created */ 1921ab64890Smrg{ 1931ab64890Smrg register _XExtension *e; /* for lookup of extension */ 1941ab64890Smrg register CreateFontType oldproc; 1951ab64890Smrg if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL); 1961ab64890Smrg LockDisplay(dpy); 1971ab64890Smrg oldproc = e->create_Font; 1981ab64890Smrg e->create_Font = proc; 1991ab64890Smrg UnlockDisplay(dpy); 2001ab64890Smrg return (CreateFontType)oldproc; 2011ab64890Smrg} 2021ab64890Smrg 2031ab64890SmrgFreeFontType XESetFreeFont( 2041ab64890Smrg Display *dpy, /* display */ 2051ab64890Smrg int extension, /* extension number */ 2061ab64890Smrg FreeFontType proc) /* routine to call when font freed */ 2071ab64890Smrg{ 2081ab64890Smrg register _XExtension *e; /* for lookup of extension */ 2091ab64890Smrg register FreeFontType oldproc; 2101ab64890Smrg if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL); 2111ab64890Smrg LockDisplay(dpy); 2121ab64890Smrg oldproc = e->free_Font; 2131ab64890Smrg e->free_Font = proc; 2141ab64890Smrg UnlockDisplay(dpy); 2151ab64890Smrg return (FreeFontType)oldproc; 2161ab64890Smrg} 2171ab64890Smrg 2181ab64890SmrgCloseDisplayType XESetCloseDisplay( 2191ab64890Smrg Display *dpy, /* display */ 2201ab64890Smrg int extension, /* extension number */ 2211ab64890Smrg CloseDisplayType proc) /* routine to call when display closed */ 2221ab64890Smrg{ 2231ab64890Smrg register _XExtension *e; /* for lookup of extension */ 2241ab64890Smrg register CloseDisplayType oldproc; 2251ab64890Smrg if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL); 2261ab64890Smrg LockDisplay(dpy); 2271ab64890Smrg oldproc = e->close_display; 2281ab64890Smrg e->close_display = proc; 2291ab64890Smrg UnlockDisplay(dpy); 2301ab64890Smrg return (CloseDisplayType)oldproc; 2311ab64890Smrg} 2321ab64890Smrg 2331ab64890Smrgtypedef Bool (*WireToEventType) ( 2341ab64890Smrg Display* /* display */, 2351ab64890Smrg XEvent* /* re */, 2361ab64890Smrg xEvent* /* event */ 2371ab64890Smrg); 2381ab64890Smrg 2391ab64890SmrgWireToEventType XESetWireToEvent( 2401ab64890Smrg Display *dpy, /* display */ 2411ab64890Smrg int event_number, /* event routine to replace */ 2421ab64890Smrg WireToEventType proc) /* routine to call when converting event */ 2431ab64890Smrg{ 2441ab64890Smrg register WireToEventType oldproc; 2451ab64890Smrg if (proc == NULL) proc = (WireToEventType)_XUnknownWireEvent; 2461ab64890Smrg LockDisplay (dpy); 2471ab64890Smrg oldproc = dpy->event_vec[event_number]; 2481ab64890Smrg dpy->event_vec[event_number] = proc; 2491ab64890Smrg UnlockDisplay (dpy); 2501ab64890Smrg return (WireToEventType)oldproc; 2511ab64890Smrg} 2521ab64890Smrg 253b4ee4795Smrgtypedef Bool (*WireToEventCookieType) ( 254b4ee4795Smrg Display* /* display */, 255b4ee4795Smrg XGenericEventCookie* /* re */, 256b4ee4795Smrg xEvent* /* event */ 257b4ee4795Smrg); 258b4ee4795Smrg 259b4ee4795SmrgWireToEventCookieType XESetWireToEventCookie( 260b4ee4795Smrg Display *dpy, /* display */ 261b4ee4795Smrg int extension, /* extension major opcode */ 262b4ee4795Smrg WireToEventCookieType proc /* routine to call for generic events */ 263b4ee4795Smrg ) 264b4ee4795Smrg{ 265b4ee4795Smrg WireToEventCookieType oldproc; 266b4ee4795Smrg if (proc == NULL) proc = (WireToEventCookieType)_XUnknownWireEventCookie; 267b4ee4795Smrg LockDisplay (dpy); 268b4ee4795Smrg oldproc = dpy->generic_event_vec[extension & 0x7F]; 269b4ee4795Smrg dpy->generic_event_vec[extension & 0x7F] = proc; 270b4ee4795Smrg UnlockDisplay (dpy); 271b4ee4795Smrg return (WireToEventCookieType)oldproc; 272b4ee4795Smrg} 273b4ee4795Smrg 274b4ee4795Smrgtypedef Bool (*CopyEventCookieType) ( 275b4ee4795Smrg Display* /* display */, 276b4ee4795Smrg XGenericEventCookie* /* in */, 277b4ee4795Smrg XGenericEventCookie* /* out */ 278b4ee4795Smrg); 279b4ee4795Smrg 280b4ee4795SmrgCopyEventCookieType XESetCopyEventCookie( 281b4ee4795Smrg Display *dpy, /* display */ 282b4ee4795Smrg int extension, /* extension major opcode */ 283b4ee4795Smrg CopyEventCookieType proc /* routine to copy generic events */ 284b4ee4795Smrg ) 285b4ee4795Smrg{ 286b4ee4795Smrg CopyEventCookieType oldproc; 287b4ee4795Smrg if (proc == NULL) proc = (CopyEventCookieType)_XUnknownCopyEventCookie; 288b4ee4795Smrg LockDisplay (dpy); 289b4ee4795Smrg oldproc = dpy->generic_event_copy_vec[extension & 0x7F]; 290b4ee4795Smrg dpy->generic_event_copy_vec[extension & 0x7F] = proc; 291b4ee4795Smrg UnlockDisplay (dpy); 292b4ee4795Smrg return (CopyEventCookieType)oldproc; 293b4ee4795Smrg} 294b4ee4795Smrg 295b4ee4795Smrg 2961ab64890Smrgtypedef Status (*EventToWireType) ( 2971ab64890Smrg Display* /* display */, 2981ab64890Smrg XEvent* /* re */, 2991ab64890Smrg xEvent* /* event */ 3001ab64890Smrg); 3011ab64890Smrg 3021ab64890SmrgEventToWireType XESetEventToWire( 3031ab64890Smrg Display *dpy, /* display */ 3041ab64890Smrg int event_number, /* event routine to replace */ 3051ab64890Smrg EventToWireType proc) /* routine to call when converting event */ 3061ab64890Smrg{ 3071ab64890Smrg register EventToWireType oldproc; 3081ab64890Smrg if (proc == NULL) proc = (EventToWireType) _XUnknownNativeEvent; 3091ab64890Smrg LockDisplay (dpy); 3101ab64890Smrg oldproc = dpy->wire_vec[event_number]; 3111ab64890Smrg dpy->wire_vec[event_number] = proc; 3121ab64890Smrg UnlockDisplay(dpy); 3131ab64890Smrg return (EventToWireType)oldproc; 3141ab64890Smrg} 3151ab64890Smrg 3161ab64890Smrgtypedef Bool (*WireToErrorType) ( 3171ab64890Smrg Display* /* display */, 3181ab64890Smrg XErrorEvent* /* he */, 3191ab64890Smrg xError* /* we */ 3201ab64890Smrg); 3211ab64890Smrg 3221ab64890SmrgWireToErrorType XESetWireToError( 3231ab64890Smrg Display *dpy, /* display */ 3241ab64890Smrg int error_number, /* error routine to replace */ 3251ab64890Smrg WireToErrorType proc) /* routine to call when converting error */ 3261ab64890Smrg{ 3271ab64890Smrg register WireToErrorType oldproc = NULL; 3281ab64890Smrg if (proc == NULL) proc = (WireToErrorType)_XDefaultWireError; 3291ab64890Smrg LockDisplay (dpy); 3301ab64890Smrg if (!dpy->error_vec) { 3311ab64890Smrg int i; 3321ab64890Smrg dpy->error_vec = Xmalloc(256 * sizeof(oldproc)); 3331ab64890Smrg for (i = 1; i < 256; i++) 3341ab64890Smrg dpy->error_vec[i] = _XDefaultWireError; 3351ab64890Smrg } 3361ab64890Smrg if (dpy->error_vec) { 3371ab64890Smrg oldproc = dpy->error_vec[error_number]; 3381ab64890Smrg dpy->error_vec[error_number] = proc; 3391ab64890Smrg } 3401ab64890Smrg UnlockDisplay (dpy); 3411ab64890Smrg return (WireToErrorType)oldproc; 3421ab64890Smrg} 3431ab64890Smrg 3441ab64890SmrgErrorType XESetError( 3451ab64890Smrg Display *dpy, /* display */ 3461ab64890Smrg int extension, /* extension number */ 3471ab64890Smrg ErrorType proc) /* routine to call when X error happens */ 3481ab64890Smrg{ 3491ab64890Smrg register _XExtension *e; /* for lookup of extension */ 3501ab64890Smrg register ErrorType oldproc; 3511ab64890Smrg if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL); 3521ab64890Smrg LockDisplay(dpy); 3531ab64890Smrg oldproc = e->error; 3541ab64890Smrg e->error = proc; 3551ab64890Smrg UnlockDisplay(dpy); 3561ab64890Smrg return (ErrorType)oldproc; 3571ab64890Smrg} 3581ab64890Smrg 3591ab64890SmrgErrorStringType XESetErrorString( 3601ab64890Smrg Display *dpy, /* display */ 3611ab64890Smrg int extension, /* extension number */ 3621ab64890Smrg ErrorStringType proc) /* routine to call when I/O error happens */ 3631ab64890Smrg{ 3641ab64890Smrg register _XExtension *e; /* for lookup of extension */ 3651ab64890Smrg register ErrorStringType oldproc; 3661ab64890Smrg if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL); 3671ab64890Smrg LockDisplay(dpy); 3681ab64890Smrg oldproc = e->error_string; 3691ab64890Smrg e->error_string = proc; 3701ab64890Smrg UnlockDisplay(dpy); 3711ab64890Smrg return (ErrorStringType)oldproc; 3721ab64890Smrg} 3731ab64890Smrg 3741ab64890SmrgPrintErrorType XESetPrintErrorValues( 3751ab64890Smrg Display *dpy, /* display */ 3761ab64890Smrg int extension, /* extension number */ 3771ab64890Smrg PrintErrorType proc) /* routine to call to print */ 3781ab64890Smrg{ 3791ab64890Smrg register _XExtension *e; /* for lookup of extension */ 3801ab64890Smrg register PrintErrorType oldproc; 3811ab64890Smrg if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL); 3821ab64890Smrg LockDisplay(dpy); 3831ab64890Smrg oldproc = e->error_values; 3841ab64890Smrg e->error_values = proc; 3851ab64890Smrg UnlockDisplay(dpy); 3861ab64890Smrg return (PrintErrorType)oldproc; 3871ab64890Smrg} 3881ab64890Smrg 3891ab64890SmrgBeforeFlushType XESetBeforeFlush( 3901ab64890Smrg Display *dpy, /* display */ 3911ab64890Smrg int extension, /* extension number */ 3921ab64890Smrg BeforeFlushType proc) /* routine to call on flush */ 3931ab64890Smrg{ 3941ab64890Smrg register _XExtension *e; /* for lookup of extension */ 3951ab64890Smrg register BeforeFlushType oldproc; 3961ab64890Smrg register _XExtension *ext; 3971ab64890Smrg if ((e = XLookupExtension (dpy, extension)) == NULL) return (NULL); 3981ab64890Smrg LockDisplay(dpy); 3991ab64890Smrg oldproc = e->before_flush; 4001ab64890Smrg e->before_flush = proc; 4011ab64890Smrg for (ext = dpy->flushes; ext && ext != e; ext = ext->next) 4021ab64890Smrg ; 4031ab64890Smrg if (!ext) { 4041ab64890Smrg e->next_flush = dpy->flushes; 4051ab64890Smrg dpy->flushes = e; 40661b2299dSmrg } 4071ab64890Smrg UnlockDisplay(dpy); 4081ab64890Smrg return (BeforeFlushType)oldproc; 4091ab64890Smrg} 410