Path: blob/main/system/include/X11/extensions/extutil.h
6162 views
/*1*2Copyright 1989, 1998 The Open Group34Permission to use, copy, modify, distribute, and sell this software and its5documentation for any purpose is hereby granted without fee, provided that6the above copyright notice appear in all copies and that both that7copyright notice and this permission notice appear in supporting8documentation.910The above copyright notice and this permission notice shall be included in11all copies or substantial portions of the Software.1213THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR14IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,15FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE16OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN17AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN18CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.1920Except as contained in this notice, the name of The Open Group shall not be21used in advertising or otherwise to promote the sale, use or other dealings22in this Software without prior written authorization from The Open Group.23*24* Author: Jim Fulton, MIT The Open Group25*26* Xlib Extension-Writing Utilities27*28* This package contains utilities for writing the client API for various29* protocol extensions. THESE INTERFACES ARE NOT PART OF THE X STANDARD AND30* ARE SUBJECT TO CHANGE!31*/3233#ifndef _EXTUTIL_H_34#define _EXTUTIL_H_3536#include <X11/extensions/Xext.h>3738/*39* We need to keep a list of open displays since the Xlib display list isn't40* public. We also have to per-display info in a separate block since it isn't41* stored directly in the Display structure.42*/43typedef struct _XExtDisplayInfo {44struct _XExtDisplayInfo *next; /* keep a linked list */45Display *display; /* which display this is */46XExtCodes *codes; /* the extension protocol codes */47XPointer data; /* extra data for extension to use */48} XExtDisplayInfo;4950typedef struct _XExtensionInfo {51XExtDisplayInfo *head; /* start of list */52XExtDisplayInfo *cur; /* most recently used */53int ndisplays; /* number of displays */54} XExtensionInfo;5556typedef struct _XExtensionHooks {57int (*create_gc)(58Display* /* display */,59GC /* gc */,60XExtCodes* /* codes */61);62int (*copy_gc)(63Display* /* display */,64GC /* gc */,65XExtCodes* /* codes */66);67int (*flush_gc)(68Display* /* display */,69GC /* gc */,70XExtCodes* /* codes */71);72int (*free_gc)(73Display* /* display */,74GC /* gc */,75XExtCodes* /* codes */76);77int (*create_font)(78Display* /* display */,79XFontStruct* /* fs */,80XExtCodes* /* codes */81);82int (*free_font)(83Display* /* display */,84XFontStruct* /* fs */,85XExtCodes* /* codes */86);87int (*close_display)(88Display* /* display */,89XExtCodes* /* codes */90);91Bool (*wire_to_event)(92Display* /* display */,93XEvent* /* re */,94xEvent* /* event */95);96Status (*event_to_wire)(97Display* /* display */,98XEvent* /* re */,99xEvent* /* event */100);101int (*error)(102Display* /* display */,103xError* /* err */,104XExtCodes* /* codes */,105int* /* ret_code */106);107char *(*error_string)(108Display* /* display */,109int /* code */,110XExtCodes* /* codes */,111char* /* buffer */,112int /* nbytes */113);114} XExtensionHooks;115116extern XExtensionInfo *XextCreateExtension(117void118);119extern void XextDestroyExtension(120XExtensionInfo* /* info */121);122extern XExtDisplayInfo *XextAddDisplay(123XExtensionInfo* /* extinfo */,124Display* /* dpy */,125_Xconst char* /* ext_name */,126XExtensionHooks* /* hooks */,127int /* nevents */,128XPointer /* data */129);130extern int XextRemoveDisplay(131XExtensionInfo* /* extinfo */,132Display* /* dpy */133);134extern XExtDisplayInfo *XextFindDisplay(135XExtensionInfo* /* extinfo */,136Display* /* dpy */137);138139#define XextHasExtension(i) ((i) && ((i)->codes))140#define XextCheckExtension(dpy,i,name,val) \141if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return val; }142#define XextSimpleCheckExtension(dpy,i,name) \143if (!XextHasExtension(i)) { XMissingExtension (dpy, name); return; }144145146/*147* helper macros to generate code that is common to all extensions; caller148* should prefix it with static if extension source is in one file; this149* could be a utility function, but have to stack 6 unused arguments for150* something that is called many, many times would be bad.151*/152#define XEXT_GENERATE_FIND_DISPLAY(proc,extinfo,extname,hooks,nev,data) \153XExtDisplayInfo *proc (Display *dpy) \154{ \155XExtDisplayInfo *dpyinfo; \156if (!extinfo) { if (!(extinfo = XextCreateExtension())) return NULL; } \157if (!(dpyinfo = XextFindDisplay (extinfo, dpy))) \158dpyinfo = XextAddDisplay (extinfo,dpy,extname,hooks,nev,data); \159return dpyinfo; \160}161162#define XEXT_FIND_DISPLAY_PROTO(proc) \163XExtDisplayInfo *proc(Display *dpy)164165#define XEXT_GENERATE_CLOSE_DISPLAY(proc,extinfo) \166int proc (Display *dpy, XExtCodes *codes) \167{ \168return XextRemoveDisplay (extinfo, dpy); \169}170171#define XEXT_CLOSE_DISPLAY_PROTO(proc) \172int proc(Display *dpy, XExtCodes *codes)173174#define XEXT_GENERATE_ERROR_STRING(proc,extname,nerr,errl) \175char *proc (Display *dpy, int code, XExtCodes *codes, char *buf, int n) \176{ \177code -= codes->first_error; \178if (code >= 0 && code < nerr) { \179char tmp[256]; \180sprintf (tmp, "%s.%d", extname, code); \181XGetErrorDatabaseText (dpy, "XProtoError", tmp, errl[code], buf, n); \182return buf; \183} \184return (char *)0; \185}186187#define XEXT_ERROR_STRING_PROTO(proc) \188char *proc(Display *dpy, int code, XExtCodes *codes, char *buf, int n)189#endif190191192