aboutsummaryrefslogtreecommitdiff
path: root/nx-X11/lib/Xext
diff options
context:
space:
mode:
authorReinhard Tartler <siretart@tauware.de>2011-10-10 17:43:39 +0200
committerReinhard Tartler <siretart@tauware.de>2011-10-10 17:43:39 +0200
commitf4092abdf94af6a99aff944d6264bc1284e8bdd4 (patch)
tree2ac1c9cc16ceb93edb2c4382c088dac5aeafdf0f /nx-X11/lib/Xext
parenta840692edc9c6d19cd7c057f68e39c7d95eb767d (diff)
downloadnx-libs-f4092abdf94af6a99aff944d6264bc1284e8bdd4.tar.gz
nx-libs-f4092abdf94af6a99aff944d6264bc1284e8bdd4.tar.bz2
nx-libs-f4092abdf94af6a99aff944d6264bc1284e8bdd4.zip
Imported nx-X11-3.1.0-1.tar.gznx-X11/3.1.0-1
Summary: Imported nx-X11-3.1.0-1.tar.gz Keywords: Imported nx-X11-3.1.0-1.tar.gz into Git repository
Diffstat (limited to 'nx-X11/lib/Xext')
-rw-r--r--nx-X11/lib/Xext/DPMS.c293
-rw-r--r--nx-X11/lib/Xext/Imakefile46
-rw-r--r--nx-X11/lib/Xext/MITMisc.c133
-rw-r--r--nx-X11/lib/Xext/XAppgroup.c391
-rw-r--r--nx-X11/lib/Xext/XEVI.c213
-rw-r--r--nx-X11/lib/Xext/XLbx.c129
-rw-r--r--nx-X11/lib/Xext/XMultibuf.c714
-rw-r--r--nx-X11/lib/Xext/XSecurity.c310
-rw-r--r--nx-X11/lib/Xext/XShape.c490
-rw-r--r--nx-X11/lib/Xext/XShm.c437
-rw-r--r--nx-X11/lib/Xext/XSync.c817
-rw-r--r--nx-X11/lib/Xext/XTestExt1.c1321
-rw-r--r--nx-X11/lib/Xext/Xcup.c265
-rw-r--r--nx-X11/lib/Xext/Xdbe.c474
-rw-r--r--nx-X11/lib/Xext/Xext-def.cpp140
-rw-r--r--nx-X11/lib/Xext/extutil.c273
-rw-r--r--nx-X11/lib/Xext/globals.c90
17 files changed, 6536 insertions, 0 deletions
diff --git a/nx-X11/lib/Xext/DPMS.c b/nx-X11/lib/Xext/DPMS.c
new file mode 100644
index 000000000..35b21b4ad
--- /dev/null
+++ b/nx-X11/lib/Xext/DPMS.c
@@ -0,0 +1,293 @@
+/* $Xorg: DPMS.c,v 1.3 2000/08/17 19:45:50 cpqbld Exp $ */
+/*****************************************************************
+
+Copyright (c) 1996 Digital Equipment Corporation, Maynard, Massachusetts.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+DIGITAL EQUIPMENT CORPORATION BE LIABLE FOR ANY CLAIM, DAMAGES, INCLUDING,
+BUT NOT LIMITED TO CONSEQUENTIAL OR INCIDENTAL DAMAGES, OR OTHER LIABILITY,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
+IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of Digital Equipment Corporation
+shall not be used in advertising or otherwise to promote the sale, use or other
+dealings in this Software without prior written authorization from Digital
+Equipment Corporation.
+
+******************************************************************/
+/* $XFree86: xc/lib/Xext/DPMS.c,v 3.5 2002/10/16 00:37:27 dawes Exp $ */
+
+/*
+ * HISTORY
+ */
+
+#define NEED_REPLIES
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <X11/extensions/dpms.h>
+#include <X11/extensions/dpmsstr.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+#include <stdio.h>
+
+static XExtensionInfo _dpms_info_data;
+static XExtensionInfo *dpms_info = &_dpms_info_data;
+static char *dpms_extension_name = DPMSExtensionName;
+
+#define DPMSCheckExtension(dpy,i,val) \
+ XextCheckExtension (dpy, i, dpms_extension_name, val)
+
+/*****************************************************************************
+ * *
+ * private utility routines *
+ * *
+ *****************************************************************************/
+
+static int close_display(Display *dpy, XExtCodes *codes);
+static /* const */ XExtensionHooks dpms_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ close_display, /* close_display */
+ NULL, /* wire_to_event */
+ NULL, /* event_to_wire */
+ NULL, /* error */
+ NULL /* error_string */
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (find_display, dpms_info,
+ dpms_extension_name,
+ &dpms_extension_hooks, DPMSNumberEvents,
+ NULL)
+
+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, dpms_info)
+
+/*****************************************************************************
+ * *
+ * public routines *
+ * *
+ *****************************************************************************/
+
+Bool
+DPMSQueryExtension (Display *dpy, int *event_basep, int *error_basep)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+
+ if (XextHasExtension(info)) {
+ *event_basep = info->codes->first_event;
+ *error_basep = info->codes->first_error;
+ return True;
+ } else {
+ return False;
+ }
+}
+
+Status
+DPMSGetVersion(Display *dpy, int *major_versionp, int *minor_versionp)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xDPMSGetVersionReply rep;
+ register xDPMSGetVersionReq *req;
+
+ DPMSCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ GetReq (DPMSGetVersion, req);
+ req->reqType = info->codes->major_opcode;
+ req->dpmsReqType = X_DPMSGetVersion;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 0;
+ }
+ *major_versionp = rep.majorVersion;
+ *minor_versionp = rep.minorVersion;
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 1;
+}
+
+Bool
+DPMSCapable(Display *dpy)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xDPMSCapableReq *req;
+ xDPMSCapableReply rep;
+
+ DPMSCheckExtension (dpy, info, 0);
+
+ LockDisplay(dpy);
+ GetReq(DPMSCapable, req);
+ req->reqType = info->codes->major_opcode;
+ req->dpmsReqType = X_DPMSCapable;
+
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return rep.capable;
+}
+
+Status
+DPMSSetTimeouts(Display *dpy, CARD16 standby, CARD16 suspend, CARD16 off)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xDPMSSetTimeoutsReq *req;
+
+ if ((off != 0)&&(off < suspend))
+ {
+ return BadValue;
+ }
+ if ((suspend != 0)&&(suspend < standby))
+ {
+ return BadValue;
+ }
+
+ DPMSCheckExtension (dpy, info, 0);
+ LockDisplay(dpy);
+ GetReq(DPMSSetTimeouts, req);
+ req->reqType = info->codes->major_opcode;
+ req->dpmsReqType = X_DPMSSetTimeouts;
+ req->standby = standby;
+ req->suspend = suspend;
+ req->off = off;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
+Bool
+DPMSGetTimeouts(Display *dpy, CARD16 *standby, CARD16 *suspend, CARD16 *off)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xDPMSGetTimeoutsReq *req;
+ xDPMSGetTimeoutsReply rep;
+
+ DPMSCheckExtension (dpy, info, 0);
+
+ LockDisplay(dpy);
+ GetReq(DPMSGetTimeouts, req);
+ req->reqType = info->codes->major_opcode;
+ req->dpmsReqType = X_DPMSGetTimeouts;
+
+ if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ *standby = rep.standby;
+ *suspend = rep.suspend;
+ *off = rep.off;
+ return 1;
+}
+
+Status
+DPMSEnable(Display *dpy)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xDPMSEnableReq *req;
+
+ DPMSCheckExtension (dpy, info, 0);
+ LockDisplay(dpy);
+ GetReq(DPMSEnable, req);
+ req->reqType = info->codes->major_opcode;
+ req->dpmsReqType = X_DPMSEnable;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
+Status
+DPMSDisable(Display *dpy)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xDPMSDisableReq *req;
+
+ DPMSCheckExtension (dpy, info, 0);
+ LockDisplay(dpy);
+ GetReq(DPMSDisable, req);
+ req->reqType = info->codes->major_opcode;
+ req->dpmsReqType = X_DPMSDisable;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
+
+Status
+DPMSForceLevel(Display *dpy, CARD16 level)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xDPMSForceLevelReq *req;
+
+ DPMSCheckExtension (dpy, info, 0);
+
+ if ((level != DPMSModeOn) &&
+ (level != DPMSModeStandby) &&
+ (level != DPMSModeSuspend) &&
+ (level != DPMSModeOff))
+ return BadValue;
+
+ LockDisplay(dpy);
+ GetReq(DPMSForceLevel, req);
+ req->reqType = info->codes->major_opcode;
+ req->dpmsReqType = X_DPMSForceLevel;
+ req->level = level;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
+Status
+DPMSInfo(Display *dpy, CARD16 *power_level, BOOL *state)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xDPMSInfoReq *req;
+ xDPMSInfoReply rep;
+
+ DPMSCheckExtension (dpy, info, 0);
+
+ LockDisplay(dpy);
+ GetReq(DPMSInfo, req);
+ req->reqType = info->codes->major_opcode;
+ req->dpmsReqType = X_DPMSInfo;
+
+ if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ *power_level = rep.power_level;
+ *state = rep.state;
+ return 1;
+}
+
+
+
diff --git a/nx-X11/lib/Xext/Imakefile b/nx-X11/lib/Xext/Imakefile
new file mode 100644
index 000000000..b323dc7c2
--- /dev/null
+++ b/nx-X11/lib/Xext/Imakefile
@@ -0,0 +1,46 @@
+XCOMM $Xorg: Imakefile,v 1.3 2000/08/17 19:45:50 cpqbld Exp $
+
+
+
+
+XCOMM $XFree86: xc/lib/Xext/Imakefile,v 1.12 2002/10/16 00:37:27 dawes Exp $
+
+#define DoNormalLib NormalLibXext
+#define DoSharedLib SharedLibXext
+#define DoExtraLib SharedLibXext
+#define DoDebugLib DebugLibXext
+#define DoProfileLib ProfileLibXext
+#define LibName Xext
+#define SoRev SOXEXTREV
+#define LibHeaders NO
+
+#include <Threads.tmpl>
+
+#ifdef SharedXextReqs
+REQUIREDLIBS = SharedXextReqs
+#endif
+
+#if HasShm
+ SHMSRCS = XShm.c
+ SHMOBJS = XShm.o
+#endif
+
+#if Malloc0ReturnsNull
+ALLOC_DEFINES = Malloc0ReturnsNullDefines
+#endif
+
+ DEFINES = $(ALLOC_DEFINES)
+ INCLUDES = -I$(XLIBSRC)
+ SRCS = globals.c extutil.c XMultibuf.c XShape.c $(SHMSRCS) \
+ MITMisc.c XTestExt1.c XSync.c Xdbe.c XLbx.c \
+ XSecurity.c XAppgroup.c Xcup.c DPMS.c XEVI.c
+ OBJS = globals.o extutil.o XMultibuf.o XShape.o $(SHMOBJS) \
+ MITMisc.o XTestExt1.o XSync.o Xdbe.o XLbx.o \
+ XSecurity.o XAppgroup.o Xcup.o DPMS.o XEVI.o
+ LINTLIBS = $(LINTXLIB)
+
+#include <Library.tmpl>
+
+LinkFile(ImUtil.h,$(XLIBSRC)/ImUtil.h)
+
+DependTarget()
diff --git a/nx-X11/lib/Xext/MITMisc.c b/nx-X11/lib/Xext/MITMisc.c
new file mode 100644
index 000000000..c0fa87209
--- /dev/null
+++ b/nx-X11/lib/Xext/MITMisc.c
@@ -0,0 +1,133 @@
+/*
+ * $Xorg: MITMisc.c,v 1.4 2001/02/09 02:03:49 xorgcvs Exp $
+ *
+Copyright 1989, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ *
+ */
+/* $XFree86: xc/lib/Xext/MITMisc.c,v 1.3 2002/10/16 00:37:27 dawes Exp $ */
+
+/* RANDOM CRUFT! THIS HAS NO OFFICIAL X CONSORTIUM BLESSING */
+
+#define NEED_REPLIES
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <X11/extensions/MITMisc.h>
+#include <X11/extensions/mitmiscstr.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+
+static XExtensionInfo _mit_info_data;
+static XExtensionInfo *mit_info = &_mit_info_data;
+static /* const */ char *mit_extension_name = MITMISCNAME;
+
+#define MITCheckExtension(dpy,i,val) \
+ XextCheckExtension (dpy, i, mit_extension_name, val)
+
+/*****************************************************************************
+ * *
+ * private utility routines *
+ * *
+ *****************************************************************************/
+
+static int close_display(Display *dpy, XExtCodes *codes);
+static /* const */ XExtensionHooks mit_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ close_display, /* close_display */
+ NULL, /* wire_to_event */
+ NULL, /* event_to_wire */
+ NULL, /* error */
+ NULL /* error_string */
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (find_display, mit_info, mit_extension_name,
+ &mit_extension_hooks, MITMiscNumberEvents,
+ NULL)
+
+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, mit_info)
+
+
+/*****************************************************************************
+ * *
+ * public routines *
+ * *
+ *****************************************************************************/
+
+Bool XMITMiscQueryExtension (Display *dpy, int *event_basep, int *error_basep)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+
+ if (XextHasExtension(info)) {
+ *event_basep = info->codes->first_event;
+ *error_basep = info->codes->first_error;
+ return True;
+ } else {
+ return False;
+ }
+}
+
+
+Status XMITMiscSetBugMode(Display *dpy, Bool onOff)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xMITSetBugModeReq *req;
+
+ MITCheckExtension (dpy, info, 0);
+
+ LockDisplay(dpy);
+ GetReq(MITSetBugMode, req);
+ req->reqType = info->codes->major_opcode;
+ req->mitReqType = X_MITSetBugMode;
+ req->onOff = onOff;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
+Bool XMITMiscGetBugMode(Display *dpy)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xMITGetBugModeReq *req;
+ xMITGetBugModeReply rep;
+
+ MITCheckExtension (dpy, info, 0);
+
+ LockDisplay(dpy);
+ GetReq(MITGetBugMode, req);
+ req->reqType = info->codes->major_opcode;
+ req->mitReqType = X_MITGetBugMode;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return rep.onOff;
+}
diff --git a/nx-X11/lib/Xext/XAppgroup.c b/nx-X11/lib/Xext/XAppgroup.c
new file mode 100644
index 000000000..2ca3e4d21
--- /dev/null
+++ b/nx-X11/lib/Xext/XAppgroup.c
@@ -0,0 +1,391 @@
+/* $XFree86: xc/lib/Xext/XAppgroup.c,v 1.11 2002/10/16 02:19:22 dawes Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/* $Xorg: XAppgroup.c,v 1.5 2001/02/09 02:03:49 xorgcvs Exp $ */
+
+#ifdef WIN32
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xwindows.h>
+#endif
+
+#define NEED_EVENTS
+#define NEED_REPLIES
+#include <X11/Xlibint.h>
+#include <X11/extensions/Xagstr.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+
+#include <stdarg.h>
+
+struct xagstuff {
+ int attrib_mask;
+ Bool app_group_leader;
+ Bool single_screen;
+ Window default_root;
+ VisualID root_visual;
+ Colormap default_colormap;
+ unsigned long black_pixel;
+ unsigned long white_pixel;
+};
+
+static XExtensionInfo _xag_info_data;
+static XExtensionInfo *xag_info = &_xag_info_data;
+static char *xag_extension_name = XAGNAME;
+
+#define XagCheckExtension(dpy,i,val) \
+ XextCheckExtension (dpy, i, xag_extension_name, val)
+
+/*****************************************************************************
+ * *
+ * private utility routines *
+ * *
+ *****************************************************************************/
+
+static int close_display(Display *dpy, XExtCodes *codes);
+static /* const */ XExtensionHooks xag_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ close_display, /* close_display */
+ NULL, /* wire_to_event */
+ NULL, /* event_to_wire */
+ NULL, /* error */
+ NULL, /* error_string */
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (find_display, xag_info,
+ xag_extension_name,
+ &xag_extension_hooks,
+ 0, NULL)
+
+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xag_info)
+
+
+/*****************************************************************************
+ * *
+ * public Xag Extension routines *
+ * *
+ *****************************************************************************/
+
+Bool
+XagQueryVersion(
+ Display *dpy,
+ int *major_version_return,
+ int *minor_version_return)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xXagQueryVersionReply rep;
+ xXagQueryVersionReq *req;
+
+ XagCheckExtension (dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(XagQueryVersion, req);
+ req->reqType = info->codes->major_opcode;
+ req->xagReqType = X_XagQueryVersion;
+ req->client_major_version = XAG_MAJOR_VERSION;
+ req->client_minor_version = XAG_MINOR_VERSION;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ *major_version_return = rep.server_major_version;
+ *minor_version_return = rep.server_minor_version;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+static void
+StuffToWire (Display *dpy, struct xagstuff *stuff, xXagCreateReq *req)
+{
+ unsigned long values[8];
+ unsigned long* value = values;
+ unsigned int nvalues;
+
+ /* the order these are in is important */
+ if (stuff->attrib_mask & XagSingleScreenMask)
+ *value++ = stuff->single_screen;
+
+ if (stuff->attrib_mask & XagDefaultRootMask)
+ *value++ = stuff->default_root;
+
+ if (stuff->attrib_mask & XagRootVisualMask)
+ *value++ = stuff->root_visual;
+
+ if (stuff->attrib_mask & XagDefaultColormapMask)
+ *value++ = stuff->default_colormap;
+
+ if (stuff->attrib_mask & XagBlackPixelMask)
+ *value++ = stuff->black_pixel;
+
+ if (stuff->attrib_mask & XagWhitePixelMask)
+ *value++ = stuff->white_pixel;
+
+ if (stuff->attrib_mask & XagAppGroupLeaderMask)
+ *value++ = stuff->app_group_leader;
+
+ req->length += (nvalues = value - values);
+
+ nvalues <<= 2;
+ Data32 (dpy, (long*) values, (long) nvalues);
+}
+
+Bool
+XagCreateEmbeddedApplicationGroup(
+ Display* dpy,
+ VisualID root_visual,
+ Colormap default_colormap,
+ unsigned long black_pixel,
+ unsigned long white_pixel,
+ XAppGroup* app_group_return)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xXagCreateReq *req;
+ struct xagstuff stuff;
+
+ XagCheckExtension (dpy, info, False);
+
+ LockDisplay(dpy);
+ stuff.app_group_leader = True;
+ stuff.single_screen = True;
+ stuff.default_root = RootWindow (dpy, DefaultScreen(dpy));
+ stuff.root_visual = root_visual;
+ stuff.default_colormap = default_colormap;
+ stuff.attrib_mask =
+ XagAppGroupLeaderMask | XagSingleScreenMask | XagDefaultRootMask |
+ XagRootVisualMask | XagDefaultColormapMask;
+ if (default_colormap != None) {
+ stuff.black_pixel = black_pixel;
+ stuff.white_pixel = white_pixel;
+ stuff.attrib_mask |= XagBlackPixelMask | XagWhitePixelMask;
+ }
+ /* might do some validation here */
+ GetReq(XagCreate, req);
+ req->reqType = info->codes->major_opcode;
+ req->xagReqType = X_XagCreate;
+ *app_group_return = req->app_group = XAllocID(dpy);
+ req->attrib_mask = stuff.attrib_mask;
+ StuffToWire (dpy, &stuff, req);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XagCreateNonembeddedApplicationGroup(
+ Display* dpy,
+ XAppGroup* app_group_return)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xXagCreateReq *req;
+ struct xagstuff stuff;
+
+ XagCheckExtension (dpy, info, False);
+
+ LockDisplay(dpy);
+ stuff.app_group_leader = False;
+ stuff.single_screen = False;
+ stuff.attrib_mask = XagAppGroupLeaderMask | XagSingleScreenMask;
+ /* might do some validation here */
+ GetReq(XagCreate, req);
+ req->reqType = info->codes->major_opcode;
+ req->xagReqType = X_XagCreate;
+ *app_group_return = req->app_group = XAllocID(dpy);
+ req->attrib_mask = stuff.attrib_mask;
+ StuffToWire (dpy, &stuff, req);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool XagDestroyApplicationGroup(Display* dpy, XAppGroup app_group)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xXagDestroyReq *req;
+
+ XagCheckExtension (dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(XagDestroy, req);
+ req->reqType = info->codes->major_opcode;
+ req->xagReqType = X_XagDestroy;
+ req->app_group = app_group;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XagGetApplicationGroupAttributes(Display* dpy, XAppGroup app_group, ...)
+{
+ va_list var;
+ XExtDisplayInfo *info = find_display (dpy);
+ xXagGetAttrReq *req;
+ xXagGetAttrReply rep;
+ int attr;
+
+ XagCheckExtension (dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(XagGetAttr, req);
+ req->reqType = info->codes->major_opcode;
+ req->xagReqType = X_XagGetAttr;
+ req->app_group = app_group;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ va_start (var, app_group);
+ for (attr = va_arg(var, int); attr != 0; attr = va_arg(var, int)) {
+ void* ptr;
+
+ switch (attr) {
+ case XagNappGroupLeader:
+ ptr = va_arg(var, void*);
+ *(Bool*)ptr = rep.app_group_leader;
+ break;
+ case XagNsingleScreen:
+ ptr = va_arg(var, void*);
+ *(Bool*)ptr = rep.single_screen;
+ break;
+ case XagNdefaultRoot:
+ ptr = va_arg(var, void*);
+ *(Window*)ptr = rep.default_root;
+ break;
+ case XagNrootVisual:
+ ptr = va_arg(var, void*);
+ *(VisualID*)ptr = rep.root_visual;
+ break;
+ case XagNdefaultColormap:
+ ptr = va_arg(var, void*);
+ *(Colormap*)ptr = rep.default_colormap;
+ break;
+ case XagNblackPixel:
+ ptr = va_arg(var, void*);
+ *(unsigned long*)ptr = rep.black_pixel;
+ break;
+ case XagNwhitePixel:
+ ptr = va_arg(var, void*);
+ *(unsigned long*)ptr = rep.white_pixel;
+ break;
+ }
+ }
+ va_end (var);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XagQueryApplicationGroup(
+ Display* dpy,
+ XID resource,
+ XAppGroup* app_group_return)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xXagQueryReq *req;
+ xXagQueryReply rep;
+
+ XagCheckExtension (dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(XagQuery, req);
+ req->reqType = info->codes->major_opcode;
+ req->xagReqType = X_XagQuery;
+ req->resource = resource;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ *app_group_return = rep.app_group;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+
+}
+
+Bool
+XagCreateAssociation(Display* dpy, Window* window_return, void* system_window)
+{
+#ifdef WIN32
+ long tmp = *(HWND*) system_window;
+ XExtDisplayInfo *info = find_display (dpy);
+ xXagCreateAssocReq *req;
+
+ XagCheckExtension (dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(XagCreateAssoc, req);
+ req->reqType = info->codes->major_opcode;
+ req->xagReqType = X_XagCreateAssoc;
+ *window_return = req->window = XAllocID(dpy);
+ req->window_type = XagWindowTypeWin32;
+ req->system_window_len = sizeof(HWND);
+ Data32 (dpy, (long*) tmp, 1L);
+ req->length++;
+ UnlockDisplay(dpy);
+ SyncHandle();
+#else
+ /* other platforms go here */
+
+ /* this whole thing could be arranged better, but since X need
+ * only short-circuit the protocol and WIN32 is the only other
+ * platform the XC supports, it will suffice for now.
+ */
+ *window_return = *(Window*)system_window;
+#endif
+ return True;
+}
+
+Bool
+XagDestroyAssociation(Display* dpy, Window window)
+{
+#ifdef WIN32
+ XExtDisplayInfo *info = find_display (dpy);
+ xXagDestroyAssocReq *req;
+
+ XagCheckExtension (dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(XagDestroyAssoc, req);
+ req->reqType = info->codes->major_opcode;
+ req->xagReqType = X_XagDestroyAssoc;
+ req->window = window;
+ UnlockDisplay(dpy);
+ SyncHandle();
+#endif
+ return True;
+}
+
diff --git a/nx-X11/lib/Xext/XEVI.c b/nx-X11/lib/Xext/XEVI.c
new file mode 100644
index 000000000..a64b9c1ba
--- /dev/null
+++ b/nx-X11/lib/Xext/XEVI.c
@@ -0,0 +1,213 @@
+/* $Xorg: XEVI.c,v 1.3 2000/08/17 19:45:51 cpqbld Exp $ */
+/************************************************************
+Copyright (c) 1997 by Silicon Graphics Computer Systems, Inc.
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Silicon Graphics not be
+used in advertising or publicity pertaining to distribution
+of the software without specific prior written permission.
+Silicon Graphics makes no representation about the suitability
+of this software for any purpose. It is provided "as is"
+without any express or implied warranty.
+SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
+AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON
+GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL
+DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
+DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
+OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH
+THE USE OR PERFORMANCE OF THIS SOFTWARE.
+********************************************************/
+/* $XFree86$ */
+#define NEED_EVENTS
+#define NEED_REPLIES
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <X11/extensions/XEVI.h>
+#include <X11/extensions/XEVIstr.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+#include <X11/Xutil.h>
+static XExtensionInfo *xevi_info;/* needs to move to globals.c */
+static /* const */ char *xevi_extension_name = EVINAME;
+#define XeviCheckExtension(dpy,i,val) \
+ XextCheckExtension (dpy, i, xevi_extension_name, val)
+/*****************************************************************************
+ * *
+ * private utility routines *
+ * *
+ *****************************************************************************/
+static /* const */ XExtensionHooks xevi_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ NULL, /* close_display */
+ NULL, /* wire_to_event */
+ NULL, /* event_to_wire */
+ NULL, /* error */
+ NULL, /* error_string */
+};
+static XEXT_GENERATE_FIND_DISPLAY (find_display, xevi_info,
+ xevi_extension_name,
+ &xevi_extension_hooks, 0, NULL)
+Bool XeviQueryExtension (Display *dpy)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ if (XextHasExtension(info)) {
+ return True;
+ } else {
+ return False;
+ }
+}
+Bool XeviQueryVersion(Display *dpy, int *majorVersion, int *minorVersion)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xEVIQueryVersionReply rep;
+ register xEVIQueryVersionReq *req;
+ XeviCheckExtension (dpy, info, False);
+ LockDisplay(dpy);
+ GetReq(EVIQueryVersion, req);
+ req->reqType = info->codes->major_opcode;
+ req->xeviReqType = X_EVIQueryVersion;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ *majorVersion = rep.majorVersion;
+ *minorVersion = rep.minorVersion;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+static Bool notInList(VisualID32 *visual, int sz_visual, VisualID newVisualid)
+{
+ while (sz_visual-- > 0) {
+ if (*visual == newVisualid)
+ return False;
+ visual++;
+ }
+ return True;
+}
+Status XeviGetVisualInfo(
+ register Display *dpy,
+ VisualID *visual,
+ int n_visual,
+ ExtendedVisualInfo **evi_return,
+ int *n_info_return)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xEVIGetVisualInfoReq *req;
+ xEVIGetVisualInfoReply rep;
+ int sz_info, sz_xInfo, sz_conflict, sz_xConflict;
+ VisualID32 *temp_conflict, *temp_visual, *xConflictPtr;
+ VisualID *conflict;
+ xExtendedVisualInfo *temp_xInfo;
+ XVisualInfo *vinfo;
+ register ExtendedVisualInfo *infoPtr;
+ register xExtendedVisualInfo *xInfoPtr;
+ register int n_data, visualIndex, vinfoIndex;
+ Bool isValid;
+ XeviCheckExtension (dpy, info, 0);
+ *n_info_return = 0;
+ *evi_return = NULL;
+ vinfo = XGetVisualInfo(dpy, 0, NULL, &sz_info);
+ if (!vinfo) {
+ return BadValue;
+ }
+ if (!n_visual || !visual) { /* copy the all visual */
+ temp_visual = (VisualID32 *)Xmalloc(sz_VisualID32 * sz_info);
+ n_visual = 0;
+ for (vinfoIndex = 0; vinfoIndex < sz_info; vinfoIndex++)
+ if (notInList(temp_visual, n_visual, vinfo[vinfoIndex].visualid))
+ temp_visual[n_visual++] = vinfo[vinfoIndex].visualid;
+ }
+ else { /* check if the visual is valid */
+ for (visualIndex = 0; visualIndex < n_visual; visualIndex++) {
+ isValid = False;
+ for (vinfoIndex = 0; vinfoIndex < sz_info; vinfoIndex++) {
+ if (visual[visualIndex] == vinfo[vinfoIndex].visualid) {
+ isValid = True;
+ break;
+ }
+ }
+ if (!isValid) {
+ XFree(vinfo);
+ return BadValue;
+ }
+ }
+ temp_visual = (VisualID32 *)Xmalloc(sz_VisualID32 * n_visual);
+ for (visualIndex = 0; visualIndex < n_visual; visualIndex++)
+ temp_visual[visualIndex] = visual[visualIndex];
+ }
+ XFree(vinfo);
+ LockDisplay(dpy);
+ GetReq(EVIGetVisualInfo, req);
+ req->reqType = info->codes->major_opcode;
+ req->xeviReqType = X_EVIGetVisualInfo;
+ req->n_visual = n_visual;
+ SetReqLen(req, n_visual, 1);
+ Data(dpy, (char *)temp_visual, n_visual * sz_VisualID32);
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ Xfree(temp_visual);
+ return BadAccess;
+ }
+ Xfree(temp_visual);
+ sz_info = rep.n_info * sizeof(ExtendedVisualInfo);
+ sz_xInfo = rep.n_info * sz_xExtendedVisualInfo;
+ sz_conflict = rep.n_conflicts * sizeof(VisualID);
+ sz_xConflict = rep.n_conflicts * sz_VisualID32;
+ infoPtr = *evi_return = (ExtendedVisualInfo *)Xmalloc(sz_info + sz_conflict);
+ xInfoPtr = temp_xInfo = (xExtendedVisualInfo *)Xmalloc(sz_xInfo);
+ xConflictPtr = temp_conflict = (VisualID32 *)Xmalloc(sz_xConflict);
+ if (!*evi_return || !temp_xInfo || !temp_conflict) {
+ _XEatData(dpy, (sz_xInfo + sz_xConflict + 3) & ~3);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ if (evi_return)
+ Xfree(evi_return);
+ if (temp_xInfo)
+ Xfree(temp_xInfo);
+ if (temp_conflict)
+ Xfree(temp_conflict);
+ return BadAlloc;
+ }
+ _XRead(dpy, (char *)temp_xInfo, sz_xInfo);
+ _XRead(dpy, (char *)temp_conflict, sz_xConflict);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ n_data = rep.n_info;
+ conflict = (VisualID *)(infoPtr + n_data);
+ while (n_data-- > 0) {
+ infoPtr->core_visual_id = xInfoPtr->core_visual_id;
+ infoPtr->screen = xInfoPtr->screen;
+ infoPtr->level = xInfoPtr->level;
+ infoPtr->transparency_type = xInfoPtr->transparency_type;
+ infoPtr->transparency_value = xInfoPtr->transparency_value;
+ infoPtr->min_hw_colormaps = xInfoPtr->min_hw_colormaps;
+ infoPtr->max_hw_colormaps = xInfoPtr->max_hw_colormaps;
+ infoPtr->num_colormap_conflicts = xInfoPtr->num_colormap_conflicts;
+ infoPtr->colormap_conflicts = conflict;
+ conflict += infoPtr->num_colormap_conflicts;
+ infoPtr++;
+ xInfoPtr++;
+ }
+ n_data = rep.n_conflicts;
+ conflict = (VisualID *)(infoPtr);
+ while (n_data-- > 0)
+ *conflict++ = *xConflictPtr++;
+ Xfree(temp_xInfo);
+ Xfree(temp_conflict);
+ *n_info_return = rep.n_info;
+ return Success;
+}
diff --git a/nx-X11/lib/Xext/XLbx.c b/nx-X11/lib/Xext/XLbx.c
new file mode 100644
index 000000000..8c0cfad0b
--- /dev/null
+++ b/nx-X11/lib/Xext/XLbx.c
@@ -0,0 +1,129 @@
+/*
+ * $Xorg: XLbx.c,v 1.3 2000/08/17 19:45:51 cpqbld Exp $
+ *
+ * Copyright 1992 Network Computing Devices
+ *
+ * Permission to use, copy, modify, distribute, and sell this software and its
+ * documentation for any purpose is hereby granted without fee, provided that
+ * the above copyright notice appear in all copies and that both that
+ * copyright notice and this permission notice appear in supporting
+ * documentation, and that the name of NCD. not be used in advertising or
+ * publicity pertaining to distribution of the software without specific,
+ * written prior permission. NCD. makes no representations about the
+ * suitability of this software for any purpose. It is provided "as is"
+ * without express or implied warranty.
+ *
+ * NCD. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL NCD.
+ * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
+ * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
+ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ * Author: Keith Packard, Network Computing Devices
+ */
+/* $XFree86: xc/lib/Xext/XLbx.c,v 1.4 2002/10/16 00:37:27 dawes Exp $ */
+
+#define NEED_EVENTS
+#define NEED_REPLIES
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xlibint.h>
+#include <X11/extensions/XLbx.h>
+#include <X11/extensions/lbxstr.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+
+static XExtensionInfo _lbx_info_data;
+static XExtensionInfo *lbx_info = &_lbx_info_data;
+static /* const */ char *lbx_extension_name = LBXNAME;
+
+#define LbxCheckExtension(dpy,i,val) \
+ XextCheckExtension (dpy, i, lbx_extension_name, val)
+
+static int close_display(Display *dpy, XExtCodes *codes);
+static char *error_string(Display *dpy, int code, XExtCodes *codes,
+ char *buf, int n);
+static /* const */ XExtensionHooks lbx_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ close_display, /* close_display */
+ NULL, /* wire_to_event */
+ NULL, /* event_to_wire */
+ NULL, /* error */
+ error_string, /* error_string */
+};
+
+static /* const */ char *lbx_error_list[] = {
+ "BadLbxClient", /* BadLbxClient */
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (find_display, lbx_info, lbx_extension_name,
+ &lbx_extension_hooks, LbxNumberEvents, NULL)
+
+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, lbx_info)
+
+static XEXT_GENERATE_ERROR_STRING (error_string, lbx_extension_name,
+ LbxNumberErrors, lbx_error_list)
+
+
+Bool XLbxQueryExtension (
+ Display *dpy,
+ int *requestp, int *event_basep, int *error_basep)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+
+ if (XextHasExtension(info)) {
+ *requestp = info->codes->major_opcode;
+ *event_basep = info->codes->first_event;
+ *error_basep = info->codes->first_error;
+ return True;
+ } else {
+ return False;
+ }
+}
+
+
+int XLbxGetEventBase(Display *dpy)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+
+ if (XextHasExtension(info)) {
+ return info->codes->first_event;
+ } else {
+ return -1;
+ }
+}
+
+
+Bool XLbxQueryVersion(Display *dpy, int *majorVersion, int *minorVersion)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xLbxQueryVersionReply rep;
+ register xLbxQueryVersionReq *req;
+
+ LbxCheckExtension (dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(LbxQueryVersion, req);
+ req->reqType = info->codes->major_opcode;
+ req->lbxReqType = X_LbxQueryVersion;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ *majorVersion = rep.majorVersion;
+ *minorVersion = rep.minorVersion;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+/* all other requests will run after Xlib has lost the wire ... */
diff --git a/nx-X11/lib/Xext/XMultibuf.c b/nx-X11/lib/Xext/XMultibuf.c
new file mode 100644
index 000000000..3e0049e92
--- /dev/null
+++ b/nx-X11/lib/Xext/XMultibuf.c
@@ -0,0 +1,714 @@
+/*
+ * $Xorg: XMultibuf.c,v 1.6 2001/02/09 02:03:49 xorgcvs Exp $
+ *
+Copyright 1989, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ *
+ * Authors: Jim Fulton, MIT X Consortium
+ */
+/* $XFree86: xc/lib/Xext/XMultibuf.c,v 1.5 2001/12/14 19:55:00 dawes Exp $ */
+
+#define NEED_EVENTS
+#define NEED_REPLIES
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <stdio.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+#include <X11/extensions/multibufst.h>
+
+static XExtensionInfo _multibuf_info_data;
+static XExtensionInfo *multibuf_info = &_multibuf_info_data;
+static /* const */ char *multibuf_extension_name = MULTIBUFFER_PROTOCOL_NAME;
+
+#define MbufCheckExtension(dpy,i,val) \
+ XextCheckExtension (dpy, i, multibuf_extension_name, val)
+#define MbufSimpleCheckExtension(dpy,i) \
+ XextSimpleCheckExtension (dpy, i, multibuf_extension_name)
+
+
+/*****************************************************************************
+ * *
+ * private utility routines *
+ * *
+ *****************************************************************************/
+
+/*
+ * find_display - locate the display info block
+ */
+static int close_display(Display *dpy, XExtCodes *codes);
+static char *error_string(Display *dpy, int code, XExtCodes *codes, char *buf, int n);
+static Bool wire_to_event(Display *dpy, XEvent *libevent, xEvent *netevent);
+static Status event_to_wire(Display *dpy, XEvent *libevent, xEvent *netevent);
+static /* const */ XExtensionHooks multibuf_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ close_display, /* close_display */
+ wire_to_event, /* wire_to_event */
+ event_to_wire, /* event_to_wire */
+ NULL, /* error */
+ error_string, /* error_string */
+};
+
+static /* const */ char *multibuf_error_list[] = {
+ "BadBuffer", /* MultibufferBadBuffer */
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (find_display, multibuf_info,
+ multibuf_extension_name,
+ &multibuf_extension_hooks,
+ MultibufferNumberEvents, NULL)
+
+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, multibuf_info)
+
+static XEXT_GENERATE_ERROR_STRING (error_string, multibuf_extension_name,
+ MultibufferNumberErrors,
+ multibuf_error_list)
+
+/*
+ * wire_to_event - convert a wire event in network format to a C
+ * event structure
+ */
+static Bool wire_to_event (Display *dpy, XEvent *libevent, xEvent *netevent)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+
+ MbufCheckExtension (dpy, info, False);
+
+ switch ((netevent->u.u.type & 0x7f) - info->codes->first_event) {
+ case MultibufferClobberNotify:
+ {
+ XmbufClobberNotifyEvent *ev;
+ xMbufClobberNotifyEvent *event;
+
+ ev = (XmbufClobberNotifyEvent *) libevent;
+ event = (xMbufClobberNotifyEvent *) netevent;
+ ev->type = event->type & 0x7f;
+ ev->serial = _XSetLastRequestRead(dpy,(xGenericReply *) netevent);
+ ev->send_event = ((event->type & 0x80) != 0);
+ ev->display = dpy;
+ ev->buffer = event->buffer;
+ ev->state = event->state;
+ return True;
+ }
+ case MultibufferUpdateNotify:
+ {
+ XmbufUpdateNotifyEvent *ev;
+ xMbufUpdateNotifyEvent *event;
+
+ ev = (XmbufUpdateNotifyEvent *) libevent;
+ event = (xMbufUpdateNotifyEvent *) netevent;
+ ev->type = event->type & 0x7f;
+ ev->serial = _XSetLastRequestRead(dpy,(xGenericReply *) netevent);
+ ev->send_event = ((event->type & 0x80) != 0);
+ ev->display = dpy;
+ ev->buffer = event->buffer;
+ return True;
+ }
+ }
+ return False;
+}
+
+
+/*
+ * event_to_wire - convert a C event structure to a wire event in
+ * network format
+ */
+static Status event_to_wire (Display *dpy, XEvent *libevent, xEvent *netevent)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+
+ MbufCheckExtension (dpy, info, 0);
+
+ switch ((libevent->type & 0x7f) - info->codes->first_event) {
+ case MultibufferClobberNotify:
+ {
+ XmbufClobberNotifyEvent *ev;
+ xMbufClobberNotifyEvent *event;
+
+ ev = (XmbufClobberNotifyEvent *) libevent;
+ event = (xMbufClobberNotifyEvent *) netevent;
+ event->type = ev->type;
+ event->sequenceNumber = (ev->serial & 0xffff);
+ event->buffer = ev->buffer;
+ event->state = ev->state;
+ return 1;
+ }
+ case MultibufferUpdateNotify:
+ {
+ XmbufUpdateNotifyEvent *ev;
+ xMbufUpdateNotifyEvent *event;
+
+ ev = (XmbufUpdateNotifyEvent *) libevent;
+ event = (xMbufUpdateNotifyEvent *) netevent;
+ event->type = ev->type;
+ event->sequenceNumber = (ev->serial & 0xffff);
+ event->buffer = ev->buffer;
+ return 1;
+ }
+ }
+ return 0;
+}
+
+
+/*
+ * read_buffer_info - read Buffer Info descriptors from the net; if unable
+ * to allocate memory, read junk to make sure that stream is clear.
+ */
+#define TALLOC(type,count) ((type *) Xmalloc ((unsigned) count * sizeof(type)))
+
+static XmbufBufferInfo *read_buffer_info (Display *dpy, int nbufs)
+{
+ xMbufBufferInfo *netbuf = TALLOC (xMbufBufferInfo, nbufs);
+ XmbufBufferInfo *bufinfo = NULL;
+ long netbytes = nbufs * SIZEOF(xMbufBufferInfo);
+
+ if (netbuf) {
+ _XRead (dpy, (char *) netbuf, netbytes);
+
+ bufinfo = TALLOC (XmbufBufferInfo, nbufs);
+ if (bufinfo) {
+ register XmbufBufferInfo *c;
+ register xMbufBufferInfo *net;
+ register int i;
+
+ for (i = 0, c = bufinfo, net = netbuf; i < nbufs;
+ i++, c++, net++) {
+ c->visualid = net->visualID;
+ c->max_buffers = net->maxBuffers;
+ c->depth = net->depth;
+ }
+ }
+ Xfree ((char *) netbuf);
+ } else { /* eat the data */
+ while (netbytes > 0) {
+ char dummy[256]; /* stack size vs loops tradeoff */
+ long nbytes = sizeof dummy;
+
+ if (nbytes > netbytes) nbytes = netbytes;
+ _XRead (dpy, dummy, nbytes);
+ netbytes -= nbytes;
+ }
+ }
+
+ return bufinfo;
+}
+
+#undef TALLOC
+
+
+/*****************************************************************************
+ * *
+ * Multibuffering/stereo public interfaces *
+ * *
+ *****************************************************************************/
+
+
+/*
+ * XmbufQueryExtension -
+ * Returns True if the multibuffering/stereo extension is available
+ * on the given display. If the extension exists, the value of the
+ * first event code (which should be added to the event type constants
+ * MultibufferClobberNotify and MultibufferUpdateNotify to get the
+ * actual values) is stored into event_base and the value of the first
+ * error code (which should be added to the error type constant
+ * MultibufferBadBuffer to get the actual value) is stored into
+ * error_base.
+ */
+Bool XmbufQueryExtension (
+ Display *dpy,
+ int *event_base_return, int *error_base_return)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+
+ if (XextHasExtension (info)) {
+ *event_base_return = info->codes->first_event;
+ *error_base_return = info->codes->first_error;
+ return True;
+ } else {
+ return False;
+ }
+}
+
+
+/*
+ * XmbufGetVersion -
+ * Gets the major and minor version numbers of the extension. The return
+ * value is zero if an error occurs or non-zero if no error happens.
+ */
+Status XmbufGetVersion (
+ Display *dpy,
+ int *major_version_return, int *minor_version_return)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xMbufGetBufferVersionReply rep;
+ register xMbufGetBufferVersionReq *req;
+
+ MbufCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ MbufGetReq (MbufGetBufferVersion, req, info);
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 0;
+ }
+ *major_version_return = rep.majorVersion;
+ *minor_version_return = rep.minorVersion;
+ UnlockDisplay (dpy);
+
+ SyncHandle ();
+ return 1;
+}
+
+
+/*
+ * XmbufCreateBuffers -
+ * Requests that "count" buffers be created with the given update_action
+ * and update_hint and be associated with the indicated window. The
+ * number of buffers created is returned (zero if an error occurred)
+ * and buffers_return is filled in with that many Multibuffer identifiers.
+ */
+int XmbufCreateBuffers (
+ Display *dpy,
+ Window w,
+ int count,
+ int update_action, int update_hint,
+ Multibuffer *buffers)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xMbufCreateImageBuffersReply rep;
+ register xMbufCreateImageBuffersReq *req;
+ int result;
+
+ MbufCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+
+ XAllocIDs(dpy, buffers, count);
+ MbufGetReq (MbufCreateImageBuffers, req, info);
+ req->window = w;
+ req->updateAction = update_action;
+ req->updateHint = update_hint;
+ req->length += count;
+ count <<= 2;
+ PackData32 (dpy, buffers, count);
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 0;
+ }
+ result = rep.numberBuffer;
+ UnlockDisplay (dpy);
+
+ SyncHandle ();
+ return result;
+}
+
+
+/*
+ * XmbufDestroyBuffers -
+ * Destroys the buffers associated with the given window.
+ */
+void XmbufDestroyBuffers (Display *dpy, Window window)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xMbufDestroyImageBuffersReq *req;
+
+ MbufSimpleCheckExtension (dpy, info);
+
+ LockDisplay (dpy);
+ MbufGetReq (MbufDestroyImageBuffers, req, info);
+ req->window = window;
+ UnlockDisplay (dpy);
+ SyncHandle ();
+}
+
+
+/*
+ * XmbufDisplayBuffers -
+ * Displays the indicated buffers their appropriate windows within
+ * max_delay milliseconds after min_delay milliseconds have passed.
+ * No two buffers may be associated with the same window or else a Matc
+ * error is generated.
+ */
+void XmbufDisplayBuffers (
+ Display *dpy,
+ int count,
+ Multibuffer *buffers,
+ int min_delay, int max_delay)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xMbufDisplayImageBuffersReq *req;
+
+ MbufSimpleCheckExtension (dpy, info);
+
+ LockDisplay (dpy);
+ MbufGetReq (MbufDisplayImageBuffers, req, info);
+ req->minDelay = min_delay;
+ req->maxDelay = max_delay;
+ req->length += count;
+ count <<= 2;
+ PackData32 (dpy, buffers, count);
+ UnlockDisplay (dpy);
+ SyncHandle();
+}
+
+
+/*
+ * XmbufGetWindowAttributes -
+ * Gets the multibuffering attributes that apply to all buffers associated
+ * with the given window. Returns non-zero on success and zero if an
+ * error occurs.
+ */
+Status XmbufGetWindowAttributes (
+ Display *dpy,
+ Window w,
+ XmbufWindowAttributes *attr)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xMbufGetMBufferAttributesReq *req;
+ xMbufGetMBufferAttributesReply rep;
+
+ MbufCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ MbufGetReq (MbufGetMBufferAttributes, req, info);
+ req->window = w;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 0;
+ }
+ attr->buffers = (Multibuffer *) NULL;
+ if ((attr->nbuffers = rep.length)) {
+ int nbytes = rep.length * sizeof(Multibuffer);
+ attr->buffers = (Multibuffer *) Xmalloc((unsigned) nbytes);
+ nbytes = rep.length << 2;
+ if (! attr->buffers) {
+ _XEatData(dpy, (unsigned long) nbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return (0);
+ }
+ _XRead32 (dpy, (long *) attr->buffers, nbytes);
+ }
+ attr->displayed_index = rep.displayedBuffer;
+ attr->update_action = rep.updateAction;
+ attr->update_hint = rep.updateHint;
+ attr->window_mode = rep.windowMode;
+
+ UnlockDisplay (dpy);
+ SyncHandle();
+ return 1;
+}
+
+
+/*
+ * XmbufChangeWindowAttributes -
+ * Sets the multibuffering attributes that apply to all buffers associated
+ * with the given window. This is currently limited to the update_hint.
+ */
+void XmbufChangeWindowAttributes (
+ Display *dpy,
+ Window w,
+ unsigned long valuemask,
+ XmbufSetWindowAttributes *attr)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xMbufSetMBufferAttributesReq *req;
+
+ MbufSimpleCheckExtension (dpy, info);
+
+ LockDisplay (dpy);
+ MbufGetReq (MbufSetMBufferAttributes, req, info);
+ req->window = w;
+ if ((req->valueMask = valuemask)) { /* stolen from lib/X/XWindow.c */
+ unsigned long values[1]; /* one per element in if stmts below */
+ unsigned long *v = values;
+ unsigned int nvalues;
+
+ if (valuemask & MultibufferWindowUpdateHint)
+ *v++ = attr->update_hint;
+ req->length += (nvalues = v - values);
+ nvalues <<= 2; /* watch out for macros... */
+ Data32 (dpy, (long *) values, (long)nvalues);
+ }
+ UnlockDisplay (dpy);
+ SyncHandle();
+}
+
+
+/*
+ * XmbufGetBufferAttributes -
+ * Gets the attributes for the indicated buffer. Returns non-zero on
+ * success and zero if an error occurs.
+ */
+Status XmbufGetBufferAttributes (
+ Display *dpy,
+ Multibuffer b,
+ XmbufBufferAttributes *attr)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xMbufGetBufferAttributesReq *req;
+ xMbufGetBufferAttributesReply rep;
+
+ MbufCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ MbufGetReq (MbufGetBufferAttributes, req, info);
+ req->buffer = b;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 0;
+ }
+ attr->window = rep.window;
+ attr->event_mask = rep.eventMask;
+ attr->buffer_index = rep.bufferIndex;
+ attr->side = rep.side;
+
+ UnlockDisplay (dpy);
+ SyncHandle();
+ return 1;
+}
+
+
+/*
+ * XmbufChangeBufferAttributes -
+ * Sets the attributes for the indicated buffer. This is currently
+ * limited to the event_mask.
+ */
+void XmbufChangeBufferAttributes (
+ Display *dpy,
+ Multibuffer b,
+ unsigned long valuemask,
+ XmbufSetBufferAttributes *attr)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xMbufSetBufferAttributesReq *req;
+
+ MbufSimpleCheckExtension (dpy, info);
+
+ LockDisplay (dpy);
+ MbufGetReq (MbufSetBufferAttributes, req, info);
+ req->buffer = b;
+ if ((req->valueMask = valuemask)) { /* stolen from lib/X/XWindow.c */
+ unsigned long values[1]; /* one per element in if stmts below */
+ unsigned long *v = values;
+ unsigned int nvalues;
+
+ if (valuemask & MultibufferBufferEventMask)
+ *v++ = attr->event_mask;
+ req->length += (nvalues = v - values);
+ nvalues <<= 2; /* watch out for macros... */
+ Data32 (dpy, (long *) values, (long)nvalues);
+ }
+ UnlockDisplay (dpy);
+ SyncHandle();
+}
+
+
+
+/*
+ * XmbufGetScreenInfo -
+ * Gets the parameters controlling how mono and stereo windows may be
+ * created on the indicated screen. The numbers of sets of visual and
+ * depths are returned in nmono_return and nstereo_return. If
+ * nmono_return is greater than zero, then mono_info_return is set to
+ * the address of an array of XmbufBufferInfo structures describing the
+ * various visuals and depths that may be used. Otherwise,
+ * mono_info_return is set to NULL. Similarly, stereo_info_return is
+ * set according to nstereo_return. The storage returned in
+ * mono_info_return and stereo_info_return may be released by XFree.
+ * If no errors are encounted, non-zero will be returned.
+ */
+Status XmbufGetScreenInfo (
+ Display *dpy,
+ Drawable d,
+ int *nmono_return,
+ XmbufBufferInfo **mono_info_return,
+ int *nstereo_return,
+ XmbufBufferInfo **stereo_info_return)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xMbufGetBufferInfoReq *req;
+ xMbufGetBufferInfoReply rep;
+ int nmono, nstereo;
+ XmbufBufferInfo *minfo, *sinfo;
+
+ MbufCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ MbufGetReq (MbufGetBufferInfo, req, info);
+ req->drawable = d;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 0;
+ }
+ nmono = rep.normalInfo;
+ nstereo = rep.stereoInfo;
+ minfo = ((nmono > 0) ? read_buffer_info (dpy, nmono) : NULL);
+ sinfo = ((nstereo > 0) ? read_buffer_info (dpy, nstereo) : NULL);
+
+ /* check for bad reads indicating we need to return an error */
+ if ((nmono > 0 && !minfo) || (nstereo > 0 && !sinfo)) {
+ if (minfo) Xfree ((char *) minfo);
+ if (sinfo) Xfree ((char *) sinfo);
+ UnlockDisplay (dpy);
+ SyncHandle();
+ return 0;
+ }
+
+ *nmono_return = nmono;
+ *mono_info_return = minfo;
+ *nstereo_return = nstereo;
+ *stereo_info_return = sinfo;
+
+ UnlockDisplay (dpy);
+ SyncHandle();
+ return 1;
+}
+
+
+/*
+ * XmbufCreateStereoWindow -
+ * Creates a stereo window in the same way that XCreateWindow creates
+ * a mono window (in fact, use the same code, except for the request)
+ * and returns the left and right buffers that may be
+ */
+Window XmbufCreateStereoWindow (
+ Display *dpy,
+ Window parent,
+ int x, int y,
+ unsigned int width, unsigned int height, unsigned int border_width,
+ int depth,
+ unsigned int class,
+ Visual *visual,
+ unsigned long valuemask,
+ XSetWindowAttributes *attr,
+ Multibuffer *leftp, Multibuffer *rightp)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ Window wid;
+ register xMbufCreateStereoWindowReq *req;
+
+ MbufCheckExtension (dpy, info, None);
+
+ LockDisplay(dpy);
+ MbufGetReq(MbufCreateStereoWindow, req, info);
+ wid = req->wid = XAllocID(dpy);
+ req->parent = parent;
+ req->left = *leftp = XAllocID (dpy);
+ req->right = *rightp = XAllocID (dpy);
+ req->x = x;
+ req->y = y;
+ req->width = width;
+ req->height = height;
+ req->borderWidth = border_width;
+ req->depth = depth;
+ req->class = class;
+ if (visual == CopyFromParent)
+ req->visual = CopyFromParent;
+ else
+ req->visual = visual->visualid;
+ valuemask &= (CWBackPixmap|CWBackPixel|CWBorderPixmap|
+ CWBorderPixel|CWBitGravity|CWWinGravity|
+ CWBackingStore|CWBackingPlanes|CWBackingPixel|
+ CWOverrideRedirect|CWSaveUnder|CWEventMask|
+ CWDontPropagate|CWColormap|CWCursor);
+ if ((req->mask = valuemask)) {
+ unsigned long values[32];
+ register unsigned long *value = values;
+ unsigned int nvalues;
+
+ if (valuemask & CWBackPixmap)
+ *value++ = attr->background_pixmap;
+ if (valuemask & CWBackPixel)
+ *value++ = attr->background_pixel;
+ if (valuemask & CWBorderPixmap)
+ *value++ = attr->border_pixmap;
+ if (valuemask & CWBorderPixel)
+ *value++ = attr->border_pixel;
+ if (valuemask & CWBitGravity)
+ *value++ = attr->bit_gravity;
+ if (valuemask & CWWinGravity)
+ *value++ = attr->win_gravity;
+ if (valuemask & CWBackingStore)
+ *value++ = attr->backing_store;
+ if (valuemask & CWBackingPlanes)
+ *value++ = attr->backing_planes;
+ if (valuemask & CWBackingPixel)
+ *value++ = attr->backing_pixel;
+ if (valuemask & CWOverrideRedirect)
+ *value++ = attr->override_redirect;
+ if (valuemask & CWSaveUnder)
+ *value++ = attr->save_under;
+ if (valuemask & CWEventMask)
+ *value++ = attr->event_mask;
+ if (valuemask & CWDontPropagate)
+ *value++ = attr->do_not_propagate_mask;
+ if (valuemask & CWColormap)
+ *value++ = attr->colormap;
+ if (valuemask & CWCursor)
+ *value++ = attr->cursor;
+ req->length += (nvalues = value - values);
+
+ nvalues <<= 2; /* watch out for macros... */
+ Data32 (dpy, (long *) values, (long)nvalues);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return wid;
+}
+
+void XmbufClearBufferArea (
+ Display *dpy,
+ Multibuffer buffer,
+ int x, int y,
+ unsigned int width, unsigned int height,
+ Bool exposures)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xMbufClearImageBufferAreaReq *req;
+
+ MbufSimpleCheckExtension (dpy, info);
+
+ LockDisplay (dpy);
+ MbufGetReq (MbufClearImageBufferArea, req, info);
+ req->buffer = buffer;
+ req->x = x;
+ req->y = y;
+ req->width = width;
+ req->height = height;
+ req->exposures = exposures;
+ UnlockDisplay (dpy);
+ SyncHandle();
+}
+
diff --git a/nx-X11/lib/Xext/XSecurity.c b/nx-X11/lib/Xext/XSecurity.c
new file mode 100644
index 000000000..161ade3b7
--- /dev/null
+++ b/nx-X11/lib/Xext/XSecurity.c
@@ -0,0 +1,310 @@
+/* $Xorg: XSecurity.c,v 1.6 2001/02/09 02:03:49 xorgcvs Exp $ */
+/*
+
+Copyright 1996, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/* $XFree86: xc/lib/Xext/XSecurity.c,v 1.5 2002/10/16 00:37:27 dawes Exp $ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <stdio.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+#include <X11/extensions/securstr.h>
+
+static XExtensionInfo _Security_info_data;
+static XExtensionInfo *Security_info = &_Security_info_data;
+static char *Security_extension_name = SECURITY_EXTENSION_NAME;
+
+#define SecurityCheckExtension(dpy,i,val) \
+ XextCheckExtension (dpy, i, Security_extension_name, val)
+#define SecuritySimpleCheckExtension(dpy,i) \
+ XextSimpleCheckExtension (dpy, i, Security_extension_name)
+
+#define SecurityGetReq(name,req,info) GetReq (name, req); \
+ req->reqType = info->codes->major_opcode; \
+ req->securityReqType = X_##name;
+
+/*****************************************************************************
+ * *
+ * private utility routines *
+ * *
+ *****************************************************************************/
+
+/*
+ * find_display - locate the display info block
+ */
+static int close_display(Display *dpy, XExtCodes *codes);
+static Bool wire_to_event(Display *dpy, XEvent *event, xEvent *wire);
+static Status event_to_wire(Display *dpy, XEvent *event, xEvent *wire);
+static char *error_string(Display *dpy, int code, XExtCodes *codes,
+ char *buf, int n);
+
+static XExtensionHooks Security_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ close_display, /* close_display */
+ wire_to_event, /* wire_to_event */
+ event_to_wire, /* event_to_wire */
+ NULL, /* error */
+ error_string /* error_string */
+};
+
+static char *security_error_list[] = {
+ "BadAuthorization"
+ "BadAuthorizationProtocol"
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (find_display, Security_info,
+ Security_extension_name,
+ &Security_extension_hooks,
+ XSecurityNumberEvents, NULL)
+
+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, Security_info)
+
+static
+XEXT_GENERATE_ERROR_STRING(error_string, Security_extension_name,
+ XSecurityNumberErrors, security_error_list)
+
+static Bool
+wire_to_event(Display *dpy, XEvent *event, xEvent *wire)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+
+ SecurityCheckExtension (dpy, info, False);
+
+ switch ((wire->u.u.type & 0x7F) - info->codes->first_event)
+ {
+ case XSecurityAuthorizationRevoked:
+ {
+ xSecurityAuthorizationRevokedEvent *rwire =
+ (xSecurityAuthorizationRevokedEvent *)wire;
+ XSecurityAuthorizationRevokedEvent *revent =
+ (XSecurityAuthorizationRevokedEvent *)event;
+
+ revent->type = rwire->type & 0x7F;
+ revent->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *) wire);
+ revent->send_event = (rwire->type & 0x80) != 0;
+ revent->display = dpy;
+ revent->auth_id = rwire->authId;
+ return True;
+ }
+ }
+ return False;
+}
+
+static Status
+event_to_wire(Display *dpy, XEvent *event, xEvent *wire)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+
+ SecurityCheckExtension(dpy, info, False);
+
+ switch ((event->type & 0x7F) - info->codes->first_event)
+ {
+ case XSecurityAuthorizationRevoked:
+ {
+ xSecurityAuthorizationRevokedEvent *rwire =
+ (xSecurityAuthorizationRevokedEvent *)wire;
+ XSecurityAuthorizationRevokedEvent *revent =
+ (XSecurityAuthorizationRevokedEvent *)event;
+ rwire->type = revent->type | (revent->send_event ? 0x80 : 0);
+ rwire->sequenceNumber = revent->serial & 0xFFFF;
+ return True;
+ }
+ }
+ return False;
+}
+
+/*****************************************************************************
+ * *
+ * Security public interfaces *
+ * *
+ *****************************************************************************/
+
+Status XSecurityQueryExtension (
+ Display *dpy,
+ int *major_version_return,
+ int *minor_version_return)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xSecurityQueryVersionReply rep;
+ register xSecurityQueryVersionReq *req;
+
+ if (!XextHasExtension (info))
+ return (Status)0; /* failure */
+
+ LockDisplay (dpy);
+ SecurityGetReq (SecurityQueryVersion, req, info);
+ req->majorVersion = SECURITY_MAJOR_VERSION;
+ req->minorVersion = SECURITY_MINOR_VERSION;
+
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return (Status)0; /* failure */
+ }
+ *major_version_return = rep.majorVersion;
+ *minor_version_return = rep.minorVersion;
+ UnlockDisplay (dpy);
+
+ SyncHandle ();
+
+ if (*major_version_return != SECURITY_MAJOR_VERSION)
+ return (Status)0; /* failure */
+ else
+ return (Status)1; /* success */
+}
+
+Xauth *
+XSecurityAllocXauth(void)
+{
+ return Xcalloc(1, sizeof(Xauth));
+}
+
+void
+XSecurityFreeXauth(Xauth *auth)
+{
+ XFree(auth);
+}
+
+static int
+Ones(Mask mask)
+{
+ register Mask y;
+
+ y = (mask >> 1) &033333333333;
+ y = mask - y - ((y >>1) & 033333333333);
+ return (((y + (y >> 3)) & 030707070707) % 077);
+}
+
+Xauth *
+XSecurityGenerateAuthorization(
+ Display *dpy,
+ Xauth *auth_in,
+ unsigned long valuemask,
+ XSecurityAuthorizationAttributes *attributes,
+ XSecurityAuthorization *auth_id_return)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xSecurityGenerateAuthorizationReq *req;
+ xSecurityGenerateAuthorizationReply rep;
+ Xauth *auth_return;
+ unsigned long values[3];
+ unsigned long *value = values;
+ unsigned int nvalues;
+
+ *auth_id_return = 0; /* in case we fail */
+
+ /* make sure extension is available */
+
+ SecurityCheckExtension (dpy, info, (Xauth *)NULL);
+
+ LockDisplay(dpy);
+ SecurityGetReq(SecurityGenerateAuthorization, req, info);
+
+ req->nbytesAuthProto = auth_in->name_length;
+ req->nbytesAuthData = auth_in->data_length;
+
+ /* adjust length to account for auth name and data */
+ req->length += (auth_in->name_length + (unsigned)3) >> 2;
+ req->length += (auth_in->data_length + (unsigned)3) >> 2;
+
+ /* adjust length to account for list of values */
+ req->valueMask = valuemask & XSecurityAllAuthorizationAttributes;
+ nvalues = Ones(req->valueMask);
+ req->length += nvalues;
+
+ /* send auth name and data */
+ Data(dpy, auth_in->name, auth_in->name_length);
+ Data(dpy, auth_in->data, auth_in->data_length);
+
+ /* send values */
+ if (valuemask & XSecurityTimeout) *value++ = attributes->timeout;
+ if (valuemask & XSecurityTrustLevel) *value++ = attributes->trust_level;
+ if (valuemask & XSecurityGroup) *value++ = attributes->group;
+ if (valuemask & XSecurityEventMask) *value++ = attributes->event_mask;
+
+ nvalues <<= 2;
+ Data32(dpy, (long *)values, (long)nvalues);
+
+ if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return (Xauth *)NULL;
+ }
+
+ *auth_id_return = rep.authId;
+
+ /* Allocate space for the Xauth struct and the auth name and data all
+ * in one hunk. This lets XSecurityFreeXauth not have to care
+ * about whether the auth was allocated here or in
+ * XSecurityAllocXauth; in both cases, you just free one pointer.
+ */
+
+ if ((auth_return = (Xauth *)Xcalloc(1,
+ (sizeof(Xauth) + auth_in->name_length + rep.dataLength))))
+ {
+ auth_return->data_length = rep.dataLength;
+ auth_return->data = (char *)&auth_return[1];
+ _XReadPad(dpy, auth_return->data, (long)rep.dataLength);
+
+ auth_return->name_length = auth_in->name_length;
+ auth_return->name = auth_return->data + auth_return->data_length;
+ memcpy(auth_return->name, auth_in->name, auth_return->name_length);
+ }
+ else
+ {
+ _XEatData(dpy, (unsigned long) (rep.dataLength + 3) & ~3);
+ }
+
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return auth_return;
+
+} /* XSecurityGenerateAuthorization */
+
+Status
+XSecurityRevokeAuthorization(
+ Display *dpy,
+ XSecurityAuthorization auth_id)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xSecurityRevokeAuthorizationReq *req;
+
+ SecurityCheckExtension (dpy, info, 0);
+ LockDisplay(dpy);
+ SecurityGetReq(SecurityRevokeAuthorization, req, info);
+ req->authId = auth_id;
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 1;
+} /* XSecurityRevokeAuthorization */
diff --git a/nx-X11/lib/Xext/XShape.c b/nx-X11/lib/Xext/XShape.c
new file mode 100644
index 000000000..29a7f83f9
--- /dev/null
+++ b/nx-X11/lib/Xext/XShape.c
@@ -0,0 +1,490 @@
+/*
+ * $Xorg: XShape.c,v 1.4 2001/02/09 02:03:49 xorgcvs Exp $
+ *
+Copyright 1989, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ *
+ * Author: Keith Packard, MIT X Consortium
+ */
+/* $XFree86: xc/lib/Xext/XShape.c,v 1.3 2002/10/16 00:37:27 dawes Exp $ */
+#define NEED_EVENTS
+#define NEED_REPLIES
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <X11/Xutil.h>
+#include <X11/Xregion.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+#include <X11/extensions/shapestr.h>
+
+static XExtensionInfo _shape_info_data;
+static XExtensionInfo *shape_info = &_shape_info_data;
+static /* const */ char *shape_extension_name = SHAPENAME;
+
+#define ShapeCheckExtension(dpy,i,val) \
+ XextCheckExtension (dpy, i, shape_extension_name, val)
+#define ShapeSimpleCheckExtension(dpy,i) \
+ XextSimpleCheckExtension (dpy, i, shape_extension_name)
+
+
+/*****************************************************************************
+ * *
+ * private utility routines *
+ * *
+ *****************************************************************************/
+
+static int close_display(Display *dpy, XExtCodes *codes);
+static Bool wire_to_event (Display *dpy, XEvent *re, xEvent *event);
+static Status event_to_wire (Display *dpy, XEvent *re, xEvent *event);
+static /* const */ XExtensionHooks shape_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ close_display, /* close_display */
+ wire_to_event, /* wire_to_event */
+ event_to_wire, /* event_to_wire */
+ NULL, /* error */
+ NULL, /* error_string */
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (find_display, shape_info,
+ shape_extension_name,
+ &shape_extension_hooks,
+ ShapeNumberEvents, NULL)
+
+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, shape_info)
+
+
+static Bool
+wire_to_event (Display *dpy, XEvent *re, xEvent *event)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ XShapeEvent *se;
+ xShapeNotifyEvent *sevent;
+
+ ShapeCheckExtension (dpy, info, False);
+
+ switch ((event->u.u.type & 0x7f) - info->codes->first_event) {
+ case ShapeNotify:
+ se = (XShapeEvent *) re;
+ sevent = (xShapeNotifyEvent *) event;
+ se->type = sevent->type & 0x7f;
+ se->serial = _XSetLastRequestRead(dpy,(xGenericReply *) event);
+ se->send_event = (sevent->type & 0x80) != 0;
+ se->display = dpy;
+ se->window = sevent->window;
+ se->kind = sevent->kind;
+ se->x = cvtINT16toInt (sevent->x);
+ se->y = cvtINT16toInt (sevent->y);
+ se->width = sevent->width;
+ se->height = sevent->height;
+ se->time = sevent->time;
+ se->shaped = True;
+ if (sevent->shaped == xFalse)
+ se->shaped = False;
+ return True;
+ }
+ return False;
+}
+
+static Status
+event_to_wire (Display *dpy, XEvent *re, xEvent *event)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ XShapeEvent *se;
+ xShapeNotifyEvent *sevent;
+
+ ShapeCheckExtension (dpy, info, 0);
+
+ switch ((re->type & 0x7f) - info->codes->first_event) {
+ case ShapeNotify:
+ se = (XShapeEvent *) re;
+ sevent = (xShapeNotifyEvent *) event;
+ sevent->type = se->type | (se->send_event ? 0x80 : 0);
+ sevent->sequenceNumber = se->serial & 0xffff;
+ sevent->window = se->window;
+ sevent->kind = se->kind;
+ sevent->x = se->x;
+ sevent->y = se->y;
+ sevent->width = se->width;
+ sevent->height = se->height;
+ sevent->time = se->time;
+ return 1;
+ }
+ return 0;
+}
+
+
+/****************************************************************************
+ * *
+ * Shape public interfaces *
+ * *
+ ****************************************************************************/
+
+Bool XShapeQueryExtension (Display *dpy, int *event_basep, int *error_basep)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+
+ if (XextHasExtension(info)) {
+ *event_basep = info->codes->first_event;
+ *error_basep = info->codes->first_error;
+ return True;
+ } else {
+ return False;
+ }
+}
+
+
+Status XShapeQueryVersion(
+ Display *dpy,
+ int *major_versionp,
+ int *minor_versionp)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xShapeQueryVersionReply rep;
+ register xShapeQueryVersionReq *req;
+
+ ShapeCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ GetReq (ShapeQueryVersion, req);
+ req->reqType = info->codes->major_opcode;
+ req->shapeReqType = X_ShapeQueryVersion;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 0;
+ }
+ *major_versionp = rep.majorVersion;
+ *minor_versionp = rep.minorVersion;
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 1;
+}
+
+void XShapeCombineRegion(
+ register Display *dpy,
+ Window dest,
+ int destKind, int xOff, int yOff,
+ register REGION *r,
+ int op)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xShapeRectanglesReq *req;
+ register long nbytes;
+ register int i;
+ register XRectangle *xr, *pr;
+ register BOX *pb;
+
+ ShapeSimpleCheckExtension (dpy, info);
+
+ LockDisplay(dpy);
+ GetReq(ShapeRectangles, req);
+ xr = (XRectangle *)
+ _XAllocScratch(dpy, (unsigned long)(r->numRects * sizeof (XRectangle)));
+ for (pr = xr, pb = r->rects, i = r->numRects; --i >= 0; pr++, pb++) {
+ pr->x = pb->x1;
+ pr->y = pb->y1;
+ pr->width = pb->x2 - pb->x1;
+ pr->height = pb->y2 - pb->y1;
+ }
+ req->reqType = info->codes->major_opcode;
+ req->shapeReqType = X_ShapeRectangles;
+ req->op = op;
+ req->ordering = YXBanded;
+ req->destKind = destKind;
+ req->dest = dest;
+ req->xOff = xOff;
+ req->yOff = yOff;
+
+ /* SIZEOF(xRectangle) will be a multiple of 4 */
+ req->length += r->numRects * (SIZEOF(xRectangle) / 4);
+
+ nbytes = r->numRects * sizeof(xRectangle);
+
+ Data16 (dpy, (short *) xr, nbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+}
+
+
+void XShapeCombineRectangles (
+ register Display *dpy,
+ XID dest,
+ int destKind, int xOff, int yOff,
+ XRectangle *rects,
+ int n_rects,
+ int op, int ordering)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xShapeRectanglesReq *req;
+ register long nbytes;
+
+ ShapeSimpleCheckExtension (dpy, info);
+
+ LockDisplay(dpy);
+ GetReq(ShapeRectangles, req);
+ req->reqType = info->codes->major_opcode;
+ req->shapeReqType = X_ShapeRectangles;
+ req->op = op;
+ req->ordering = ordering;
+ req->destKind = destKind;
+ req->dest = dest;
+ req->xOff = xOff;
+ req->yOff = yOff;
+
+ /* SIZEOF(xRectangle) will be a multiple of 4 */
+ req->length += n_rects * (SIZEOF(xRectangle) / 4);
+
+ nbytes = n_rects * sizeof(xRectangle);
+
+ Data16 (dpy, (short *) rects, nbytes);
+ UnlockDisplay(dpy);
+ SyncHandle();
+}
+
+
+void XShapeCombineMask (
+ register Display *dpy,
+ XID dest,
+ int destKind,
+ int xOff, int yOff,
+ Pixmap src,
+ int op)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xShapeMaskReq *req;
+
+ ShapeSimpleCheckExtension (dpy, info);
+
+ LockDisplay(dpy);
+ GetReq(ShapeMask, req);
+ req->reqType = info->codes->major_opcode;
+ req->shapeReqType = X_ShapeMask;
+ req->op = op;
+ req->destKind = destKind;
+ req->dest = dest;
+ req->xOff = xOff;
+ req->yOff = yOff;
+ req->src = src;
+ UnlockDisplay(dpy);
+ SyncHandle();
+}
+
+void XShapeCombineShape (
+ register Display *dpy,
+ XID dest,
+ int destKind,
+ int xOff, int yOff,
+ XID src,
+ int srcKind,
+ int op)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xShapeCombineReq *req;
+
+ ShapeSimpleCheckExtension (dpy, info);
+
+ LockDisplay(dpy);
+ GetReq(ShapeCombine, req);
+ req->reqType = info->codes->major_opcode;
+ req->shapeReqType = X_ShapeCombine;
+ req->op = op;
+ req->destKind = destKind;
+ req->srcKind = srcKind;
+ req->dest = dest;
+ req->xOff = xOff;
+ req->yOff = yOff;
+ req->src = src;
+ UnlockDisplay(dpy);
+ SyncHandle();
+}
+
+void XShapeOffsetShape (
+ register Display *dpy,
+ XID dest,
+ int destKind,
+ int xOff, int yOff)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xShapeOffsetReq *req;
+
+ ShapeSimpleCheckExtension (dpy, info);
+
+ LockDisplay(dpy);
+ GetReq(ShapeOffset, req);
+ req->reqType = info->codes->major_opcode;
+ req->shapeReqType = X_ShapeOffset;
+ req->destKind = destKind;
+ req->dest = dest;
+ req->xOff = xOff;
+ req->yOff = yOff;
+ UnlockDisplay(dpy);
+ SyncHandle();
+}
+
+Status XShapeQueryExtents (
+ register Display *dpy,
+ Window window,
+ int *bShaped, int *xbs, int *ybs, unsigned int *wbs, unsigned int *hbs, /* RETURN */
+ int *cShaped, int *xcs, int *ycs, unsigned int *wcs, unsigned int *hcs /* RETURN */)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xShapeQueryExtentsReply rep;
+ register xShapeQueryExtentsReq *req;
+
+ ShapeCheckExtension (dpy, info, 0);
+
+ LockDisplay (dpy);
+ GetReq (ShapeQueryExtents, req);
+ req->reqType = info->codes->major_opcode;
+ req->shapeReqType = X_ShapeQueryExtents;
+ req->window = window;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 0;
+ }
+ *bShaped = rep.boundingShaped;
+ *cShaped = rep.clipShaped;
+ *xbs = cvtINT16toInt (rep.xBoundingShape);
+ *ybs = cvtINT16toInt (rep.yBoundingShape);
+ *wbs = rep.widthBoundingShape;
+ *hbs = rep.heightBoundingShape;
+ *xcs = cvtINT16toInt (rep.xClipShape);
+ *ycs = cvtINT16toInt (rep.yClipShape);
+ *wcs = rep.widthClipShape;
+ *hcs = rep.heightClipShape;
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return 1;
+}
+
+
+void XShapeSelectInput (
+ register Display *dpy,
+ Window window,
+ unsigned long mask)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xShapeSelectInputReq *req;
+
+ ShapeSimpleCheckExtension (dpy, info);
+
+ LockDisplay (dpy);
+ GetReq (ShapeSelectInput, req);
+ req->reqType = info->codes->major_opcode;
+ req->shapeReqType = X_ShapeSelectInput;
+ req->window = window;
+ if (mask & ShapeNotifyMask)
+ req->enable = xTrue;
+ else
+ req->enable = xFalse;
+ UnlockDisplay (dpy);
+ SyncHandle ();
+}
+
+unsigned long XShapeInputSelected (register Display *dpy, Window window)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xShapeInputSelectedReq *req;
+ xShapeInputSelectedReply rep;
+
+ ShapeCheckExtension (dpy, info, False);
+
+ LockDisplay (dpy);
+ GetReq (ShapeInputSelected, req);
+ req->reqType = info->codes->major_opcode;
+ req->shapeReqType = X_ShapeInputSelected;
+ req->window = window;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return False;
+ }
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return rep.enabled ? ShapeNotifyMask : 0L;
+}
+
+
+XRectangle *XShapeGetRectangles (
+ register Display *dpy,
+ Window window,
+ int kind,
+ int *count, /* RETURN */
+ int *ordering /* RETURN */)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xShapeGetRectanglesReq *req;
+ xShapeGetRectanglesReply rep;
+ XRectangle *rects;
+ xRectangle *xrects;
+ int i;
+
+ ShapeCheckExtension (dpy, info, (XRectangle *)NULL);
+
+ LockDisplay (dpy);
+ GetReq (ShapeGetRectangles, req);
+ req->reqType = info->codes->major_opcode;
+ req->shapeReqType = X_ShapeGetRectangles;
+ req->window = window;
+ req->kind = kind;
+ if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return (XRectangle *)NULL;
+ }
+ *count = rep.nrects;
+ *ordering = rep.ordering;
+ rects = 0;
+ if (*count) {
+ xrects = (xRectangle *) Xmalloc (*count * sizeof (xRectangle));
+ rects = (XRectangle *) Xmalloc (*count * sizeof (XRectangle));
+ if (!xrects || !rects) {
+ if (xrects)
+ Xfree (xrects);
+ if (rects)
+ Xfree (rects);
+ _XEatData (dpy, *count * sizeof (xRectangle));
+ rects = 0;
+ *count = 0;
+ } else {
+ _XRead (dpy, (char *) xrects, *count * sizeof (xRectangle));
+ for (i = 0; i < *count; i++) {
+ rects[i].x = (short) cvtINT16toInt (xrects[i].x);
+ rects[i].y = (short) cvtINT16toInt (xrects[i].y);
+ rects[i].width = xrects[i].width;
+ rects[i].height = xrects[i].height;
+ }
+ Xfree (xrects);
+ }
+ }
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return rects;
+}
diff --git a/nx-X11/lib/Xext/XShm.c b/nx-X11/lib/Xext/XShm.c
new file mode 100644
index 000000000..f4e29a42b
--- /dev/null
+++ b/nx-X11/lib/Xext/XShm.c
@@ -0,0 +1,437 @@
+/* $XdotOrg: xc/lib/Xext/XShm.c,v 1.5 2005/07/30 21:07:25 alanc Exp $ */
+/*
+ * $Xorg: XShm.c,v 1.4 2001/02/09 02:03:49 xorgcvs Exp $
+ *
+Copyright 1989, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ *
+ * Author: Bob Scheifler and Keith Packard, MIT X Consortium
+ */
+/* $XFree86: xc/lib/Xext/XShm.c,v 1.6 2002/10/16 02:19:22 dawes Exp $ */
+
+/* THIS IS NOT AN X CONSORTIUM STANDARD OR AN X PROJECT TEAM SPECIFICATION */
+
+#define NEED_EVENTS
+#define NEED_REPLIES
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xlibint.h>
+#include <X11/ImUtil.h>
+#include <X11/extensions/XShm.h>
+#include <X11/extensions/shmstr.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+
+static XExtensionInfo _shm_info_data;
+static XExtensionInfo *shm_info = &_shm_info_data;
+static /* const */ char *shm_extension_name = SHMNAME;
+
+#define ShmCheckExtension(dpy,i,val) \
+ XextCheckExtension (dpy, i, shm_extension_name, val)
+
+/*****************************************************************************
+ * *
+ * private utility routines *
+ * *
+ *****************************************************************************/
+
+static int close_display(Display *dpy, XExtCodes *codes);
+static char *error_string(Display *dpy, int code, XExtCodes *codes,
+ char *buf, int n);
+static Bool wire_to_event (Display *dpy, XEvent *re, xEvent *event);
+static Status event_to_wire (Display *dpy, XEvent *re, xEvent *event);
+static /* const */ XExtensionHooks shm_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ close_display, /* close_display */
+ wire_to_event, /* wire_to_event */
+ event_to_wire, /* event_to_wire */
+ NULL, /* error */
+ error_string, /* error_string */
+};
+
+static /* const */ char *shm_error_list[] = {
+ "BadShmSeg", /* BadShmSeg */
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (find_display, shm_info, shm_extension_name,
+ &shm_extension_hooks, ShmNumberEvents, NULL)
+
+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, shm_info)
+
+static XEXT_GENERATE_ERROR_STRING (error_string, shm_extension_name,
+ ShmNumberErrors, shm_error_list)
+
+
+static Bool
+wire_to_event (Display *dpy, XEvent *re, xEvent *event)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ XShmCompletionEvent *se;
+ xShmCompletionEvent *sevent;
+
+ ShmCheckExtension (dpy, info, False);
+
+ switch ((event->u.u.type & 0x7f) - info->codes->first_event) {
+ case ShmCompletion:
+ se = (XShmCompletionEvent *) re;
+ sevent = (xShmCompletionEvent *) event;
+ se->type = sevent->type & 0x7f;
+ se->serial = _XSetLastRequestRead(dpy,(xGenericReply *) event);
+ se->send_event = (sevent->type & 0x80) != 0;
+ se->display = dpy;
+ se->drawable = sevent->drawable;
+ se->major_code = sevent->majorEvent;
+ se->minor_code = sevent->minorEvent;
+ se->shmseg = sevent->shmseg;
+ se->offset = sevent->offset;
+ return True;
+ }
+ return False;
+}
+
+static Status
+event_to_wire (Display *dpy, XEvent *re, xEvent *event)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ XShmCompletionEvent *se;
+ xShmCompletionEvent *sevent;
+
+ ShmCheckExtension (dpy, info, 0);
+
+ switch ((re->type & 0x7f) - info->codes->first_event) {
+ case ShmCompletion:
+ se = (XShmCompletionEvent *) re;
+ sevent = (xShmCompletionEvent *) event;
+ sevent->type = se->type | (se->send_event ? 0x80 : 0);
+ sevent->sequenceNumber = se->serial & 0xffff;
+ sevent->drawable = se->drawable;
+ sevent->majorEvent = se->major_code;
+ sevent->minorEvent = se->minor_code;
+ sevent->shmseg = se->shmseg;
+ sevent->offset = se->offset;
+ return True;
+ }
+ return False;
+}
+
+/*****************************************************************************
+ * *
+ * public Shared Memory Extension routines *
+ * *
+ *****************************************************************************/
+
+Bool XShmQueryExtension (Display *dpy /* int *event_basep, *error_basep */)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+
+ if (XextHasExtension(info)) {
+/* *event_basep = info->codes->first_event;
+ *error_basep = info->codes->error_event; */
+ return True;
+ } else {
+ return False;
+ }
+}
+
+
+int XShmGetEventBase(Display *dpy)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+
+ if (XextHasExtension(info)) {
+ return info->codes->first_event;
+ } else {
+ return -1;
+ }
+}
+
+
+Bool XShmQueryVersion(
+ Display *dpy,
+ int *majorVersion,
+ int *minorVersion,
+ Bool *sharedPixmaps)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xShmQueryVersionReply rep;
+ register xShmQueryVersionReq *req;
+
+ ShmCheckExtension (dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(ShmQueryVersion, req);
+ req->reqType = info->codes->major_opcode;
+ req->shmReqType = X_ShmQueryVersion;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ *majorVersion = rep.majorVersion;
+ *minorVersion = rep.minorVersion;
+ *sharedPixmaps = rep.sharedPixmaps ? True : False;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+
+int XShmPixmapFormat(Display *dpy)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xShmQueryVersionReply rep;
+ register xShmQueryVersionReq *req;
+
+ ShmCheckExtension (dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(ShmQueryVersion, req);
+ req->reqType = info->codes->major_opcode;
+ req->shmReqType = X_ShmQueryVersion;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ if (rep.sharedPixmaps &&
+ (rep.majorVersion > 1 || rep.minorVersion > 0))
+ return rep.pixmapFormat;
+ return 0;
+}
+
+
+Status XShmAttach(Display *dpy, XShmSegmentInfo *shminfo)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xShmAttachReq *req;
+
+ ShmCheckExtension (dpy, info, 0);
+
+ shminfo->shmseg = XAllocID(dpy);
+ LockDisplay(dpy);
+ GetReq(ShmAttach, req);
+ req->reqType = info->codes->major_opcode;
+ req->shmReqType = X_ShmAttach;
+ req->shmseg = shminfo->shmseg;
+ req->shmid = shminfo->shmid;
+ req->readOnly = shminfo->readOnly ? xTrue : xFalse;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
+
+Status XShmDetach(Display *dpy, XShmSegmentInfo *shminfo)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xShmDetachReq *req;
+
+ ShmCheckExtension (dpy, info, 0);
+
+ LockDisplay(dpy);
+ GetReq(ShmDetach, req);
+ req->reqType = info->codes->major_opcode;
+ req->shmReqType = X_ShmDetach;
+ req->shmseg = shminfo->shmseg;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
+static int _XShmDestroyImage (XImage *ximage)
+{
+ Xfree((char *)ximage);
+ return 1;
+}
+
+#define ROUNDUP(nbytes, pad) ((((nbytes) + ((pad) - 1)) / (pad)) * (pad))
+
+XImage *XShmCreateImage (
+ register Display *dpy,
+ register Visual *visual,
+ unsigned int depth,
+ int format,
+ char *data,
+ XShmSegmentInfo *shminfo,
+ unsigned int width,
+ unsigned int height)
+{
+ register XImage *image;
+
+ image = (XImage *)Xcalloc(1, (unsigned)sizeof(XImage));
+ if (!image)
+ return image;
+ image->data = data;
+ image->obdata = (char *)shminfo;
+ image->width = width;
+ image->height = height;
+ image->depth = depth;
+ image->format = format;
+ image->byte_order = dpy->byte_order;
+ image->bitmap_unit = dpy->bitmap_unit;
+ image->bitmap_bit_order = dpy->bitmap_bit_order;
+ image->bitmap_pad = _XGetScanlinePad(dpy, depth);
+ image->xoffset = 0;
+ if (visual) {
+ image->red_mask = visual->red_mask;
+ image->green_mask = visual->green_mask;
+ image->blue_mask = visual->blue_mask;
+ } else {
+ image->red_mask = image->green_mask = image->blue_mask = 0;
+ }
+ if (format == ZPixmap)
+ image->bits_per_pixel = _XGetBitsPerPixel(dpy, (int)depth);
+ else
+ image->bits_per_pixel = 1;
+ image->bytes_per_line = ROUNDUP((image->bits_per_pixel * width),
+ image->bitmap_pad) >> 3;
+ _XInitImageFuncPtrs(image);
+ image->f.destroy_image = _XShmDestroyImage;
+ return image;
+}
+
+Status XShmPutImage (
+ register Display *dpy,
+ Drawable d,
+ GC gc,
+ register XImage *image,
+ int src_x, int src_y, int dst_x, int dst_y,
+ unsigned int src_width, unsigned int src_height,
+ Bool send_event)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ XShmSegmentInfo *shminfo = (XShmSegmentInfo *)image->obdata;
+ register xShmPutImageReq *req;
+
+ ShmCheckExtension (dpy, info, 0);
+ if (!shminfo) return 0;
+
+ LockDisplay(dpy);
+ FlushGC(dpy, gc);
+ GetReq(ShmPutImage, req);
+ req->reqType = info->codes->major_opcode;
+ req->shmReqType = X_ShmPutImage;
+ req->drawable = d;
+ req->gc = gc->gid;
+ req->srcX = src_x;
+ req->srcY = src_y;
+ req->srcWidth = src_width;
+ req->srcHeight = src_height;
+ req->dstX = dst_x;
+ req->dstY = dst_y;
+ req->totalWidth = image->width;
+ req->totalHeight = image->height;
+ req->depth = image->depth;
+ req->format = image->format;
+ req->sendEvent = send_event;
+ req->shmseg = shminfo->shmseg;
+ req->offset = image->data - shminfo->shmaddr;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
+
+Status XShmGetImage(
+ register Display *dpy,
+ Drawable d,
+ XImage *image,
+ int x, int y,
+ unsigned long plane_mask)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ XShmSegmentInfo *shminfo = (XShmSegmentInfo *)image->obdata;
+ register xShmGetImageReq *req;
+ xShmGetImageReply rep;
+ register Visual *visual;
+
+ ShmCheckExtension (dpy, info, 0);
+ if (!shminfo) return 0;
+
+ LockDisplay(dpy);
+ GetReq(ShmGetImage, req);
+ req->reqType = info->codes->major_opcode;
+ req->shmReqType = X_ShmGetImage;
+ req->drawable = d;
+ req->x = x;
+ req->y = y;
+ req->width = image->width;
+ req->height = image->height;
+ req->planeMask = plane_mask;
+ req->format = image->format;
+ req->shmseg = shminfo->shmseg;
+ req->offset = image->data - shminfo->shmaddr;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 0;
+ }
+ visual = _XVIDtoVisual(dpy, rep.visual);
+ if (visual) {
+ image->red_mask = visual->red_mask;
+ image->green_mask = visual->green_mask;
+ image->blue_mask = visual->blue_mask;
+ } else {
+ image->red_mask = image->green_mask = image->blue_mask = 0;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return 1;
+}
+
+Pixmap XShmCreatePixmap (
+ register Display *dpy,
+ Drawable d,
+ char *data,
+ XShmSegmentInfo *shminfo,
+ unsigned int width, unsigned int height, unsigned int depth)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ Pixmap pid;
+ register xShmCreatePixmapReq *req;
+
+ ShmCheckExtension (dpy, info, 0);
+
+ LockDisplay(dpy);
+ GetReq(ShmCreatePixmap, req);
+ req->reqType = info->codes->major_opcode;
+ req->shmReqType = X_ShmCreatePixmap;
+ req->drawable = d;
+ req->width = width;
+ req->height = height;
+ req->depth = depth;
+ req->shmseg = shminfo->shmseg;
+ req->offset = data - shminfo->shmaddr;
+ pid = req->pid = XAllocID(dpy);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return pid;
+}
diff --git a/nx-X11/lib/Xext/XSync.c b/nx-X11/lib/Xext/XSync.c
new file mode 100644
index 000000000..61f8600ce
--- /dev/null
+++ b/nx-X11/lib/Xext/XSync.c
@@ -0,0 +1,817 @@
+/* $Xorg: XSync.c,v 1.5 2001/02/09 02:03:49 xorgcvs Exp $ */
+/*
+
+Copyright 1991, 1993, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+
+/***********************************************************
+Copyright 1991,1993 by Digital Equipment Corporation, Maynard, Massachusetts,
+and Olivetti Research Limited, Cambridge, England.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Digital or Olivetti
+not be used in advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+DIGITAL AND OLIVETTI DISCLAIM ALL WARRANTIES WITH REGARD TO THIS
+SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL THEY BE LIABLE FOR ANY SPECIAL, INDIRECT OR
+CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
+USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
+OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
+PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+/* $XFree86: xc/lib/Xext/XSync.c,v 1.7tsi Exp $ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#define NEED_EVENTS
+#define NEED_REPLIES
+#include <X11/Xlibint.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+#include <X11/extensions/syncstr.h>
+
+static XExtensionInfo _sync_info_data;
+static XExtensionInfo *sync_info = &_sync_info_data;
+static char *sync_extension_name = SYNC_NAME;
+
+#define SyncCheckExtension(dpy,i,val) \
+ XextCheckExtension(dpy, i, sync_extension_name, val)
+#define SyncSimpleCheckExtension(dpy,i) \
+ XextSimpleCheckExtension(dpy, i, sync_extension_name)
+
+static int close_display(Display *dpy, XExtCodes *codes);
+static Bool wire_to_event(Display *dpy, XEvent *event, xEvent *wire);
+static Status event_to_wire(Display *dpy, XEvent *event, xEvent *wire);
+static char *error_string(Display *dpy, int code, XExtCodes *codes,
+ char *buf, int n);
+
+static XExtensionHooks sync_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ close_display, /* close_display */
+ wire_to_event, /* wire_to_event */
+ event_to_wire, /* event_to_wire */
+ NULL, /* error */
+ error_string, /* error_string */
+};
+
+static char *sync_error_list[] = {
+ "BadCounter",
+ "BadAlarm",
+};
+
+static
+XEXT_GENERATE_FIND_DISPLAY(find_display, sync_info,
+ sync_extension_name,
+ &sync_extension_hooks,
+ XSyncNumberEvents, (XPointer) NULL)
+
+static
+XEXT_GENERATE_CLOSE_DISPLAY(close_display, sync_info)
+
+static
+XEXT_GENERATE_ERROR_STRING(error_string, sync_extension_name,
+ XSyncNumberErrors, sync_error_list)
+
+
+static Bool
+wire_to_event(Display *dpy, XEvent *event, xEvent *wire)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ XSyncCounterNotifyEvent *aevent;
+ xSyncCounterNotifyEvent *awire;
+ XSyncAlarmNotifyEvent *anl;
+ xSyncAlarmNotifyEvent *ane;
+
+ SyncCheckExtension(dpy, info, False);
+
+ switch ((wire->u.u.type & 0x7F) - info->codes->first_event)
+ {
+ case XSyncCounterNotify:
+ awire = (xSyncCounterNotifyEvent *) wire;
+ aevent = (XSyncCounterNotifyEvent *) event;
+ aevent->type = awire->type & 0x7F;
+ aevent->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *) wire);
+ aevent->send_event = (awire->type & 0x80) != 0;
+ aevent->display = dpy;
+ aevent->counter = awire->counter;
+ XSyncIntsToValue(&aevent->wait_value, awire->wait_value_lo,
+ awire->wait_value_hi);
+ XSyncIntsToValue(&aevent->counter_value,
+ awire->counter_value_lo,
+ awire->counter_value_hi);
+ aevent->time = awire->time;
+ aevent->count = awire->count;
+ aevent->destroyed = awire->destroyed;
+ return True;
+
+ case XSyncAlarmNotify:
+ ane = (xSyncAlarmNotifyEvent *) wire; /* ENCODING EVENT PTR */
+ anl = (XSyncAlarmNotifyEvent *) event; /* LIBRARY EVENT PTR */
+ anl->type = ane->type & 0x7F;
+ anl->serial = _XSetLastRequestRead(dpy,
+ (xGenericReply *) wire);
+ anl->send_event = (ane->type & 0x80) != 0;
+ anl->display = dpy;
+ anl->alarm = ane->alarm;
+ XSyncIntsToValue(&anl->counter_value,
+ ane->counter_value_lo,
+ ane->counter_value_hi);
+ XSyncIntsToValue(&anl->alarm_value,
+ ane->alarm_value_lo,
+ ane->alarm_value_hi);
+ anl->state = (XSyncAlarmState)ane->state;
+ anl->time = ane->time;
+ return True;
+ }
+
+ return False;
+}
+
+static Status
+event_to_wire(Display *dpy, XEvent *event, xEvent *wire)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ XSyncCounterNotifyEvent *aevent;
+ xSyncCounterNotifyEvent *awire;
+ XSyncAlarmNotifyEvent *anl;
+ xSyncAlarmNotifyEvent *ane;
+
+ SyncCheckExtension(dpy, info, False);
+
+ switch ((event->type & 0x7F) - info->codes->first_event)
+ {
+ case XSyncCounterNotify:
+ awire = (xSyncCounterNotifyEvent *) wire;
+ aevent = (XSyncCounterNotifyEvent *) event;
+ awire->type = aevent->type | (aevent->send_event ? 0x80 : 0);
+ awire->sequenceNumber = aevent->serial & 0xFFFF;
+ awire->counter = aevent->counter;
+ awire->wait_value_lo = XSyncValueLow32(aevent->wait_value);
+ awire->wait_value_hi = XSyncValueHigh32(aevent->wait_value);
+ awire->counter_value_lo = XSyncValueLow32(aevent->counter_value);
+ awire->counter_value_hi = XSyncValueHigh32(aevent->counter_value);
+ awire->time = aevent->time;
+ awire->count = aevent->count;
+ awire->destroyed = aevent->destroyed;
+ return True;
+
+ case XSyncAlarmNotify:
+ ane = (xSyncAlarmNotifyEvent *) wire; /* ENCODING EVENT PTR */
+ anl = (XSyncAlarmNotifyEvent *) event; /* LIBRARY EVENT PTR */
+ ane->type = anl->type | (anl->send_event ? 0x80 : 0);
+ ane->sequenceNumber = anl->serial & 0xFFFF;
+ ane->alarm = anl->alarm;
+ ane->counter_value_lo = XSyncValueLow32(anl->counter_value);
+ ane->counter_value_hi = XSyncValueHigh32(anl->counter_value);
+ ane->alarm_value_lo = XSyncValueLow32(anl->alarm_value);
+ ane->alarm_value_hi = XSyncValueHigh32(anl->alarm_value);
+ ane->state = anl->state;
+ ane->time = anl->time;
+ return True;
+ }
+ return False;
+}
+
+Status
+XSyncQueryExtension(
+ Display *dpy,
+ int *event_base_return, int *error_base_return)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+
+ if (XextHasExtension(info))
+ {
+ *event_base_return = info->codes->first_event;
+ *error_base_return = info->codes->first_error;
+ return True;
+ }
+ else
+ return False;
+}
+
+Status
+XSyncInitialize(
+ Display *dpy,
+ int *major_version_return, int *minor_version_return)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncInitializeReply rep;
+ xSyncInitializeReq *req;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncInitialize, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncInitialize;
+ req->majorVersion = SYNC_MAJOR_VERSION;
+ req->minorVersion = SYNC_MINOR_VERSION;
+ if (!_XReply(dpy, (xReply *) & rep, 0, xTrue))
+ {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ *major_version_return = rep.majorVersion;
+ *minor_version_return = rep.minorVersion;
+ return ((rep.majorVersion == SYNC_MAJOR_VERSION)
+#if SYNC_MINOR_VERSION > 0 /* avoid compiler warning */
+ && (rep.minorVersion >= SYNC_MINOR_VERSION)
+#endif
+ );
+}
+
+XSyncSystemCounter *
+XSyncListSystemCounters(Display *dpy, int *n_counters_return)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncListSystemCountersReply rep;
+ xSyncListSystemCountersReq *req;
+ XSyncSystemCounter *list = NULL;
+
+ SyncCheckExtension(dpy, info, NULL);
+
+ LockDisplay(dpy);
+ GetReq(SyncListSystemCounters, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncListSystemCounters;
+ if (!_XReply(dpy, (xReply *) & rep, 0, xFalse))
+ goto bail;
+
+ *n_counters_return = rep.nCounters;
+ if (rep.nCounters > 0)
+ {
+ xSyncSystemCounter *pWireSysCounter, *pNextWireSysCounter;
+ XSyncCounter counter;
+ int replylen;
+ int i;
+
+ list = (XSyncSystemCounter *)Xmalloc(
+ rep.nCounters * sizeof(XSyncSystemCounter));
+ replylen = rep.length << 2;
+ pWireSysCounter = (xSyncSystemCounter *) Xmalloc ((unsigned) replylen + 1);
+ /* +1 to leave room for last null-terminator */
+
+ if ((!list) || (!pWireSysCounter))
+ {
+ if (list) Xfree((char *) list);
+ if (pWireSysCounter) Xfree((char *) pWireSysCounter);
+ _XEatData(dpy, (unsigned long) replylen);
+ list = NULL;
+ goto bail;
+ }
+
+ _XReadPad(dpy, (char *)pWireSysCounter, replylen);
+
+ counter = pWireSysCounter->counter;
+ for (i = 0; i < rep.nCounters; i++)
+ {
+ list[i].counter = counter;
+ XSyncIntsToValue(&list[i].resolution,
+ pWireSysCounter->resolution_lo,
+ pWireSysCounter->resolution_hi);
+
+ /* we may be about to clobber the counter field of the
+ * next syscounter because we have to add a null terminator
+ * to the counter name string. So we save the next counter
+ * here.
+ */
+ pNextWireSysCounter = (xSyncSystemCounter *)
+ (((char *)pWireSysCounter) + ((SIZEOF(xSyncSystemCounter) +
+ pWireSysCounter->name_length + 3) & ~3));
+ counter = pNextWireSysCounter->counter;
+
+ list[i].name = ((char *)pWireSysCounter) +
+ SIZEOF(xSyncSystemCounter);
+ /* null-terminate the string */
+ *(list[i].name + pWireSysCounter->name_length) = '\0';
+ pWireSysCounter = pNextWireSysCounter;
+ }
+ }
+
+bail:
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return list;
+}
+
+void
+XSyncFreeSystemCounterList(XSyncSystemCounter *list)
+{
+ if (list)
+ {
+ Xfree( ((char *)list[0].name) - SIZEOF(xSyncSystemCounter));
+ Xfree(list);
+ }
+}
+
+
+XSyncCounter
+XSyncCreateCounter(Display *dpy, XSyncValue initial_value)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncCreateCounterReq *req;
+
+ SyncCheckExtension(dpy, info, None);
+
+ LockDisplay(dpy);
+ GetReq(SyncCreateCounter, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncCreateCounter;
+
+ req->cid = XAllocID(dpy);
+ req->initial_value_lo = XSyncValueLow32(initial_value);
+ req->initial_value_hi = XSyncValueHigh32(initial_value);
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return req->cid;
+}
+
+Status
+XSyncSetCounter(Display *dpy, XSyncCounter counter, XSyncValue value)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncSetCounterReq *req;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncSetCounter, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncSetCounter;
+ req->cid = counter;
+ req->value_lo = XSyncValueLow32(value);
+ req->value_hi = XSyncValueHigh32(value);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Status
+XSyncChangeCounter(Display *dpy, XSyncCounter counter, XSyncValue value)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncChangeCounterReq *req;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncChangeCounter, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncChangeCounter;
+ req->cid = counter;
+ req->value_lo = XSyncValueLow32(value);
+ req->value_hi = XSyncValueHigh32(value);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Status
+XSyncDestroyCounter(Display *dpy, XSyncCounter counter)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncDestroyCounterReq *req;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncDestroyCounter, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncDestroyCounter;
+ req->counter = counter;
+ UnlockDisplay(dpy);
+ SyncHandle();
+
+ return True;
+}
+
+Status
+XSyncQueryCounter(Display *dpy, XSyncCounter counter, XSyncValue *value_return)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncQueryCounterReply rep;
+ xSyncQueryCounterReq *req;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncQueryCounter, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncQueryCounter;
+ req->counter = counter;
+ if (!_XReply(dpy, (xReply *) & rep, 0, xTrue))
+ {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ XSyncIntsToValue(value_return, rep.value_lo, rep.value_hi);
+ UnlockDisplay(dpy);
+ SyncHandle();
+
+ return True;
+}
+
+
+Status
+XSyncAwait(Display *dpy, XSyncWaitCondition *wait_list, int n_conditions)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ XSyncWaitCondition *wait_item = wait_list;
+ xSyncAwaitReq *req;
+ unsigned int len;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncAwait, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncAwait;
+ len = (n_conditions * SIZEOF(xSyncWaitCondition)) >> 2;
+ SetReqLen(req, len, len /* XXX */ );
+
+ while (n_conditions--)
+ {
+ xSyncWaitCondition wc;
+ wc.counter = wait_item->trigger.counter;
+ wc.value_type = wait_item->trigger.value_type;
+ wc.wait_value_lo = XSyncValueLow32(wait_item->trigger.wait_value);
+ wc.wait_value_hi = XSyncValueHigh32(wait_item->trigger.wait_value);
+ wc.test_type = wait_item->trigger.test_type;
+ wc.event_threshold_lo = XSyncValueLow32(wait_item->event_threshold);
+ wc.event_threshold_hi = XSyncValueHigh32(wait_item->event_threshold);
+ Data(dpy, (char *)&wc, SIZEOF(xSyncWaitCondition));
+ wait_item++; /* get next trigger */
+ }
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+static void
+_XProcessAlarmAttributes(Display *dpy, xSyncChangeAlarmReq *req,
+ unsigned long valuemask,
+ XSyncAlarmAttributes *attributes)
+{
+
+ unsigned long values[32];
+ unsigned long *value = values;
+ unsigned int nvalues;
+
+ if (valuemask & XSyncCACounter)
+ *value++ = attributes->trigger.counter;
+
+ if (valuemask & XSyncCAValueType)
+ *value++ = attributes->trigger.value_type;
+
+ if (valuemask & XSyncCAValue)
+ {
+ *value++ = XSyncValueHigh32(attributes->trigger.wait_value);
+ *value++ = XSyncValueLow32(attributes->trigger.wait_value);
+ }
+
+ if (valuemask & XSyncCATestType)
+ *value++ = attributes->trigger.test_type;
+
+ if (valuemask & XSyncCADelta)
+ {
+ *value++ = XSyncValueHigh32(attributes->delta);
+ *value++ = XSyncValueLow32(attributes->delta);
+ }
+
+ if (valuemask & XSyncCAEvents)
+ *value++ = attributes->events;
+
+ /* N.B. the 'state' field cannot be set or changed */
+ req->length += (nvalues = value - values);
+ nvalues <<= 2; /* watch out for macros... */
+
+ Data32(dpy, (long *) values, (long) nvalues);
+}
+
+XSyncAlarm
+XSyncCreateAlarm(
+ Display *dpy,
+ unsigned long values_mask,
+ XSyncAlarmAttributes *values)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncCreateAlarmReq *req;
+ XSyncAlarm aid;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncCreateAlarm, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncCreateAlarm;
+ req->id = aid = XAllocID(dpy);
+ values_mask &= XSyncCACounter | XSyncCAValueType | XSyncCAValue
+ | XSyncCATestType | XSyncCADelta | XSyncCAEvents;
+ if ((req->valueMask = values_mask))
+ _XProcessAlarmAttributes(dpy, (xSyncChangeAlarmReq *) req,
+ values_mask, values);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return aid;
+}
+
+Status
+XSyncDestroyAlarm(Display *dpy, XSyncAlarm alarm)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncDestroyAlarmReq *req;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncDestroyAlarm, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncDestroyAlarm;
+ req->alarm = alarm;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Status
+XSyncQueryAlarm(
+ Display *dpy,
+ XSyncAlarm alarm,
+ XSyncAlarmAttributes *values_return)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncQueryAlarmReq *req;
+ xSyncQueryAlarmReply rep;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncQueryAlarm, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncQueryAlarm;
+ req->alarm = alarm;
+
+ if (!(_XReply(dpy, (xReply *) & rep,
+ ((SIZEOF(xSyncQueryAlarmReply) - SIZEOF(xGenericReply)) >> 2), xFalse)))
+ {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+
+ values_return->trigger.counter = rep.counter;
+ values_return->trigger.value_type = (XSyncValueType)rep.value_type;
+ XSyncIntsToValue(&values_return->trigger.wait_value,
+ rep.wait_value_lo, rep.wait_value_hi);
+ values_return->trigger.test_type = (XSyncTestType)rep.test_type;
+ XSyncIntsToValue(&values_return->delta, rep.delta_lo,
+ rep.delta_hi);
+ values_return->events = rep.events;
+ values_return->state = (XSyncAlarmState)rep.state;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Status
+XSyncChangeAlarm(
+ Display *dpy,
+ XSyncAlarm alarm,
+ unsigned long values_mask,
+ XSyncAlarmAttributes *values)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncChangeAlarmReq *req;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncChangeAlarm, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncChangeAlarm;
+ req->alarm = alarm;
+ values_mask &= XSyncCACounter | XSyncCAValueType | XSyncCAValue
+ | XSyncCATestType | XSyncCADelta | XSyncCAEvents;
+ if ((req->valueMask = values_mask))
+ _XProcessAlarmAttributes(dpy, req, values_mask, values);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Status
+XSyncSetPriority(
+ Display *dpy,
+ XID client_resource_id,
+ int priority)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncSetPriorityReq *req;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncSetPriority, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncSetPriority;
+ req->id = client_resource_id;
+ req->priority = priority;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Status
+XSyncGetPriority(Display *dpy, XID client_resource_id, int *return_priority)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncGetPriorityReply rep;
+ xSyncGetPriorityReq *req;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncGetPriority, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncGetPriority;
+ req->id = client_resource_id;
+
+ if (!_XReply(dpy, (xReply *) & rep, 0, xFalse))
+ {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ if (return_priority)
+ *return_priority = rep.priority;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+/*
+ * Functions corresponding to the macros for manipulating 64-bit values
+ */
+
+/* get rid of macros so we can define corresponding functions */
+#undef XSyncIntToValue
+#undef XSyncIntsToValue
+#undef XSyncValueGreaterThan
+#undef XSyncValueLessThan
+#undef XSyncValueGreaterOrEqual
+#undef XSyncValueLessOrEqual
+#undef XSyncValueEqual
+#undef XSyncValueIsNegative
+#undef XSyncValueIsZero
+#undef XSyncValueIsPositive
+#undef XSyncValueLow32
+#undef XSyncValueHigh32
+#undef XSyncValueAdd
+#undef XSyncValueSubtract
+#undef XSyncMaxValue
+#undef XSyncMinValue
+
+void
+XSyncIntToValue(XSyncValue *pv, int i)
+{
+ _XSyncIntToValue(pv,i);
+}
+
+void
+XSyncIntsToValue(XSyncValue *pv, unsigned int l, int h)
+{
+ _XSyncIntsToValue(pv, l, h);
+}
+
+Bool
+XSyncValueGreaterThan(XSyncValue a, XSyncValue b)
+{
+ return _XSyncValueGreaterThan(a, b);
+}
+
+Bool
+XSyncValueLessThan(XSyncValue a, XSyncValue b)
+{
+ return _XSyncValueLessThan(a, b);
+}
+
+Bool
+XSyncValueGreaterOrEqual(XSyncValue a, XSyncValue b)
+{
+ return _XSyncValueGreaterOrEqual(a, b);
+}
+
+Bool
+XSyncValueLessOrEqual(XSyncValue a, XSyncValue b)
+{
+ return _XSyncValueLessOrEqual(a, b);
+}
+
+Bool
+XSyncValueEqual(XSyncValue a, XSyncValue b)
+{
+ return _XSyncValueEqual(a, b);
+}
+
+Bool
+XSyncValueIsNegative(XSyncValue v)
+{
+ return _XSyncValueIsNegative(v);
+}
+
+Bool
+XSyncValueIsZero(XSyncValue a)
+{
+ return _XSyncValueIsZero(a);
+}
+
+Bool
+XSyncValueIsPositive(XSyncValue v)
+{
+ return _XSyncValueIsPositive(v);
+}
+
+unsigned int
+XSyncValueLow32(XSyncValue v)
+{
+ return _XSyncValueLow32(v);
+}
+
+int
+XSyncValueHigh32(XSyncValue v)
+{
+ return _XSyncValueHigh32(v);
+}
+
+void
+XSyncValueAdd(XSyncValue *presult, XSyncValue a, XSyncValue b, Bool *poverflow)
+{
+ _XSyncValueAdd(presult, a, b, poverflow);
+}
+
+void
+XSyncValueSubtract(
+ XSyncValue *presult,
+ XSyncValue a, XSyncValue b,
+ Bool *poverflow)
+{
+ _XSyncValueSubtract(presult, a, b, poverflow);
+}
+
+void
+XSyncMaxValue(XSyncValue *pv)
+{
+ _XSyncMaxValue(pv);
+}
+
+void
+XSyncMinValue(XSyncValue *pv)
+{
+ _XSyncMinValue(pv);
+}
diff --git a/nx-X11/lib/Xext/XTestExt1.c b/nx-X11/lib/Xext/XTestExt1.c
new file mode 100644
index 000000000..ee4a0bde0
--- /dev/null
+++ b/nx-X11/lib/Xext/XTestExt1.c
@@ -0,0 +1,1321 @@
+/* $Xorg: XTestExt1.c,v 1.4 2001/02/09 02:03:49 xorgcvs Exp $ */
+/*
+ * File: xtestext1lib.c
+ *
+ * This file contains the Xlib parts of the input synthesis extension
+ */
+
+/*
+
+
+Copyright 1986, 1987, 1988, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+
+Copyright 1986, 1987, 1988 by Hewlett-Packard Corporation
+
+Permission to use, copy, modify, and distribute this
+software and its documentation for any purpose and without
+fee is hereby granted, provided that the above copyright
+notice appear in all copies and that both that copyright
+notice and this permission notice appear in supporting
+documentation, and that the name of Hewlett-Packard not be used in
+advertising or publicity pertaining to distribution of the
+software without specific, written prior permission.
+
+Hewlett-Packard makes no representations about the
+suitability of this software for any purpose. It is provided
+"as is" without express or implied warranty.
+
+This software is not subject to any license of the American
+Telephone and Telegraph Company or of the Regents of the
+University of California.
+
+*/
+/* $XFree86: xc/lib/Xext/XTestExt1.c,v 1.3 2001/01/17 19:42:46 dawes Exp $ */
+
+/******************************************************************************
+ * include files
+ *****************************************************************************/
+
+#define NEED_REPLIES
+#define NEED_EVENTS
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xproto.h>
+#include <X11/Xlibint.h>
+#include <X11/extensions/xtestext1.h>
+
+/******************************************************************************
+ * variables
+ *****************************************************************************/
+
+/*
+ * Holds the request type code for this extension. The request type code
+ * for this extension may vary depending on how many extensions are installed
+ * already, so the initial value given below will be added to the base request
+ * code that is aquired when this extension is installed.
+ */
+static int XTestReqCode = 0;
+/*
+ * Holds the two event type codes for this extension. The event type codes
+ * for this extension may vary depending on how many extensions are installed
+ * already, so the initial values given below will be added to the base event
+ * code that is aquired when this extension is installed.
+ *
+ * These two variables must be available to programs that use this extension.
+ */
+int XTestInputActionType = 0;
+int XTestFakeAckType = 1;
+/*
+ * holds the current x and y coordinates for XTestMovePointer
+ */
+static int current_x = 0;
+static int current_y = 0;
+/*
+ * Holds input actions being accumulated until the input action buffer is
+ * full or until XTestFlush is called.
+ */
+static CARD8 action_buf[XTestMAX_ACTION_LIST_SIZE];
+/*
+ * the index into the input action buffer
+ */
+static int action_index = 0;
+/*
+ * the number of input actions that the server can handle at one time
+ */
+static unsigned long action_array_size = 0;
+/*
+ * the current number of input actions
+ */
+static unsigned long action_count = 0;
+
+/******************************************************************************
+ * function declarations
+ *****************************************************************************/
+
+static int XTestWireToEvent(Display *dpy, XEvent *reTemp, xEvent *eventTemp);
+static int XTestCheckExtInit(register Display *dpy);
+static Bool XTestIdentifyMyEvent(Display *display, XEvent *event_ptr, char *args);
+static int XTestInitExtension(register Display *dpy);
+static int XTestKeyOrButton(Display *display, int device_id, long unsigned int delay, unsigned int code, unsigned int action);
+static int XTestCheckDelay(Display *display, long unsigned int *delay_addr);
+static int XTestPackInputAction(Display *display, CARD8 *action_addr, int action_size);
+static int XTestWriteInputActions(Display *display, char *action_list_addr, int action_list_size, int ack_flag);
+
+/******************************************************************************
+ *
+ * XTestFakeInput
+ *
+ * Send a a request containing one or more input actions to be sent
+ * to the server by this extension.
+ */
+int
+XTestFakeInput(
+/*
+ * the connection to the X server
+ */
+register Display *dpy,
+/*
+ * the address of a list of input actions to be sent to the server
+ */
+char *action_list_addr,
+/*
+ * the size (in bytes) of the list of input actions
+ */
+int action_list_size,
+/*
+ * specifies whether the server needs to send an event to indicate that its
+ * input action buffer is empty
+ */
+int ack_flag)
+{
+ /*
+ * pointer to xTestFakeInputReq structure
+ */
+ xTestFakeInputReq *req;
+ /*
+ * loop index
+ */
+ int i;
+
+ LockDisplay(dpy);
+ if ((XTestCheckExtInit(dpy) == -1) ||
+ (action_list_size > XTestMAX_ACTION_LIST_SIZE))
+ {
+ /*
+ * if the extension is not installed in the server or the
+ * action list will not fit in the request, then unlock
+ * the display and return -1.
+ */
+ UnlockDisplay(dpy);
+ return(-1);
+ }
+ else
+ {
+ /*
+ * Get the next available X request packet in the buffer.
+ * It sets the `length' field to the size (in 32-bit words)
+ * of the request. It also sets the `reqType' field in the
+ * request to X_TestFakeInput, which is not what is needed.
+ *
+ * GetReq is a macro defined in Xlibint.h.
+ */
+ GetReq(TestFakeInput, req);
+ /*
+ * fix up the request type code to what is needed
+ */
+ req->reqType = XTestReqCode;
+ /*
+ * set the minor request type code to X_TestFakeInput
+ */
+ req->XTestReqType = X_TestFakeInput;
+ /*
+ * set the ack code
+ */
+ req->ack = ack_flag;
+ /*
+ * Set the action_list area to all 0's. An input action header
+ * value of 0 is interpreted as a flag to the input action
+ * list handling code in the server part of this extension
+ * that there are no more input actions in this request.
+ */
+ for (i = 0; i < XTestMAX_ACTION_LIST_SIZE; i++)
+ {
+ req->action_list[i] = 0;
+ }
+ /*
+ * copy the input actions into the request
+ */
+ for (i = 0; i < action_list_size; i++)
+ {
+ req->action_list[i] = *(action_list_addr++);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(0);
+ }
+}
+
+/******************************************************************************
+ *
+ * XTestGetInput
+ *
+ * Request the server to begin putting user input actions into events
+ * to be sent to the client that called this function.
+ */
+int
+XTestGetInput(
+/*
+ * the connection to the X server
+ */
+register Display *dpy,
+/*
+ * tells the server what to do with the user input actions
+ */
+int action_handling)
+{
+ /*
+ * pointer to xTestGetInputReq structure
+ */
+ xTestGetInputReq *req;
+
+ LockDisplay(dpy);
+ if (XTestCheckExtInit(dpy) == -1)
+ {
+ /*
+ * if the extension is not installed in the server
+ * then unlock the display and return -1.
+ */
+ UnlockDisplay(dpy);
+ return(-1);
+ }
+ else
+ {
+ /*
+ * Get the next available X request packet in the buffer.
+ * It sets the `length' field to the size (in 32-bit words)
+ * of the request. It also sets the `reqType' field in the
+ * request to X_TestGetInput, which is not what is needed.
+ *
+ * GetReq is a macro defined in Xlibint.h.
+ */
+ GetReq(TestGetInput, req);
+ /*
+ * fix up the request type code to what is needed
+ */
+ req->reqType = XTestReqCode;
+ /*
+ * set the minor request type code to X_TestGetInput
+ */
+ req->XTestReqType = X_TestGetInput;
+ /*
+ * set the action handling mode
+ */
+ req->mode = action_handling;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(0);
+ }
+}
+
+/******************************************************************************
+ *
+ * XTestStopInput
+ *
+ * Tell the server to stop putting information about user input actions
+ * into events.
+ */
+int
+XTestStopInput(
+/*
+ * the connection to the X server
+ */
+register Display *dpy)
+{
+ /*
+ * pointer to xTestStopInputReq structure
+ */
+ xTestStopInputReq *req;
+
+ LockDisplay(dpy);
+ if (XTestCheckExtInit(dpy) == -1)
+ {
+ /*
+ * if the extension is not installed in the server
+ * then unlock the display and return -1.
+ */
+ UnlockDisplay(dpy);
+ return(-1);
+ }
+ else
+ {
+ /*
+ * Get the next available X request packet in the buffer.
+ * It sets the `length' field to the size (in 32-bit words)
+ * of the request. It also sets the `reqType' field in the
+ * request to X_TestStopInput, which is not what is needed.
+ *
+ * GetReq is a macro defined in Xlibint.h.
+ */
+ GetReq(TestStopInput, req);
+ /*
+ * fix up the request type code to what is needed
+ */
+ req->reqType = XTestReqCode;
+ /*
+ * set the minor request type code to X_TestStopInput
+ */
+ req->XTestReqType = X_TestStopInput;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(0);
+ }
+}
+
+/******************************************************************************
+ *
+ * XTestReset
+ *
+ * Tell the server to set everything having to do with this extension
+ * back to its initial state.
+ */
+int
+XTestReset(
+/*
+ * the connection to the X server
+ */
+register Display *dpy)
+{
+ /*
+ * pointer to xTestReset structure
+ */
+ xTestResetReq *req;
+
+ LockDisplay(dpy);
+ if (XTestCheckExtInit(dpy) == -1)
+ {
+ /*
+ * if the extension is not installed in the server
+ * then unlock the display and return -1.
+ */
+ UnlockDisplay(dpy);
+ return(-1);
+ }
+ else
+ {
+ /*
+ * Get the next available X request packet in the buffer.
+ * It sets the `length' field to the size (in 32-bit words)
+ * of the request. It also sets the `reqType' field in the
+ * request to X_TestReset, which is not what is needed.
+ *
+ * GetReq is a macro defined in Xlibint.h.
+ */
+ GetReq(TestReset, req);
+ /*
+ * fix up the request type code to what is needed
+ */
+ req->reqType = XTestReqCode;
+ /*
+ * set the minor request type code to X_TestReset
+ */
+ req->XTestReqType = X_TestReset;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(0);
+ }
+}
+
+/******************************************************************************
+ *
+ * XTestQueryInputSize
+ *
+ * Returns the number of input actions in the server's input action buffer.
+ */
+int
+XTestQueryInputSize(
+/*
+ * the connection to the X server
+ */
+register Display *dpy,
+/*
+ * the address of the place to put the number of input actions in the
+ * server's input action buffer
+ */
+unsigned long *size_return)
+{
+ /*
+ * pointer to xTestQueryInputSize structure
+ */
+ xTestQueryInputSizeReq *req;
+ /*
+ * pointer to xTestQueryInputSize structure
+ */
+ xTestQueryInputSizeReply rep;
+
+ LockDisplay(dpy);
+ if (XTestCheckExtInit(dpy) == -1)
+ {
+ /*
+ * if the extension is not installed in the server
+ * then unlock the display and return -1.
+ */
+ UnlockDisplay(dpy);
+ return(-1);
+ }
+ else
+ {
+ /*
+ * Get the next available X request packet in the buffer.
+ * It sets the `length' field to the size (in 32-bit words)
+ * of the request. It also sets the `reqType' field in the
+ * request to X_TestQueryInputSize, which is not what is needed.
+ *
+ * GetReq is a macro defined in Xlibint.h.
+ */
+ GetReq(TestQueryInputSize, req);
+ /*
+ * fix up the request type code to what is needed
+ */
+ req->reqType = XTestReqCode;
+ /*
+ * set the minor request type code to X_TestQueryInputSize
+ */
+ req->XTestReqType = X_TestQueryInputSize;
+ /*
+ * get a reply from the server
+ */
+ (void) _XReply (dpy, (xReply *) &rep, 0, xTrue);
+ /*
+ * put the size in the caller's variable
+ */
+ *size_return = (unsigned long) rep.size_return;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return(0);
+ }
+}
+
+/******************************************************************************
+ *
+ * XTestCheckExtInit
+ *
+ * Check to see if the XTest extension is installed in the server.
+ */
+static int
+XTestCheckExtInit(
+/*
+ * the connection to the X server
+ */
+register Display *dpy)
+{
+ /*
+ * if the extension has not been initialized, then do so
+ */
+ if (!XTestReqCode)
+ {
+ return(XTestInitExtension(dpy));
+ }
+ return(0);
+}
+
+/******************************************************************************
+ *
+ * XTestInitExtension
+ *
+ * Attempt to initialize this extension in the server. Return 0 if it
+ * succeeds, -1 if it does not succeed.
+ */
+static int
+XTestInitExtension(
+/*
+ * the connection to the X server
+ */
+register Display *dpy)
+{
+ /*
+ * loop index
+ */
+ int i;
+ /*
+ * return value from XInitExtension
+ */
+ XExtCodes *ret;
+
+ /*
+ * attempt to initialize the extension
+ */
+ ret = XInitExtension(dpy, XTestEXTENSION_NAME);
+ /*
+ * if the initialize failed, return -1
+ */
+ if (ret == NULL)
+ {
+ return (-1);
+ }
+ /*
+ * the initialize succeeded, remember the major opcode
+ * for this extension
+ */
+ XTestReqCode = ret->major_opcode;
+ /*
+ * set up the event handler for any events from
+ * this extension
+ */
+ for (i = 0; i < XTestEVENT_COUNT; i++)
+ {
+ XESetWireToEvent(dpy,
+ ret->first_event+i,
+ XTestWireToEvent);
+ }
+ /*
+ * compute the event type codes for the events
+ * in this extension
+ */
+ XTestInputActionType += ret->first_event;
+ XTestFakeAckType += ret->first_event;
+ /*
+ * everything worked ok
+ */
+ return(0);
+}
+
+/******************************************************************************
+ *
+ * XTestWireToEvent
+ *
+ * Handle XTest extension events.
+ * Reformat a wire event into an XEvent structure of the right type.
+ */
+static Bool
+XTestWireToEvent(
+/*
+ * the connection to the X server
+ */
+Display *dpy,
+/*
+ * a pointer to where a host formatted event should be stored
+ * with the information copied to it
+ */
+XEvent *reTemp,
+/*
+ * a pointer to the wire event
+ */
+xEvent *eventTemp)
+{
+ XTestInputActionEvent *re = (XTestInputActionEvent *) reTemp;
+ xTestInputActionEvent *event = (xTestInputActionEvent *) eventTemp;
+
+ /*
+ * loop index
+ */
+ int i;
+ /*
+ * pointer to where the input actions go in the host format event
+ */
+ CARD8 *to;
+ /*
+ * pointer to the input actions in the wire event
+ */
+ CARD8 *from;
+
+ /*
+ * Copy the type of the wire event to the new event.
+ * This will work for either event type because the type,
+ * display, and window fields in the events have to be the same.
+ */
+ re->type = event->type;
+ /*
+ * set the display parameter in case it is needed (by who?)
+ */
+ re->display = dpy;
+ if (re->type == XTestInputActionType)
+ {
+ /*
+ * point at the first byte of input actions in the wire event
+ */
+ from = &(event->actions[0]);
+ /*
+ * point at where the input action bytes go in the new event
+ */
+ to = &(re->actions[0]);
+ /*
+ * copy the input action bytes from the wire event to
+ * the new event
+ */
+ for (i = 0; i < XTestACTIONS_SIZE; i++)
+ {
+ *(to++) = *(from++);
+ }
+ }
+ else if (re->type == XTestFakeAckType)
+ {
+ /*
+ * nothing else needs to be done
+ */
+ }
+ else
+ {
+ printf("XTestWireToEvent: UNKNOWN WIRE EVENT! type=%d\n",
+ (int) event->type);
+ printf("%s is giving up.\n", XTestEXTENSION_NAME);
+ exit (1);
+ }
+ return 1;
+}
+
+/******************************************************************************
+ *
+ * XTestPressKey
+ *
+ * Send input actions to the server to cause the server to think
+ * that the specified key on the keyboard was moved as specified.
+ */
+int
+XTestPressKey(
+Display *display,
+int device_id,
+unsigned long delay,
+unsigned int keycode,
+unsigned int key_action)
+{
+ /*
+ * bounds check the key code
+ */
+ if (keycode < 8 || keycode > 255)
+ {
+ return(-1);
+ }
+ /*
+ * use the commmon key/button handling routine
+ */
+ return(XTestKeyOrButton(display,
+ device_id,
+ delay,
+ keycode,
+ key_action));
+}
+
+/******************************************************************************
+ *
+ * XTestPressButton
+ *
+ * Send input actions to the server to cause the server to think
+ * that the specified button on the mouse was moved as specified.
+ */
+int
+XTestPressButton(
+Display *display,
+int device_id,
+unsigned long delay,
+unsigned int button_number,
+unsigned int button_action)
+{
+ /*
+ * bounds check the button number
+ */
+ if (button_number > 7)
+ {
+ return(-1);
+ }
+ /*
+ * use the commmon key/button handling routine
+ */
+ return(XTestKeyOrButton(display,
+ device_id,
+ delay,
+ button_number,
+ button_action));
+}
+
+/******************************************************************************
+ *
+ * XTestKeyOrButton
+ *
+ * Send input actions to the server to cause the server to think
+ * that the specified key/button was moved as specified.
+ */
+static int
+XTestKeyOrButton(
+Display *display,
+int device_id,
+unsigned long delay,
+unsigned int code,
+unsigned int action)
+{
+ /*
+ * holds a key input action to be filled out and sent to the server
+ */
+ XTestKeyInfo keyinfo;
+
+ /*
+ * bounds check the device id
+ */
+ if (device_id < 0 || device_id > XTestMAX_DEVICE_ID)
+ {
+ return(-1);
+ }
+ /*
+ * fill out the key input action(s) as appropriate
+ */
+ switch(action)
+ {
+ case XTestPRESS:
+ /*
+ * Check the delay. If it is larger than will fit in the
+ * key input action, send a delay input action.
+ */
+ if(XTestCheckDelay(display, &delay) == -1)
+ {
+ /*
+ * an error occurred, return -1
+ */
+ return(-1);
+ }
+ /*
+ * create the header
+ */
+ keyinfo.header = XTestPackDeviceID(device_id) |
+ XTestKEY_ACTION |
+ XTestKEY_DOWN;
+ /*
+ * set the key/button code
+ */
+ keyinfo.keycode = code;
+ /*
+ * set the delay time
+ */
+ keyinfo.delay_time = delay;
+ /*
+ * pack the input action into a request to be sent to the
+ * server when the request is full or XTestFlush is called
+ */
+ return(XTestPackInputAction(display,
+ (CARD8 *) &keyinfo,
+ sizeof(XTestKeyInfo)));
+ case XTestRELEASE:
+ /*
+ * Check the delay. If it is larger than will fit in the
+ * key input action, send a delay input action.
+ */
+ if(XTestCheckDelay(display, &delay) == -1)
+ {
+ /*
+ * an error occurred, return -1
+ */
+ return(-1);
+ }
+ /*
+ * create the header
+ */
+ keyinfo.header = XTestPackDeviceID(device_id) |
+ XTestKEY_ACTION |
+ XTestKEY_UP;
+ /*
+ * set the key/button code
+ */
+ keyinfo.keycode = code;
+ /*
+ * set the delay time
+ */
+ keyinfo.delay_time = delay;
+ /*
+ * pack the input action into a request to be sent to the
+ * server when the request is full or XTestFlush is called
+ */
+ return(XTestPackInputAction(display,
+ (CARD8 *) &keyinfo,
+ sizeof(XTestKeyInfo)));
+ case XTestSTROKE:
+ /*
+ * Check the delay. If it is larger than will fit in the
+ * key input action, send a delay input action.
+ */
+ if(XTestCheckDelay(display, &delay) == -1)
+ {
+ /*
+ * an error occurred, return -1
+ */
+ return(-1);
+ }
+ /*
+ * create a key/button-down input action header
+ */
+ keyinfo.header = XTestPackDeviceID(device_id) |
+ XTestKEY_ACTION |
+ XTestKEY_DOWN;
+ /*
+ * set the key/button code
+ */
+ keyinfo.keycode = code;
+ /*
+ * set the delay time
+ */
+ keyinfo.delay_time = delay;
+ /*
+ * pack the input action into a request to be sent to the
+ * server when the request is full or XTestFlush is called
+ */
+ if (XTestPackInputAction(display,
+ (CARD8 *) &keyinfo,
+ sizeof(XTestKeyInfo)) == -1)
+ {
+ /*
+ * an error occurred, return -1
+ */
+ return(-1);
+ }
+ /*
+ * set the delay to XTestSTROKE_DELAY_TIME
+ */
+ delay = XTestSTROKE_DELAY_TIME;
+ /*
+ * Check the delay. If it is larger than will fit in the
+ * key input action, send a delay input action.
+ */
+ if(XTestCheckDelay(display, &delay) == -1)
+ {
+ /*
+ * an error occurred, return -1
+ */
+ return(-1);
+ }
+ /*
+ * create a key/button-up input action header
+ */
+ keyinfo.header = XTestPackDeviceID(device_id) |
+ XTestKEY_ACTION |
+ XTestKEY_UP;
+ /*
+ * set the key/button code
+ */
+ keyinfo.keycode = code;
+ /*
+ * set the delay time
+ */
+ keyinfo.delay_time = delay;
+ /*
+ * pack the input action into a request to be sent to the
+ * server when the request is full or XTestFlush is called
+ */
+ return(XTestPackInputAction(display,
+ (CARD8 *) &keyinfo,
+ sizeof(XTestKeyInfo)));
+ default:
+ /*
+ * invalid action value, return -1
+ */
+ return(-1);
+ }
+}
+
+/******************************************************************************
+ *
+ * XTestMovePointer
+ *
+ * Send input actions to the server to cause the server to think
+ * that the mouse was moved as specified.
+ */
+int
+XTestMovePointer(
+Display *display,
+int device_id,
+unsigned long delay[],
+int x[],
+int y[],
+unsigned int count)
+{
+ /*
+ * holds a motion input action to be filled out and sent to the server
+ */
+ XTestMotionInfo motioninfo;
+ /*
+ * holds a jump input action to be filled out and sent to the server
+ */
+ XTestJumpInfo jumpinfo;
+ /*
+ * loop index
+ */
+ unsigned int i;
+ /*
+ * holds the change in x and y directions from the current x and y
+ * coordinates
+ */
+ int dx;
+ int dy;
+
+ /*
+ * bounds check the device id
+ */
+ if (device_id < 0 || device_id > XTestMAX_DEVICE_ID)
+ {
+ return(-1);
+ }
+ /*
+ * if the count is 0, there is nothing to do. return 0
+ */
+ if (count == 0)
+ {
+ return(0);
+ }
+ /*
+ * loop through the pointer motions, creating the appropriate
+ * input actions for each motion
+ */
+ for (i = 0; i < count; i++)
+ {
+ /*
+ * Check the delay. If it is larger than will fit in the
+ * input action, send a delay input action.
+ */
+ if(XTestCheckDelay(display, &(delay[i])) == -1)
+ {
+ /*
+ * an error occurred, return -1
+ */
+ return(-1);
+ }
+ /*
+ * compute the change from the current x and y coordinates
+ * to the new x and y coordinates
+ */
+ dx = x[i] - current_x;
+ dy = y[i] - current_y;
+ /*
+ * update the current x and y coordinates
+ */
+ current_x = x[i];
+ current_y = y[i];
+ /*
+ * If the pointer motion range is too large to fit into
+ * a motion input action, then use a jump input action.
+ * Otherwise, use a motion input action.
+ */
+ if ((dx > XTestMOTION_MAX) || (dx < XTestMOTION_MIN) ||
+ (dy > XTestMOTION_MAX) || (dy < XTestMOTION_MIN))
+ {
+ /*
+ * create a jump input action header
+ */
+ jumpinfo.header = XTestPackDeviceID(device_id) |
+ XTestJUMP_ACTION;
+ /*
+ * set the x and y coordinates to jump to
+ */
+ jumpinfo.jumpx = x[i];
+ jumpinfo.jumpy = y[i];
+ /*
+ * set the delay time
+ */
+ jumpinfo.delay_time = delay[i];
+ /*
+ * pack the jump input action into a request to be
+ * sent to the server when the request is full
+ * or XTestFlush is called
+ */
+ if (XTestPackInputAction(display,
+ (CARD8 *) &jumpinfo,
+ sizeof(XTestJumpInfo)) == -1)
+ {
+ /*
+ * an error occurred, return -1
+ */
+ return(-1);
+ }
+ }
+ else
+ {
+ /*
+ * create a motion input action header
+ */
+ motioninfo.header = XTestPackDeviceID(device_id) |
+ XTestMOTION_ACTION;
+ /*
+ * compute the motion data byte
+ */
+ if (dx < 0)
+ {
+ motioninfo.header |= XTestX_NEGATIVE;
+ dx = abs(dx);
+ }
+ if (dy < 0)
+ {
+ motioninfo.header |= XTestY_NEGATIVE;
+ dy = abs(dy);
+ }
+ motioninfo.motion_data = XTestPackXMotionValue(dx);
+ motioninfo.motion_data |= XTestPackYMotionValue(dy);
+ /*
+ * set the delay time
+ */
+ motioninfo.delay_time = delay[i];
+ /*
+ * pack the motion input action into a request to be
+ * sent to the server when the request is full
+ * or XTestFlush is called
+ */
+ if (XTestPackInputAction(display,
+ (CARD8 *) &motioninfo,
+ sizeof(XTestMotionInfo)) == -1)
+ {
+ /*
+ * an error occurred, return -1
+ */
+ return(-1);
+ }
+ }
+ }
+ /*
+ * if you get here, everything went ok
+ */
+ return(0);
+}
+
+/******************************************************************************
+ *
+ * XTestCheckDelay
+ *
+ * Check the delay value at the passed-in address. If it is larger than
+ * will fit in a normal input action, then send a delay input action.
+ */
+static int
+XTestCheckDelay(
+Display *display,
+unsigned long *delay_addr)
+{
+ /*
+ * holds a delay input action to be filled out and sent to the server
+ */
+ XTestDelayInfo delayinfo;
+
+ /*
+ * if the delay value will fit in the input action,
+ * then there is no need for a delay input action
+ */
+ if (*delay_addr <= XTestSHORT_DELAY_TIME)
+ {
+ return(0);
+ }
+ /*
+ * fill out a delay input action
+ */
+ delayinfo.header = XTestPackDeviceID(XTestDELAY_DEVICE_ID);
+ delayinfo.delay_time = *delay_addr;
+ /*
+ * all of the delay time will be accounted for in the
+ * delay input action, so set the original delay value to 0
+ */
+ *delay_addr = 0;
+ /*
+ * pack the delay input action into a request to be sent to the
+ * server when the request is full or XTestFlush is called
+ */
+ return(XTestPackInputAction(display,
+ (CARD8 *) &delayinfo,
+ sizeof(XTestDelayInfo)));
+}
+
+/******************************************************************************
+ *
+ * XTestPackInputAction
+ *
+ * If the input action buffer is full or the number of input actions
+ * has reached the maximum that the server can handle at one time,
+ * then send the input actions to the server using XTestFakeInput.
+ */
+static int
+XTestPackInputAction(
+Display *display,
+CARD8 *action_addr,
+int action_size)
+{
+ /*
+ * loop index
+ */
+ int i;
+ /*
+ * acknowledge flag
+ */
+ int ack_flag;
+
+ /*
+ * if we don't already know it, find out how many input actions
+ * the server can handle at one time
+ */
+ if (action_array_size == 0)
+ {
+ if(XTestQueryInputSize(display, &action_array_size) == -1)
+ {
+ /*
+ * if an error, return -1
+ */
+ return(-1);
+ }
+ }
+ /*
+ * if the specified input action will fit in the the input
+ * action buffer and won't exceed the server's capacity, then
+ * put the input action into the input buffer
+ */
+ if(((action_index + action_size) <= XTestMAX_ACTION_LIST_SIZE) &&
+ ((action_count + 1) < action_array_size))
+ {
+ /*
+ * copy the input action into the buffer
+ */
+ for (i = 0; i < action_size; i++)
+ {
+ action_buf[action_index++] = *(action_addr++);
+ }
+ /*
+ * increment the action count
+ */
+ action_count++;
+ /*
+ * everything went ok, return 0
+ */
+ return(0);
+ }
+ /*
+ * We have to write input actions to the server. If the server's
+ * input action capacity will be reached, then ask for an
+ * acknowledge event when the server has processed all of the
+ * input actions. Otherwise, an acknowledge event is not needed.
+ */
+ if (action_count >= action_array_size)
+ {
+ ack_flag = XTestFAKE_ACK_REQUEST;
+ }
+ else
+ {
+ ack_flag = XTestFAKE_ACK_NOT_NEEDED;
+ }
+ /*
+ * write the input actions to the server
+ */
+ if (XTestWriteInputActions(display,
+ (char *) &(action_buf[0]),
+ action_index,
+ ack_flag) == -1)
+ {
+ /*
+ * error, return -1
+ */
+ return(-1);
+ }
+ /*
+ * copy the input action into the buffer
+ */
+ for (i = 0; i < action_size; i++)
+ {
+ action_buf[action_index++] = *(action_addr++);
+ }
+ /*
+ * increment the action count
+ */
+ action_count++;
+ return(0);
+}
+
+/******************************************************************************
+ *
+ * XTestWriteInputActions
+ *
+ * Send input actions to the server.
+ */
+static int
+XTestWriteInputActions(
+Display *display,
+char *action_list_addr,
+int action_list_size,
+int ack_flag)
+{
+ /*
+ * Holds an event. Used while waiting for an acknowledge event
+ */
+ XEvent event;
+ /*
+ * points to XTestIdentifyMyEvent
+ */
+ Bool (*func_ptr)();
+
+ /*
+ * write the input actions to the server
+ */
+ if (XTestFakeInput(display,
+ action_list_addr,
+ action_list_size,
+ ack_flag) == -1)
+ {
+ /*
+ * if an error, return -1
+ */
+ return(-1);
+ }
+ /*
+ * flush X's buffers to make sure that the server really gets
+ * the input actions
+ */
+ XFlush(display);
+ /*
+ * mark the input action buffer as empty
+ */
+ action_index = 0;
+ /*
+ * if we asked for an acknowledge event, then wait for it
+ */
+ if (ack_flag == XTestFAKE_ACK_REQUEST)
+ {
+ /*
+ * point func_ptr at XTestIdentifyMyEvent
+ */
+ func_ptr = XTestIdentifyMyEvent;
+ /*
+ * Wait until the acknowledge event comes. When the
+ * acknowledge event comes, it is removed from the event
+ * queue without disturbing any other events that might
+ * be in the queue.
+ */
+ XIfEvent(display, &event, func_ptr, NULL);
+ /*
+ * set the input action count back to 0
+ */
+ action_count = 0;
+ }
+ /*
+ * if we got here, then everything is ok, return 0
+ */
+ return(0);
+}
+
+/******************************************************************************
+ *
+ * XTestIdentifyMyEvent
+ *
+ * This function is called by XIfEvent to look at an event and see if
+ * it is of XTestFakeAckType.
+ */
+static Bool
+XTestIdentifyMyEvent(
+Display *display,
+/*
+ * Holds the event that this routiine is supposed to look at.
+ */
+XEvent *event_ptr,
+/*
+ * this points to any user-specified arguments (ignored)
+ */
+char *args)
+{
+ /*
+ * if the event if of the correct type, return the Bool True,
+ * otherwise return the Bool False.
+ */
+ if (event_ptr->type == XTestFakeAckType)
+ {
+ return(True);
+ }
+ else
+ {
+ return(False);
+ }
+}
+
+/******************************************************************************
+ *
+ * XTestFlush
+ *
+ * Send any input actions in the input action buffer to the server.
+ */
+int
+XTestFlush(Display *display)
+{
+ /*
+ * acknowledge flag
+ */
+ int ack_flag;
+
+ /*
+ * if there are no input actions in the input action buffer,
+ * then return 0
+ */
+ if (action_index == 0)
+ {
+ return(0);
+ }
+ /*
+ * We have input actions to write to the server. We will
+ * wait until the server has finished processing the input actions.
+ */
+ ack_flag = XTestFAKE_ACK_REQUEST;
+ /*
+ * write the input actions to the server
+ */
+ return(XTestWriteInputActions(display,
+ (char *) &(action_buf[0]),
+ action_index,
+ ack_flag));
+}
diff --git a/nx-X11/lib/Xext/Xcup.c b/nx-X11/lib/Xext/Xcup.c
new file mode 100644
index 000000000..6315d32a4
--- /dev/null
+++ b/nx-X11/lib/Xext/Xcup.c
@@ -0,0 +1,265 @@
+/* $XFree86: xc/lib/Xext/Xcup.c,v 1.8 2002/10/16 02:19:22 dawes Exp $ */
+/*
+
+Copyright 1987, 1988, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+
+*/
+/* $Xorg: Xcup.c,v 1.5 2001/02/09 02:03:49 xorgcvs Exp $ */
+
+#ifdef WIN32
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xwindows.h>
+#endif
+
+#define NEED_EVENTS
+#define NEED_REPLIES
+#include <X11/Xlibint.h>
+#include <X11/extensions/Xcupstr.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+
+static XExtensionInfo _xcup_info_data;
+static XExtensionInfo *xcup_info = &_xcup_info_data;
+static char *xcup_extension_name = XCUPNAME;
+
+/*****************************************************************************
+ * *
+ * private utility routines *
+ * *
+ *****************************************************************************/
+
+static int close_display(Display *dpy, XExtCodes *codes);
+static /* const */ XExtensionHooks xcup_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ close_display, /* close_display */
+ NULL, /* wire_to_event */
+ NULL, /* event_to_wire */
+ NULL, /* error */
+ NULL, /* error_string */
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (find_display, xcup_info,
+ xcup_extension_name,
+ &xcup_extension_hooks,
+ 0, NULL)
+
+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xcup_info)
+
+
+/*****************************************************************************
+ * *
+ * public Xcup Extension routines *
+ * *
+ *****************************************************************************/
+
+Status
+XcupQueryVersion(
+ Display* dpy,
+ int* major_version_return,
+ int* minor_version_return)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xXcupQueryVersionReply rep;
+ xXcupQueryVersionReq *req;
+
+ XextCheckExtension (dpy, info, xcup_extension_name, False);
+
+ LockDisplay(dpy);
+ GetReq(XcupQueryVersion, req);
+ req->reqType = info->codes->major_opcode;
+ req->xcupReqType = X_XcupQueryVersion;
+ req->client_major_version = XCUP_MAJOR_VERSION;
+ req->client_minor_version = XCUP_MINOR_VERSION;
+ if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ *major_version_return = rep.server_major_version;
+ *minor_version_return = rep.server_minor_version;
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+/* Win32 reserves 20 colormap entries for its desktop */
+#ifndef TYP_RESERVED_ENTRIES
+#define TYP_RESERVED_ENTRIES 20
+#endif
+
+Status
+XcupGetReservedColormapEntries(
+ Display* dpy,
+ int screen,
+ XColor** colors_out,
+ int* ncolors)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xXcupGetReservedColormapEntriesReply rep;
+ xXcupGetReservedColormapEntriesReq *req;
+ xColorItem rbuf[TYP_RESERVED_ENTRIES];
+
+ *ncolors = 0;
+
+ XextCheckExtension (dpy, info, xcup_extension_name, False);
+
+ LockDisplay(dpy);
+ GetReq(XcupGetReservedColormapEntries, req);
+ req->reqType = info->codes->major_opcode;
+ req->xcupReqType = X_XcupGetReservedColormapEntries;
+ req->screen = screen;
+ if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ long nbytes;
+ xColorItem* rbufp;
+ int nentries = rep.length / 3;
+
+ nbytes = nentries * SIZEOF (xColorItem);
+ if (nentries > TYP_RESERVED_ENTRIES)
+ rbufp = (xColorItem*) Xmalloc (nbytes);
+ else
+ rbufp = rbuf;
+
+ if (rbufp == NULL) {
+ _XEatData (dpy, (unsigned long) nbytes);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return False;
+ }
+ _XRead (dpy, (char*) rbufp, nbytes);
+
+ *colors_out = (XColor*) Xmalloc (nentries * sizeof (XColor));
+ if (*colors_out) {
+ xColorItem* cs = (xColorItem *) rbufp;
+ XColor* cd = *colors_out;
+ int i;
+
+ *ncolors = nentries;
+ for (i = 0; i < *ncolors; i++, cd++) {
+ cd->pixel = cs->pixel;
+ cd->red = cs->red;
+ cd->green = cs->green;
+ cd->blue = cs->blue;
+ cs = (xColorItem*) (((char*) cs) + SIZEOF(xColorItem));
+ }
+ if (rbufp != rbuf) XFree ((char*) rbufp);
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+ }
+ if (rbufp != rbuf) XFree ((char*) rbufp);
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+}
+
+Status
+XcupStoreColors(
+ Display* dpy,
+ Colormap colormap,
+ XColor* colors_in_out,
+ int ncolors)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xXcupStoreColorsReply rep;
+ xXcupStoreColorsReq *req;
+ xColorItem rbuf[256];
+ xColorItem citem;
+ int i;
+ XColor* xcp;
+
+ XextCheckExtension (dpy, info, xcup_extension_name, False);
+
+ LockDisplay(dpy);
+ GetReq(XcupStoreColors, req);
+ req->reqType = info->codes->major_opcode;
+ req->xcupReqType = X_XcupStoreColors;
+ req->cmap = colormap;
+ req->length += (ncolors * SIZEOF(xColorItem)) >> 2;
+
+ for (i = 0, xcp = colors_in_out; i < ncolors; i++, xcp++) {
+ citem.pixel = xcp->pixel;
+ citem.red = xcp->red;
+ citem.green = xcp->green;
+ citem.blue = xcp->blue;
+
+ /* note that xColorItem doesn't contain all 16-bit quantities, so
+ we can't use Data16 */
+ Data(dpy, (char *)&citem, (long) SIZEOF(xColorItem));
+ }
+
+ if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) {
+ long nbytes;
+ xColorItem* rbufp;
+ xColorItem* cs;
+ int nentries = rep.length / 3;
+
+ nbytes = nentries * SIZEOF (xColorItem);
+
+ if (nentries != ncolors) {
+ _XEatData (dpy, (unsigned long) nbytes);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return False;
+ }
+
+ if (ncolors > 256)
+ rbufp = (xColorItem*) Xmalloc (nbytes);
+ else
+ rbufp = rbuf;
+
+ if (rbufp == NULL) {
+ _XEatData (dpy, (unsigned long) nbytes);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return False;
+
+ }
+
+ _XRead (dpy, (char*) rbufp, nbytes);
+
+ for (i = 0, xcp = colors_in_out, cs = rbufp; i < ncolors; i++, xcp++, cs++) {
+ xcp->pixel = cs->pixel;
+ xcp->red = cs->red;
+ xcp->green = cs->green;
+ xcp->blue = cs->blue;
+ xcp->flags = cs->flags;
+ }
+ if (rbufp != rbuf) XFree ((char*)rbufp);
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+}
+
diff --git a/nx-X11/lib/Xext/Xdbe.c b/nx-X11/lib/Xext/Xdbe.c
new file mode 100644
index 000000000..954c8f01d
--- /dev/null
+++ b/nx-X11/lib/Xext/Xdbe.c
@@ -0,0 +1,474 @@
+/* $Xorg: Xdbe.c,v 1.4 2000/08/17 19:45:53 cpqbld Exp $ */
+/******************************************************************************
+ *
+ * Copyright (c) 1994, 1995 Hewlett-Packard Company
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL HEWLETT-PACKARD COMPANY BE LIABLE FOR ANY CLAIM,
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ * Except as contained in this notice, the name of the Hewlett-Packard
+ * Company shall not be used in advertising or otherwise to promote the
+ * sale, use or other dealings in this Software without prior written
+ * authorization from the Hewlett-Packard Company.
+ *
+ * Xlib DBE code
+ *
+ *****************************************************************************/
+/* $XFree86: xc/lib/Xext/Xdbe.c,v 3.7 2002/10/16 02:19:22 dawes Exp $ */
+
+#define NEED_EVENTS
+#define NEED_REPLIES
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xlibint.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+#define NEED_DBE_PROTOCOL
+#include <X11/extensions/Xdbe.h>
+
+static XExtensionInfo _dbe_info_data;
+static XExtensionInfo *dbe_info = &_dbe_info_data;
+static char *dbe_extension_name = DBE_PROTOCOL_NAME;
+
+#define DbeCheckExtension(dpy,i,val) \
+ XextCheckExtension (dpy, i, dbe_extension_name, val)
+#define DbeSimpleCheckExtension(dpy,i) \
+ XextSimpleCheckExtension (dpy, i, dbe_extension_name)
+
+#if !defined(UNIXCPP)
+#define DbeGetReq(name,req,info) GetReq (name, req); \
+ req->reqType = info->codes->major_opcode; \
+ req->dbeReqType = X_##name;
+#else
+#define DbeGetReq(name,req,info) GetReq (name, req); \
+ req->reqType = info->codes->major_opcode; \
+ req->dbeReqType = X_/**/name;
+#endif
+
+
+/*****************************************************************************
+ * *
+ * private utility routines *
+ * *
+ *****************************************************************************/
+
+/*
+ * find_display - locate the display info block
+ */
+static int close_display(Display *dpy, XExtCodes *codes);
+static char *error_string(Display *dpy, int code, XExtCodes *codes,
+ char *buf, int n);
+static XExtensionHooks dbe_extension_hooks = {
+ NULL, /* create_gc */
+ NULL, /* copy_gc */
+ NULL, /* flush_gc */
+ NULL, /* free_gc */
+ NULL, /* create_font */
+ NULL, /* free_font */
+ close_display, /* close_display */
+ NULL, /* wire_to_event */
+ NULL, /* event_to_wire */
+ NULL, /* error */
+ error_string, /* error_string */
+};
+
+static char *dbe_error_list[] = {
+ "BadBuffer", /* DbeBadBuffer */
+};
+
+static XEXT_GENERATE_FIND_DISPLAY (find_display, dbe_info,
+ dbe_extension_name,
+ &dbe_extension_hooks,
+ DbeNumberEvents, NULL)
+
+static XEXT_GENERATE_CLOSE_DISPLAY (close_display, dbe_info)
+
+static XEXT_GENERATE_ERROR_STRING (error_string, dbe_extension_name,
+ DbeNumberErrors,
+ dbe_error_list)
+
+
+/*****************************************************************************
+ * *
+ * Double-Buffering public interfaces *
+ * *
+ *****************************************************************************/
+
+/*
+ * XdbeQueryExtension -
+ * Sets major_version_return and minor_verion_return to the major and
+ * minor DBE protocol version supported by the server. If the DBE
+ * library is compatible with the version returned by the server, this
+ * function returns non-zero. If dpy does not support the DBE
+ * extension, or if there was an error during communication with the
+ * server, or if the server and library protocol versions are
+ * incompatible, this functions returns zero. No other Xdbe functions
+ * may be called before this function. If a client violates this rule,
+ * the effects of all subsequent Xdbe calls are undefined.
+ */
+Status XdbeQueryExtension (
+ Display *dpy,
+ int *major_version_return,
+ int *minor_version_return)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ xDbeGetVersionReply rep;
+ register xDbeGetVersionReq *req;
+
+ if (!XextHasExtension (info))
+ return (Status)0; /* failure */
+
+ LockDisplay (dpy);
+ DbeGetReq (DbeGetVersion, req, info);
+ req->majorVersion = DBE_MAJOR_VERSION;
+ req->minorVersion = DBE_MINOR_VERSION;
+
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return (Status)0; /* failure */
+ }
+ *major_version_return = rep.majorVersion;
+ *minor_version_return = rep.minorVersion;
+ UnlockDisplay (dpy);
+
+ SyncHandle ();
+
+ if (*major_version_return != DBE_MAJOR_VERSION)
+ return (Status)0; /* failure */
+ else
+ return (Status)1; /* success */
+}
+
+
+/*
+ * XdbeAllocateBackBuffer -
+ * This function returns a drawable ID used to refer to the back buffer
+ * of the specified window. The swap_action is a hint to indicate the
+ * swap action that will likely be used in subsequent calls to
+ * XdbeSwapBuffers. The actual swap action used in calls to
+ * XdbeSwapBuffers does not have to be the same as the swap_action
+ * passed to this function, though clients are encouraged to provide
+ * accurate information whenever possible.
+ */
+
+XdbeBackBuffer XdbeAllocateBackBufferName(
+ Display *dpy,
+ Window window,
+ XdbeSwapAction swap_action)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xDbeAllocateBackBufferNameReq *req;
+ XdbeBackBuffer buffer;
+
+ /* make sure extension is available; if not, return the
+ * third parameter (0).
+ */
+ DbeCheckExtension (dpy, info, (XdbeBackBuffer)0);
+
+ /* allocate the id */
+ buffer = XAllocID (dpy);
+
+ LockDisplay(dpy);
+ DbeGetReq(DbeAllocateBackBufferName, req, info);
+ req->window = window;
+ req->swapAction = (unsigned char)swap_action;
+ req->buffer = buffer;
+
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return buffer;
+
+} /* XdbeAllocateBackBufferName() */
+
+/*
+ * XdbeDeallocateBackBufferName -
+ * This function frees a drawable ID, buffer, that was obtained via
+ * XdbeAllocateBackBufferName. The buffer must refer to the back buffer
+ * of the specified window, or a protocol error results.
+ */
+Status XdbeDeallocateBackBufferName (
+ Display *dpy,
+ XdbeBackBuffer buffer)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xDbeDeallocateBackBufferNameReq *req;
+
+ DbeCheckExtension (dpy, info, (Status)0 /* failure */);
+
+ LockDisplay (dpy);
+ DbeGetReq (DbeDeallocateBackBufferName, req, info);
+ req->buffer = buffer;
+ UnlockDisplay (dpy);
+ SyncHandle ();
+
+ return (Status)1; /* success */
+}
+
+
+/*
+ * XdbeSwapBuffers -
+ * This function swaps the front and back buffers for a list of windows.
+ * The argument num_windows specifies how many windows are to have their
+ * buffers swapped; it is the number of elements in the swap_info array.
+ * The argument swap_info specifies the information needed per window
+ * to do the swap.
+ */
+Status XdbeSwapBuffers (
+ Display *dpy,
+ XdbeSwapInfo *swap_info,
+ int num_windows)
+{
+ XExtDisplayInfo *info = find_display (dpy);
+ register xDbeSwapBuffersReq *req;
+ int i;
+
+ DbeCheckExtension (dpy, info, (Status)0 /* failure */);
+
+ LockDisplay (dpy);
+ DbeGetReq (DbeSwapBuffers, req, info);
+ req->length += 2*num_windows;
+ req->n = num_windows;
+
+ /* We need to handle 64-bit machines, where we can not use PackData32
+ * directly because info would be lost in translating from 32- to 64-bit.
+ * Instead we send data via a loop that accounts for the translation.
+ */
+ for (i = 0; i < num_windows; i++)
+ {
+ char tmp[4];
+ Data32 (dpy, (long *)&swap_info[i].swap_window, 4);
+ tmp[0] = swap_info[i].swap_action;
+ Data (dpy, (char *)tmp, 4);
+ }
+
+ UnlockDisplay (dpy);
+ SyncHandle ();
+
+
+ return (Status)1; /* success */
+
+} /* XdbeSwapBuffers() */
+
+
+/*
+ * XdbeBeginIdiom -
+ * This function marks the beginning of an idiom sequence.
+ */
+Status XdbeBeginIdiom (Display *dpy)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ register xDbeBeginIdiomReq *req;
+
+ DbeCheckExtension (dpy, info, (Status)0 /* failure */);
+
+ LockDisplay (dpy);
+ DbeGetReq (DbeBeginIdiom, req, info);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+
+ return (Status)1; /* success */
+}
+
+
+/*
+ * XdbeEndIdiom -
+ * This function marks the end of an idiom sequence.
+ */
+Status XdbeEndIdiom (Display *dpy)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ register xDbeEndIdiomReq *req;
+
+ DbeCheckExtension (dpy, info, (Status)0 /* failure */);
+
+ LockDisplay (dpy);
+ DbeGetReq (DbeEndIdiom, req, info);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+
+ return (Status)1; /* success */
+}
+
+
+/*
+ * XdbeGetVisualInfo -
+ * This function returns information about which visuals support
+ * double buffering. The argument num_screens specifies how many
+ * elements there are in the screen_specifiers list. Each drawable
+ * in screen_specifiers designates a screen for which the supported
+ * visuals are being requested. If num_screens is zero, information
+ * for all screens is requested. In this case, upon return from this
+ * function, num_screens will be set to the number of screens that were
+ * found. If an error occurs, this function returns NULL, else it returns
+ * a pointer to a list of XdbeScreenVisualInfo structures of length
+ * num_screens. The nth element in the returned list corresponds to the
+ * nth drawable in the screen_specifiers list, unless num_screens was
+ * passed in with the value zero, in which case the nth element in the
+ * returned list corresponds to the nth screen of the server, starting
+ * with screen zero.
+ */
+XdbeScreenVisualInfo *XdbeGetVisualInfo (
+ Display *dpy,
+ Drawable *screen_specifiers,
+ int *num_screens) /* SEND and RETURN */
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ register xDbeGetVisualInfoReq *req;
+ xDbeGetVisualInfoReply rep;
+ XdbeScreenVisualInfo *scrVisInfo;
+ int i;
+
+ DbeCheckExtension (dpy, info, (XdbeScreenVisualInfo *)NULL);
+
+ LockDisplay (dpy);
+
+ DbeGetReq(DbeGetVisualInfo, req, info);
+ req->length = 2 + *num_screens;
+ req->n = *num_screens;
+ Data32 (dpy, screen_specifiers, (*num_screens * sizeof (CARD32)));
+
+ if (!_XReply (dpy, (xReply *) &rep, 0, xFalse)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
+ /* return the number of screens actually found if we
+ * requested information about all screens (*num_screens == 0)
+ */
+ if (*num_screens == 0)
+ *num_screens = rep.m;
+
+ /* allocate list of visual information to be returned */
+ if (!(scrVisInfo =
+ (XdbeScreenVisualInfo *)Xmalloc(
+ (unsigned)(*num_screens * sizeof(XdbeScreenVisualInfo))))) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
+ for (i = 0; i < *num_screens; i++)
+ {
+ int nbytes;
+ int j;
+ long c;
+
+ _XRead32 (dpy, &c, sizeof(CARD32));
+ scrVisInfo[i].count = c;
+
+ nbytes = scrVisInfo[i].count * sizeof(XdbeVisualInfo);
+
+ /* if we can not allocate the list of visual/depth info
+ * then free the lists that we already allocate as well
+ * as the visual info list itself
+ */
+ if (!(scrVisInfo[i].visinfo = (XdbeVisualInfo *)Xmalloc(
+ (unsigned)nbytes))) {
+ for (j = 0; j < i; j++) {
+ Xfree ((char *)scrVisInfo[j].visinfo);
+ }
+ Xfree ((char *)scrVisInfo);
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+
+ /* Read the visual info item into the wire structure. Then copy each
+ * element into the library structure. The element sizes and/or
+ * padding may be different in the two structures.
+ */
+ for (j = 0; j < scrVisInfo[i].count; j++) {
+ xDbeVisInfo xvi;
+
+ _XRead (dpy, (char *)&xvi, sizeof(xDbeVisInfo));
+ scrVisInfo[i].visinfo[j].visual = xvi.visualID;
+ scrVisInfo[i].visinfo[j].depth = xvi.depth;
+ scrVisInfo[i].visinfo[j].perflevel = xvi.perfLevel;
+ }
+
+ }
+
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return scrVisInfo;
+
+} /* XdbeGetVisualInfo() */
+
+
+/*
+ * XdbeFreeVisualInfo -
+ * This function frees the list of XdbeScreenVisualInfo returned by the
+ * function XdbeGetVisualInfo.
+ */
+void XdbeFreeVisualInfo(XdbeScreenVisualInfo *visual_info)
+{
+ if (visual_info == NULL) {
+ return;
+ }
+
+ if (visual_info->visinfo) {
+ XFree(visual_info->visinfo);
+ }
+
+ XFree(visual_info);
+}
+
+
+/*
+ * XdbeGetBackBufferAttributes -
+ * This function returns the attributes associated with the specified
+ * buffer.
+ */
+XdbeBackBufferAttributes *XdbeGetBackBufferAttributes(
+ Display *dpy,
+ XdbeBackBuffer buffer)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ register xDbeGetBackBufferAttributesReq *req;
+ xDbeGetBackBufferAttributesReply rep;
+ XdbeBackBufferAttributes *attr;
+
+ DbeCheckExtension(dpy, info, (XdbeBackBufferAttributes *)NULL);
+
+ if (!(attr =
+ (XdbeBackBufferAttributes *)Xmalloc(sizeof(XdbeBackBufferAttributes)))) {
+ return NULL;
+ }
+
+ LockDisplay(dpy);
+ DbeGetReq(DbeGetBackBufferAttributes, req, info);
+ req->buffer = buffer;
+
+ if (!_XReply (dpy, (xReply *) &rep, 0, xTrue)) {
+ UnlockDisplay (dpy);
+ SyncHandle ();
+ return NULL;
+ }
+ attr->window = rep.attributes;
+
+ UnlockDisplay (dpy);
+ SyncHandle ();
+
+ return attr;
+}
+
diff --git a/nx-X11/lib/Xext/Xext-def.cpp b/nx-X11/lib/Xext/Xext-def.cpp
new file mode 100644
index 000000000..fcd9f49a2
--- /dev/null
+++ b/nx-X11/lib/Xext/Xext-def.cpp
@@ -0,0 +1,140 @@
+LIBRARY XEXT
+VERSION LIBRARY_VERSION
+EXPORTS
+ XMITMiscGetBugMode
+ XMITMiscQueryExtension
+ XMITMiscSetBugMode
+ XMissingExtension
+ XSetExtensionErrorHandler
+ XShapeCombineMask
+ XShapeCombineRectangles
+ XShapeCombineRegion
+ XShapeCombineShape
+ XShapeGetRectangles
+ XShapeInputSelected
+ XShapeOffsetShape
+ XShapeQueryExtension
+ XShapeQueryExtents
+ XShapeQueryVersion
+ XShapeSelectInput
+#if (defined(__CYGWIN__) && defined(HAS_SHM)) || defined(__UNIXOS2__)
+ XShmAttach
+ XShmCreateImage
+ XShmCreatePixmap
+ XShmDetach
+;XShmDestroyImage
+ XShmGetEventBase
+ XShmGetImage
+ XShmPixmapFormat
+ XShmPutImage
+ XShmQueryExtension
+ XShmQueryVersion
+#endif
+ XSyncAwait
+ XSyncChangeAlarm
+ XSyncChangeCounter
+ XSyncCreateAlarm
+ XSyncCreateCounter
+ XSyncDestroyAlarm
+ XSyncDestroyCounter
+ XSyncFreeSystemCounterList
+ XSyncGetPriority
+ XSyncInitialize
+ XSyncIntToValue
+ XSyncIntsToValue
+ XSyncListSystemCounters
+ XSyncMaxValue
+ XSyncMinValue
+ XSyncQueryAlarm
+ XSyncQueryCounter
+ XSyncQueryExtension
+ XSyncSetCounter
+ XSyncSetPriority
+ XSyncValueAdd
+ XSyncValueEqual
+ XSyncValueGreaterOrEqual
+ XSyncValueGreaterThan
+ XSyncValueHigh32
+ XSyncValueIsNegative
+ XSyncValueIsPositive
+ XSyncValueIsZero
+ XSyncValueLessOrEqual
+ XSyncValueLessThan
+ XSyncValueLow32
+ XSyncValueSubtract
+ XTestFakeInput
+ XTestFlush
+ XTestGetInput
+ XTestMovePointer
+ XTestPressButton
+ XTestPressKey
+ XTestQueryInputSize
+ XTestReset
+ XTestStopInput
+ XextAddDisplay
+ XextCreateExtension
+ XextDestroyExtension
+ XextFindDisplay
+ XextRemoveDisplay
+ XmbufChangeBufferAttributes
+ XmbufChangeWindowAttributes
+ XmbufClearBufferArea
+ XmbufCreateBuffers
+ XmbufCreateStereoWindow
+ XmbufDestroyBuffers
+ XmbufDisplayBuffers
+ XmbufGetBufferAttributes
+ XmbufGetScreenInfo
+ XmbufGetVersion
+ XmbufGetWindowAttributes
+ XmbufQueryExtension
+ XdbeQueryExtension
+ XdbeAllocateBackBufferName
+ XdbeDeallocateBackBufferName
+ XdbeSwapBuffers
+ XdbeBeginIdiom
+ XdbeEndIdiom
+ XdbeGetVisualInfo
+ XdbeFreeVisualInfo
+ XdbeGetBackBufferAttributes
+ XSecurityQueryExtension
+ XSecurityAllocXauth
+ XSecurityFreeXauth
+ XSecurityGenerateAuthorization
+ XSecurityRevokeAuthorization
+ XagQueryVersion
+ XagCreateAssociation
+ XagCreateEmbeddedApplicationGroup
+ XagCreateNonembeddedApplicationGroup
+ XagDestroyApplicationGroup
+ XagDestroyAssociation
+ XagGetApplicationGroupAttributes
+ XagQueryApplicationGroup
+ XLbxQueryExtension
+ XLbxGetEventBase
+ XLbxQueryVersion
+ XcupGetReservedColormapEntries
+ XcupQueryVersion
+ XcupStoreColors
+#if !defined(__CYGWIN__) && !defined(__UNIXOS2__)
+ XPanoramiXQueryVersion
+ XPanoramiXAllocInfo
+ XPanoramiXGetScreenCount
+ XPanoramiXGetScreenSize
+ XPanoramiXGetState
+ XPanoramiXQueryExtension
+#endif
+ DPMSQueryExtension
+ DPMSGetVersion
+ DPMSCapable
+ DPMSSetTimeouts
+ DPMSGetTimeouts
+ DPMSEnable
+ DPMSDisable
+ DPMSForceLevel
+ DPMSInfo
+ XeviQueryExtension
+ XeviQueryVersion
+ XeviGetVisualInfo
+/* $Xorg: Xext-def.cpp,v 1.3 2000/08/17 19:45:53 cpqbld Exp $ */
+/* $XFree86: xc/lib/Xext/Xext-def.cpp,v 1.8 2001/05/06 10:35:51 alanh Exp $ */
diff --git a/nx-X11/lib/Xext/extutil.c b/nx-X11/lib/Xext/extutil.c
new file mode 100644
index 000000000..d96b17f3f
--- /dev/null
+++ b/nx-X11/lib/Xext/extutil.c
@@ -0,0 +1,273 @@
+/*
+ * $Xorg: extutil.c,v 1.4 2001/02/09 02:03:49 xorgcvs Exp $
+ *
+Copyright 1989, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
+AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall not be
+used in advertising or otherwise to promote the sale, use or other dealings
+in this Software without prior written authorization from The Open Group.
+ *
+ * Author: Jim Fulton, MIT X Consortium
+ *
+ *
+ * Xlib Extension-Writing Utilities
+ *
+ * This package contains utilities for writing the client API for various
+ * protocol extensions. THESE INTERFACES ARE NOT PART OF THE X STANDARD AND
+ * ARE SUBJECT TO CHANGE!
+ *
+ * Routines include:
+ *
+ * XextCreateExtension called once per extension
+ * XextDestroyExtension if no longer using extension
+ * XextAddDisplay add another display
+ * XextRemoveDisplay remove a display
+ * XextFindDisplay is a display open
+ *
+ * In addition, the following Xlib-style interfaces are provided:
+ *
+ * XSetExtensionErrorHandler establish an extension error handler
+ * XMissingExtension raise an error about missing ext
+ */
+/* $XFree86: xc/lib/Xext/extutil.c,v 1.5 2002/10/16 00:37:27 dawes Exp $ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xlibint.h>
+#include <X11/extensions/Xext.h>
+#include <X11/extensions/extutil.h>
+
+
+/*
+ * XextCreateExtension - return an extension descriptor containing context
+ * information for this extension. This object is passed to all Xext
+ * routines.
+ */
+XExtensionInfo *XextCreateExtension (void)
+{
+ register XExtensionInfo *info =
+ (XExtensionInfo *) Xmalloc (sizeof (XExtensionInfo));
+
+ if (info) {
+ info->head = NULL;
+ info->cur = NULL;
+ info->ndisplays = 0;
+ }
+ return info;
+}
+
+
+/*
+ * XextDestroyExtension - free memory the given extension descriptor
+ */
+void XextDestroyExtension (XExtensionInfo *info)
+{
+ info->head = NULL; /* to catch refs after this */
+ info->cur = NULL;
+ info->ndisplays = 0;
+ XFree ((char *) info);
+}
+
+
+
+/*
+ * XextAddDisplay - add a display to this extension
+ */
+XExtDisplayInfo *XextAddDisplay (
+ XExtensionInfo *extinfo,
+ Display *dpy,
+ char *ext_name,
+ XExtensionHooks *hooks,
+ int nevents,
+ XPointer data)
+{
+ XExtDisplayInfo *dpyinfo;
+
+ dpyinfo = (XExtDisplayInfo *) Xmalloc (sizeof (XExtDisplayInfo));
+ if (!dpyinfo) return NULL;
+ dpyinfo->display = dpy;
+ dpyinfo->data = data;
+ dpyinfo->codes = XInitExtension (dpy, ext_name);
+
+ /*
+ * if the server has the extension, then we can initialize the
+ * appropriate function vectors
+ */
+ if (dpyinfo->codes) {
+ int i, j;
+
+ for (i = 0, j = dpyinfo->codes->first_event; i < nevents; i++, j++) {
+ XESetWireToEvent (dpy, j, hooks->wire_to_event);
+ XESetEventToWire (dpy, j, hooks->event_to_wire);
+ }
+ if (hooks->create_gc)
+ XESetCreateGC (dpy, dpyinfo->codes->extension, hooks->create_gc);
+ if (hooks->copy_gc)
+ XESetCopyGC (dpy, dpyinfo->codes->extension, hooks->copy_gc);
+ if (hooks->flush_gc)
+ XESetFlushGC (dpy, dpyinfo->codes->extension, hooks->flush_gc);
+ if (hooks->free_gc)
+ XESetFreeGC (dpy, dpyinfo->codes->extension, hooks->free_gc);
+ if (hooks->create_font)
+ XESetCreateFont (dpy, dpyinfo->codes->extension, hooks->create_font);
+ if (hooks->free_font)
+ XESetFreeFont (dpy, dpyinfo->codes->extension, hooks->free_font);
+ if (hooks->close_display)
+ XESetCloseDisplay (dpy, dpyinfo->codes->extension,
+ hooks->close_display);
+ if (hooks->error)
+ XESetError (dpy, dpyinfo->codes->extension, hooks->error);
+ if (hooks->error_string)
+ XESetErrorString (dpy, dpyinfo->codes->extension,
+ hooks->error_string);
+ } else if (hooks->close_display) {
+ /* The server doesn't have this extension.
+ * Use a private Xlib-internal extension to hang the close_display
+ * hook on so that the "cache" (extinfo->cur) is properly cleaned.
+ * (XBUG 7955)
+ */
+ XExtCodes *codes = XAddExtension(dpy);
+ if (!codes) {
+ XFree(dpyinfo);
+ return NULL;
+ }
+ XESetCloseDisplay (dpy, codes->extension, hooks->close_display);
+ }
+
+ /*
+ * now, chain it onto the list
+ */
+ _XLockMutex(_Xglobal_lock);
+ dpyinfo->next = extinfo->head;
+ extinfo->head = dpyinfo;
+ extinfo->cur = dpyinfo;
+ extinfo->ndisplays++;
+ _XUnlockMutex(_Xglobal_lock);
+ return dpyinfo;
+}
+
+
+/*
+ * XextRemoveDisplay - remove the indicated display from the extension object
+ */
+int XextRemoveDisplay (XExtensionInfo *extinfo, Display *dpy)
+{
+ XExtDisplayInfo *dpyinfo, *prev;
+
+ /*
+ * locate this display and its back link so that it can be removed
+ */
+ _XLockMutex(_Xglobal_lock);
+ prev = NULL;
+ for (dpyinfo = extinfo->head; dpyinfo; dpyinfo = dpyinfo->next) {
+ if (dpyinfo->display == dpy) break;
+ prev = dpyinfo;
+ }
+ if (!dpyinfo) {
+ _XUnlockMutex(_Xglobal_lock);
+ return 0; /* hmm, actually an error */
+ }
+
+ /*
+ * remove the display from the list; handles going to zero
+ */
+ if (prev)
+ prev->next = dpyinfo->next;
+ else
+ extinfo->head = dpyinfo->next;
+
+ extinfo->ndisplays--;
+ if (dpyinfo == extinfo->cur) extinfo->cur = NULL; /* flush cache */
+ _XUnlockMutex(_Xglobal_lock);
+
+ Xfree ((char *) dpyinfo);
+ return 1;
+}
+
+
+/*
+ * XextFindDisplay - look for a display in this extension; keeps a cache
+ * of the most-recently used for efficiency.
+ */
+XExtDisplayInfo *XextFindDisplay (XExtensionInfo *extinfo, Display *dpy)
+{
+ register XExtDisplayInfo *dpyinfo;
+
+ /*
+ * see if this was the most recently accessed display
+ */
+ if ((dpyinfo = extinfo->cur)&& dpyinfo->display == dpy) return dpyinfo;
+
+
+ /*
+ * look for display in list
+ */
+ _XLockMutex(_Xglobal_lock);
+ for (dpyinfo = extinfo->head; dpyinfo; dpyinfo = dpyinfo->next) {
+ if (dpyinfo->display == dpy) {
+ extinfo->cur = dpyinfo; /* cache most recently used */
+ _XUnlockMutex(_Xglobal_lock);
+ return dpyinfo;
+ }
+ }
+ _XUnlockMutex(_Xglobal_lock);
+
+ return NULL;
+}
+
+
+
+static int _default_exterror (Display *dpy, char *ext_name, char *reason)
+{
+ fprintf (stderr, "Xlib: extension \"%s\" %s on display \"%s\".\n",
+ ext_name, reason, DisplayString(dpy));
+ return 0;
+}
+
+
+/*
+ * XSetExtensionErrorHandler - sets the handler that gets called when a
+ * requested extension is referenced. This should eventually move into Xlib.
+ */
+
+extern int (*_XExtensionErrorFunction)();
+
+int (*XSetExtensionErrorHandler(int (*handler)(Display*, char *, char * )))()
+{
+ int (*oldhandler)() = _XExtensionErrorFunction;
+
+ _XExtensionErrorFunction = (handler ? handler :
+ _default_exterror);
+ return oldhandler;
+}
+
+
+/*
+ * XMissingExtension - call the extension error handler
+ */
+int XMissingExtension (Display *dpy, _Xconst char *ext_name)
+{
+ int (*func)() = (_XExtensionErrorFunction ?
+ _XExtensionErrorFunction : _default_exterror);
+
+ if (!ext_name) ext_name = X_EXTENSION_UNKNOWN;
+ return (*func) (dpy, ext_name, X_EXTENSION_MISSING);
+}
diff --git a/nx-X11/lib/Xext/globals.c b/nx-X11/lib/Xext/globals.c
new file mode 100644
index 000000000..0cd5d2690
--- /dev/null
+++ b/nx-X11/lib/Xext/globals.c
@@ -0,0 +1,90 @@
+/* $Xorg: globals.c,v 1.4 2001/02/09 02:03:50 xorgcvs Exp $ */
+/*
+
+Copyright 1989, 1998 The Open Group
+
+Permission to use, copy, modify, distribute, and sell this software and its
+documentation for any purpose is hereby granted without fee, provided that
+the above copyright notice appear in all copies and that both that
+copyright notice and this permission notice appear in supporting
+documentation.
+
+The above copyright notice and this permission notice shall be included
+in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
+OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
+ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+OTHER DEALINGS IN THE SOFTWARE.
+
+Except as contained in this notice, the name of The Open Group shall
+not be used in advertising or otherwise to promote the sale, use or
+other dealings in this Software without prior written authorization
+from The Open Group.
+
+*/
+/* $XFree86: xc/lib/Xext/globals.c,v 3.4 2001/07/29 05:01:12 tsi Exp $ */
+
+/*
+ * This file should contain only those objects which must be predefined.
+ */
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlib.h>
+#include <X11/extensions/Xext.h>
+#include <stddef.h> /* for definition of NULL */
+
+/*
+ * If possible, it is useful to have the global data default to a null value.
+ * Some shared library implementations are *much* happier if there isn't any
+ * global initialized data.
+ */
+#ifdef NULL_NOT_ZERO /* then need to initialize */
+#define SetZero(t,var,z) t var = z
+#else
+#define SetZero(t,var,z) t var
+#endif
+
+#ifdef ATTSHAREDLIB /* then need extra variables */
+/*
+ * If we need to define extra variables for each global
+ */
+#if !defined(UNIXCPP) || defined(ANSICPP)
+#define ZEROINIT(t,var,val) SetZero(t,var,val); \
+ SetZero (long, _libX_##var##Flag, 0); \
+ SetZero (void *, _libX_##var##Ptr, NULL)
+#else /* else pcc concatenation */
+#define ZEROINIT(t,var,val) SetZero(t,var,val); \
+ SetZero (long, _libX_/**/var/**/Flag, 0); \
+ SetZero (void *, _libX_/**/var/**/Ptr, NULL)
+#endif /* concat ANSI C vs. pcc */
+
+#else /* else not ATTSHAREDLIB */
+/*
+ * no extra crud
+ */
+#define ZEROINIT(t,var,val) SetZero (t, var, val)
+
+#endif /* ATTSHAREDLIB */
+
+
+/*
+ * Error handlers; used to be in XlibInt.c
+ */
+typedef int (*funcptr)();
+ZEROINIT (funcptr, _XExtensionErrorFunction, NULL);
+
+/*
+ * NOTE: any additional external definition NEED
+ * to be inserted BELOW this point!!!
+ */
+
+/*
+ * NOTE: any additional external definition NEED
+ * to be inserted ABOVE this point!!!
+ */
+