aboutsummaryrefslogtreecommitdiff
path: root/libXext/src
diff options
context:
space:
mode:
authormarha <marha@users.sourceforge.net>2011-09-19 13:39:03 +0200
committermarha <marha@users.sourceforge.net>2011-09-19 13:39:03 +0200
commit1678a69116d1c6ce900fe15f7813613bb28416dd (patch)
tree9589536f6b4bd60b34f90cf5ed20240d40bbb38c /libXext/src
parent9d911bc1246139019e555f443e934677a067bc0a (diff)
parentb2c925e360e2c366526de15b44603f855f94139c (diff)
downloadvcxsrv-1678a69116d1c6ce900fe15f7813613bb28416dd.tar.gz
vcxsrv-1678a69116d1c6ce900fe15f7813613bb28416dd.tar.bz2
vcxsrv-1678a69116d1c6ce900fe15f7813613bb28416dd.zip
Merge remote-tracking branch 'origin/released'
Conflicts: libfontenc/src/fontenc.c
Diffstat (limited to 'libXext/src')
-rw-r--r--libXext/src/DPMS.c580
-rw-r--r--libXext/src/MITMisc.c260
-rw-r--r--libXext/src/Makefile.am130
-rw-r--r--libXext/src/XAppgroup.c776
-rw-r--r--libXext/src/XLbx.c248
-rw-r--r--libXext/src/XMultibuf.c1422
-rw-r--r--libXext/src/XShape.c976
-rw-r--r--libXext/src/XShm.c2
-rw-r--r--libXext/src/XSync.c1998
-rw-r--r--libXext/src/XTestExt1.c2634
-rw-r--r--libXext/src/Xcup.c524
-rw-r--r--libXext/src/Xdbe.c936
-rw-r--r--libXext/src/extutil.c560
-rw-r--r--libXext/src/globals.c174
14 files changed, 5610 insertions, 5610 deletions
diff --git a/libXext/src/DPMS.c b/libXext/src/DPMS.c
index c6d0adac6..07818a07e 100644
--- a/libXext/src/DPMS.c
+++ b/libXext/src/DPMS.c
@@ -1,290 +1,290 @@
-/*****************************************************************
-
-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.
-
-******************************************************************/
-
-/*
- * HISTORY
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xlibint.h>
-#include <X11/extensions/dpms.h>
-#include <X11/extensions/dpmsproto.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;
-}
-
-
-
+/*****************************************************************
+
+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.
+
+******************************************************************/
+
+/*
+ * HISTORY
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <X11/extensions/dpms.h>
+#include <X11/extensions/dpmsproto.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/libXext/src/MITMisc.c b/libXext/src/MITMisc.c
index 20d1157cb..bc452dba7 100644
--- a/libXext/src/MITMisc.c
+++ b/libXext/src/MITMisc.c
@@ -1,130 +1,130 @@
-/*
- *
-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.
- *
- */
-
-/* RANDOM CRUFT! THIS HAS NO OFFICIAL X CONSORTIUM BLESSING */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <X11/Xlibint.h>
-#include <X11/extensions/MITMisc.h>
-#include <X11/extensions/mitmiscproto.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;
-}
+/*
+ *
+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.
+ *
+ */
+
+/* RANDOM CRUFT! THIS HAS NO OFFICIAL X CONSORTIUM BLESSING */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <X11/Xlibint.h>
+#include <X11/extensions/MITMisc.h>
+#include <X11/extensions/mitmiscproto.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/libXext/src/Makefile.am b/libXext/src/Makefile.am
index 62a766263..e236c3345 100644
--- a/libXext/src/Makefile.am
+++ b/libXext/src/Makefile.am
@@ -1,65 +1,65 @@
-lib_LTLIBRARIES=libXext.la
-
-AM_CPPFLAGS=\
- -I$(top_srcdir)/include \
- -I$(top_srcdir)/include/X11/extensions\
- $(XEXT_CFLAGS) $(MALLOC_ZERO_CFLAGS)
-
-AM_CFLAGS=$(CWARNFLAGS)
-
-libXext_la_LDFLAGS = -version-number $(XEXT_SOREV) -no-undefined
-
-libXext_la_LIBADD = $(XEXT_LIBS)
-
-libXext_la_SOURCES = \
- DPMS.c \
- MITMisc.c \
- XAppgroup.c \
- XEVI.c \
- XLbx.c \
- XMultibuf.c \
- XSecurity.c \
- XShape.c \
- XShm.c \
- XSync.c \
- XTestExt1.c \
- Xcup.c \
- Xdbe.c \
- Xge.c \
- extutil.c \
- globals.c
-
-libXextincludedir = $(includedir)/X11/extensions
-libXextinclude_HEADERS = $(top_srcdir)/include/X11/extensions/dpms.h \
- $(top_srcdir)/include/X11/extensions/extutil.h \
- $(top_srcdir)/include/X11/extensions/MITMisc.h \
- $(top_srcdir)/include/X11/extensions/multibuf.h \
- $(top_srcdir)/include/X11/extensions/security.h \
- $(top_srcdir)/include/X11/extensions/shape.h \
- $(top_srcdir)/include/X11/extensions/sync.h \
- $(top_srcdir)/include/X11/extensions/Xag.h \
- $(top_srcdir)/include/X11/extensions/Xcup.h \
- $(top_srcdir)/include/X11/extensions/Xdbe.h \
- $(top_srcdir)/include/X11/extensions/XEVI.h \
- $(top_srcdir)/include/X11/extensions/Xext.h \
- $(top_srcdir)/include/X11/extensions/Xge.h \
- $(top_srcdir)/include/X11/extensions/XLbx.h \
- $(top_srcdir)/include/X11/extensions/XShm.h \
- $(top_srcdir)/include/X11/extensions/xtestext1.h
-
-if LINT
-ALL_LINT_FLAGS=$(LINT_FLAGS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
- $(AM_CPPFLAGS) $(CPPFLAGS)
-
-lint:
- $(LINT) $(ALL_LINT_FLAGS) $(libXext_la_SOURCES) $(XEXT_LIBS)
-endif LINT
-
-if MAKE_LINT_LIB
-lintlibdir = $(libdir)
-
-lintlib_DATA = $(LINTLIB)
-
-$(LINTLIB): $(libXext_la_SOURCES)
- $(LINT) -y -oXext -x $(ALL_LINT_FLAGS) $(libXext_la_SOURCES)
-endif MAKE_LINT_LIB
+lib_LTLIBRARIES=libXext.la
+
+AM_CPPFLAGS=\
+ -I$(top_srcdir)/include \
+ -I$(top_srcdir)/include/X11/extensions\
+ $(XEXT_CFLAGS) $(MALLOC_ZERO_CFLAGS)
+
+AM_CFLAGS=$(CWARNFLAGS)
+
+libXext_la_LDFLAGS = -version-number $(XEXT_SOREV) -no-undefined
+
+libXext_la_LIBADD = $(XEXT_LIBS)
+
+libXext_la_SOURCES = \
+ DPMS.c \
+ MITMisc.c \
+ XAppgroup.c \
+ XEVI.c \
+ XLbx.c \
+ XMultibuf.c \
+ XSecurity.c \
+ XShape.c \
+ XShm.c \
+ XSync.c \
+ XTestExt1.c \
+ Xcup.c \
+ Xdbe.c \
+ Xge.c \
+ extutil.c \
+ globals.c
+
+libXextincludedir = $(includedir)/X11/extensions
+libXextinclude_HEADERS = $(top_srcdir)/include/X11/extensions/dpms.h \
+ $(top_srcdir)/include/X11/extensions/extutil.h \
+ $(top_srcdir)/include/X11/extensions/MITMisc.h \
+ $(top_srcdir)/include/X11/extensions/multibuf.h \
+ $(top_srcdir)/include/X11/extensions/security.h \
+ $(top_srcdir)/include/X11/extensions/shape.h \
+ $(top_srcdir)/include/X11/extensions/sync.h \
+ $(top_srcdir)/include/X11/extensions/Xag.h \
+ $(top_srcdir)/include/X11/extensions/Xcup.h \
+ $(top_srcdir)/include/X11/extensions/Xdbe.h \
+ $(top_srcdir)/include/X11/extensions/XEVI.h \
+ $(top_srcdir)/include/X11/extensions/Xext.h \
+ $(top_srcdir)/include/X11/extensions/Xge.h \
+ $(top_srcdir)/include/X11/extensions/XLbx.h \
+ $(top_srcdir)/include/X11/extensions/XShm.h \
+ $(top_srcdir)/include/X11/extensions/xtestext1.h
+
+if LINT
+ALL_LINT_FLAGS=$(LINT_FLAGS) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) \
+ $(AM_CPPFLAGS) $(CPPFLAGS)
+
+lint:
+ $(LINT) $(ALL_LINT_FLAGS) $(libXext_la_SOURCES) $(XEXT_LIBS)
+endif LINT
+
+if MAKE_LINT_LIB
+lintlibdir = $(libdir)
+
+lintlib_DATA = $(LINTLIB)
+
+$(LINTLIB): $(libXext_la_SOURCES)
+ $(LINT) -y -oXext -x $(ALL_LINT_FLAGS) $(libXext_la_SOURCES)
+endif MAKE_LINT_LIB
diff --git a/libXext/src/XAppgroup.c b/libXext/src/XAppgroup.c
index 2d3edf35f..16650b6a9 100644
--- a/libXext/src/XAppgroup.c
+++ b/libXext/src/XAppgroup.c
@@ -1,388 +1,388 @@
-/*
-
-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.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#ifdef WIN32
-#include <X11/Xwindows.h>
-#endif
-
-#include <X11/Xlibint.h>
-#include <X11/extensions/Xag.h>
-#include <X11/extensions/agproto.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;
-}
-
+/*
+
+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.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#ifdef WIN32
+#include <X11/Xwindows.h>
+#endif
+
+#include <X11/Xlibint.h>
+#include <X11/extensions/Xag.h>
+#include <X11/extensions/agproto.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/libXext/src/XLbx.c b/libXext/src/XLbx.c
index 0b7eb5827..b3ba1b2ea 100644
--- a/libXext/src/XLbx.c
+++ b/libXext/src/XLbx.c
@@ -1,124 +1,124 @@
-/*
- * 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
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include <X11/Xlibint.h>
-#include <X11/extensions/XLbx.h>
-#include <X11/extensions/lbxproto.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 ... */
+/*
+ * 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
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xlibint.h>
+#include <X11/extensions/XLbx.h>
+#include <X11/extensions/lbxproto.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/libXext/src/XMultibuf.c b/libXext/src/XMultibuf.c
index 67551443d..fb995f840 100644
--- a/libXext/src/XMultibuf.c
+++ b/libXext/src/XMultibuf.c
@@ -1,711 +1,711 @@
-/*
- *
-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
- */
-
-#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/multibufproto.h>
-#include <X11/extensions/multibuf.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 Match
- * 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 == (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();
-}
-
+/*
+ *
+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
+ */
+
+#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/multibufproto.h>
+#include <X11/extensions/multibuf.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 Match
+ * 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 == (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/libXext/src/XShape.c b/libXext/src/XShape.c
index f189a41b9..1e3a77f23 100644
--- a/libXext/src/XShape.c
+++ b/libXext/src/XShape.c
@@ -1,488 +1,488 @@
-/*
- *
-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
- */
-
-#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/shape.h>
-#include <X11/extensions/shapeproto.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 = NULL;
- 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 = NULL;
- *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;
-}
+/*
+ *
+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
+ */
+
+#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/shape.h>
+#include <X11/extensions/shapeproto.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 = NULL;
+ 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 = NULL;
+ *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/libXext/src/XShm.c b/libXext/src/XShm.c
index d1f1a4d7f..e3f8fa09b 100644
--- a/libXext/src/XShm.c
+++ b/libXext/src/XShm.c
@@ -74,7 +74,7 @@ static /* const */ char *shm_error_list[] = {
"BadShmSeg", /* BadShmSeg */
};
-static XEXT_GENERATE_FIND_DISPLAY (find_display, shm_info, shm_extension_name,
+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)
diff --git a/libXext/src/XSync.c b/libXext/src/XSync.c
index 9fdb47e2f..0e19922dd 100644
--- a/libXext/src/XSync.c
+++ b/libXext/src/XSync.c
@@ -1,999 +1,999 @@
-/*
-
-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.
-
-******************************************************************/
-
-#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>
-#include <X11/extensions/sync.h>
-#include <X11/extensions/syncproto.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",
- "BadFence",
-};
-
-typedef struct _SyncVersionInfoRec {
- short major;
- short minor;
- int num_errors;
-} SyncVersionInfo;
-
-static /* const */ SyncVersionInfo supported_versions[] = {
- { 3 /* major */, 0 /* minor */, 2 /* num_errors */ },
- { 3 /* major */, 1 /* minor */, 3 /* num_errors */ },
-};
-
-#define NUM_VERSIONS (sizeof(supported_versions)/sizeof(supported_versions[0]))
-#define GET_VERSION(info) ((info) ? (const SyncVersionInfo*)(info)->data : NULL)
-#define IS_VERSION_SUPPORTED(info) (!!GET_VERSION(info))
-
-static
-const SyncVersionInfo* GetVersionInfo(Display *dpy)
-{
- xSyncInitializeReply rep;
- xSyncInitializeReq *req;
- XExtCodes codes;
- int i;
-
- if (!XQueryExtension(dpy, sync_extension_name,
- &codes.major_opcode,
- &codes.first_event,
- &codes.first_error))
- return NULL;
-
- LockDisplay(dpy);
- GetReq(SyncInitialize, req);
- req->reqType = 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 NULL;
- }
- UnlockDisplay(dpy);
- SyncHandle();
-
- for (i = 0; i < NUM_VERSIONS; i++) {
- if (supported_versions[i].major == rep.majorVersion &&
- supported_versions[i].minor == rep.minorVersion) {
- return &supported_versions[i];
- }
- }
-
- return NULL;
-}
-
-static
-XExtDisplayInfo *find_display_create_optional(Display *dpy, Bool create)
-{
- XExtDisplayInfo *dpyinfo;
-
- if (!sync_info) {
- if (!(sync_info = XextCreateExtension())) return NULL;
- }
-
- if (!(dpyinfo = XextFindDisplay (sync_info, dpy)) && create) {
- dpyinfo = XextAddDisplay(sync_info, dpy,
- sync_extension_name,
- &sync_extension_hooks,
- XSyncNumberEvents,
- (XPointer)GetVersionInfo(dpy));
- }
-
- return dpyinfo;
-}
-
-static
-XExtDisplayInfo *find_display (Display *dpy)
-{
- return find_display_create_optional(dpy, True);
-}
-
-static
-XEXT_GENERATE_CLOSE_DISPLAY(close_display, sync_info)
-
-static
-char *error_string(Display *dpy, int code, XExtCodes *codes, char *buf, int n)
-{
- XExtDisplayInfo *info = find_display_create_optional(dpy, False);
- int nerr = IS_VERSION_SUPPORTED(info) ? GET_VERSION(info)->num_errors : 0;
-
- code -= codes->first_error;
- if (code >= 0 && code < nerr) {
- char tmp[256];
- sprintf (tmp, "%s.%d", sync_extension_name, code);
- XGetErrorDatabaseText (dpy, "XProtoError", tmp, sync_error_list[code], buf, n);
- return buf;
- }
- return (char *)0;
-}
-
-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);
-
- SyncCheckExtension(dpy, info, False);
-
- if (IS_VERSION_SUPPORTED(info)) {
- *major_version_return = GET_VERSION(info)->major;
- *minor_version_return = GET_VERSION(info)->minor;
-
- return True;
- } else {
- return False;
- }
-}
-
-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 = Xmalloc(rep.nCounters * sizeof(XSyncSystemCounter));
- replylen = rep.length << 2;
- pWireSysCounter = Xmalloc ((unsigned) replylen + sizeof(XSyncCounter));
- /* +1 to leave room for last counter read-ahead */
-
- 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;
-}
-
-XSyncFence
-XSyncCreateFence(Display *dpy, Drawable d, Bool initially_triggered)
-{
- XExtDisplayInfo *info = find_display(dpy);
- xSyncCreateFenceReq *req;
- XSyncFence id;
-
- SyncCheckExtension(dpy, info, None);
-
- LockDisplay(dpy);
- GetReq(SyncCreateFence, req);
- req->reqType = info->codes->major_opcode;
- req->syncReqType = X_SyncCreateFence;
-
- req->d = d;
- id = req->fid = XAllocID(dpy);
- req->initially_triggered = initially_triggered;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return id;
-}
-
-Bool
-XSyncTriggerFence(Display *dpy, XSyncFence fence)
-{
- XExtDisplayInfo *info = find_display(dpy);
- xSyncTriggerFenceReq *req;
-
- SyncCheckExtension(dpy, info, None);
-
- LockDisplay(dpy);
- GetReq(SyncTriggerFence, req);
- req->reqType = info->codes->major_opcode;
- req->syncReqType = X_SyncTriggerFence;
-
- req->fid = fence;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XSyncResetFence(Display *dpy, XSyncFence fence)
-{
- XExtDisplayInfo *info = find_display(dpy);
- xSyncResetFenceReq *req;
-
- SyncCheckExtension(dpy, info, None);
-
- LockDisplay(dpy);
- GetReq(SyncResetFence, req);
- req->reqType = info->codes->major_opcode;
- req->syncReqType = X_SyncResetFence;
-
- req->fid = fence;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XSyncDestroyFence(Display *dpy, XSyncFence fence)
-{
- XExtDisplayInfo *info = find_display(dpy);
- xSyncDestroyFenceReq *req;
-
- SyncCheckExtension(dpy, info, None);
-
- LockDisplay(dpy);
- GetReq(SyncDestroyFence, req);
- req->reqType = info->codes->major_opcode;
- req->syncReqType = X_SyncDestroyFence;
-
- req->fid = fence;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XSyncQueryFence(Display *dpy, XSyncFence fence, Bool *triggered)
-{
- XExtDisplayInfo *info = find_display(dpy);
- xSyncQueryFenceReply rep;
- xSyncQueryFenceReq *req;
-
- SyncCheckExtension(dpy, info, None);
-
- LockDisplay(dpy);
- GetReq(SyncQueryFence, req);
- req->reqType = info->codes->major_opcode;
- req->syncReqType = X_SyncQueryFence;
- req->fid = fence;
-
- if (!_XReply(dpy, (xReply *) & rep, 0, xFalse))
- {
- UnlockDisplay(dpy);
- SyncHandle();
- return False;
- }
- if (triggered)
- *triggered = rep.triggered;
-
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-Bool
-XSyncAwaitFence(Display *dpy, const XSyncFence *fence_list, int n_fences)
-{
- XExtDisplayInfo *info = find_display(dpy);
- xSyncAwaitFenceReq *req;
-
- SyncCheckExtension(dpy, info, False);
-
- LockDisplay(dpy);
- GetReq(SyncAwaitFence, req);
- req->reqType = info->codes->major_opcode;
- req->syncReqType = X_SyncAwaitFence;
- SetReqLen(req, n_fences, n_fences);
-
- Data32(dpy, (char *)fence_list, sizeof(CARD32) * n_fences);
-
- UnlockDisplay(dpy);
- SyncHandle();
- return True;
-}
-
-/*
- * Functions corresponding to the macros for manipulating 64-bit values
- */
-
-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);
-}
+/*
+
+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.
+
+******************************************************************/
+
+#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>
+#include <X11/extensions/sync.h>
+#include <X11/extensions/syncproto.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",
+ "BadFence",
+};
+
+typedef struct _SyncVersionInfoRec {
+ short major;
+ short minor;
+ int num_errors;
+} SyncVersionInfo;
+
+static /* const */ SyncVersionInfo supported_versions[] = {
+ { 3 /* major */, 0 /* minor */, 2 /* num_errors */ },
+ { 3 /* major */, 1 /* minor */, 3 /* num_errors */ },
+};
+
+#define NUM_VERSIONS (sizeof(supported_versions)/sizeof(supported_versions[0]))
+#define GET_VERSION(info) ((info) ? (const SyncVersionInfo*)(info)->data : NULL)
+#define IS_VERSION_SUPPORTED(info) (!!GET_VERSION(info))
+
+static
+const SyncVersionInfo* GetVersionInfo(Display *dpy)
+{
+ xSyncInitializeReply rep;
+ xSyncInitializeReq *req;
+ XExtCodes codes;
+ int i;
+
+ if (!XQueryExtension(dpy, sync_extension_name,
+ &codes.major_opcode,
+ &codes.first_event,
+ &codes.first_error))
+ return NULL;
+
+ LockDisplay(dpy);
+ GetReq(SyncInitialize, req);
+ req->reqType = 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 NULL;
+ }
+ UnlockDisplay(dpy);
+ SyncHandle();
+
+ for (i = 0; i < NUM_VERSIONS; i++) {
+ if (supported_versions[i].major == rep.majorVersion &&
+ supported_versions[i].minor == rep.minorVersion) {
+ return &supported_versions[i];
+ }
+ }
+
+ return NULL;
+}
+
+static
+XExtDisplayInfo *find_display_create_optional(Display *dpy, Bool create)
+{
+ XExtDisplayInfo *dpyinfo;
+
+ if (!sync_info) {
+ if (!(sync_info = XextCreateExtension())) return NULL;
+ }
+
+ if (!(dpyinfo = XextFindDisplay (sync_info, dpy)) && create) {
+ dpyinfo = XextAddDisplay(sync_info, dpy,
+ sync_extension_name,
+ &sync_extension_hooks,
+ XSyncNumberEvents,
+ (XPointer)GetVersionInfo(dpy));
+ }
+
+ return dpyinfo;
+}
+
+static
+XExtDisplayInfo *find_display (Display *dpy)
+{
+ return find_display_create_optional(dpy, True);
+}
+
+static
+XEXT_GENERATE_CLOSE_DISPLAY(close_display, sync_info)
+
+static
+char *error_string(Display *dpy, int code, XExtCodes *codes, char *buf, int n)
+{
+ XExtDisplayInfo *info = find_display_create_optional(dpy, False);
+ int nerr = IS_VERSION_SUPPORTED(info) ? GET_VERSION(info)->num_errors : 0;
+
+ code -= codes->first_error;
+ if (code >= 0 && code < nerr) {
+ char tmp[256];
+ sprintf (tmp, "%s.%d", sync_extension_name, code);
+ XGetErrorDatabaseText (dpy, "XProtoError", tmp, sync_error_list[code], buf, n);
+ return buf;
+ }
+ return (char *)0;
+}
+
+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);
+
+ SyncCheckExtension(dpy, info, False);
+
+ if (IS_VERSION_SUPPORTED(info)) {
+ *major_version_return = GET_VERSION(info)->major;
+ *minor_version_return = GET_VERSION(info)->minor;
+
+ return True;
+ } else {
+ return False;
+ }
+}
+
+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 = Xmalloc(rep.nCounters * sizeof(XSyncSystemCounter));
+ replylen = rep.length << 2;
+ pWireSysCounter = Xmalloc ((unsigned) replylen + sizeof(XSyncCounter));
+ /* +1 to leave room for last counter read-ahead */
+
+ 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;
+}
+
+XSyncFence
+XSyncCreateFence(Display *dpy, Drawable d, Bool initially_triggered)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncCreateFenceReq *req;
+ XSyncFence id;
+
+ SyncCheckExtension(dpy, info, None);
+
+ LockDisplay(dpy);
+ GetReq(SyncCreateFence, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncCreateFence;
+
+ req->d = d;
+ id = req->fid = XAllocID(dpy);
+ req->initially_triggered = initially_triggered;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return id;
+}
+
+Bool
+XSyncTriggerFence(Display *dpy, XSyncFence fence)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncTriggerFenceReq *req;
+
+ SyncCheckExtension(dpy, info, None);
+
+ LockDisplay(dpy);
+ GetReq(SyncTriggerFence, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncTriggerFence;
+
+ req->fid = fence;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XSyncResetFence(Display *dpy, XSyncFence fence)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncResetFenceReq *req;
+
+ SyncCheckExtension(dpy, info, None);
+
+ LockDisplay(dpy);
+ GetReq(SyncResetFence, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncResetFence;
+
+ req->fid = fence;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XSyncDestroyFence(Display *dpy, XSyncFence fence)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncDestroyFenceReq *req;
+
+ SyncCheckExtension(dpy, info, None);
+
+ LockDisplay(dpy);
+ GetReq(SyncDestroyFence, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncDestroyFence;
+
+ req->fid = fence;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XSyncQueryFence(Display *dpy, XSyncFence fence, Bool *triggered)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncQueryFenceReply rep;
+ xSyncQueryFenceReq *req;
+
+ SyncCheckExtension(dpy, info, None);
+
+ LockDisplay(dpy);
+ GetReq(SyncQueryFence, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncQueryFence;
+ req->fid = fence;
+
+ if (!_XReply(dpy, (xReply *) & rep, 0, xFalse))
+ {
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return False;
+ }
+ if (triggered)
+ *triggered = rep.triggered;
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+Bool
+XSyncAwaitFence(Display *dpy, const XSyncFence *fence_list, int n_fences)
+{
+ XExtDisplayInfo *info = find_display(dpy);
+ xSyncAwaitFenceReq *req;
+
+ SyncCheckExtension(dpy, info, False);
+
+ LockDisplay(dpy);
+ GetReq(SyncAwaitFence, req);
+ req->reqType = info->codes->major_opcode;
+ req->syncReqType = X_SyncAwaitFence;
+ SetReqLen(req, n_fences, n_fences);
+
+ Data32(dpy, (char *)fence_list, sizeof(CARD32) * n_fences);
+
+ UnlockDisplay(dpy);
+ SyncHandle();
+ return True;
+}
+
+/*
+ * Functions corresponding to the macros for manipulating 64-bit values
+ */
+
+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/libXext/src/XTestExt1.c b/libXext/src/XTestExt1.c
index 83a59a3d8..15aa4c0f2 100644
--- a/libXext/src/XTestExt1.c
+++ b/libXext/src/XTestExt1.c
@@ -1,1317 +1,1317 @@
-/*
- * 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.
-
-*/
-
-/******************************************************************************
- * include files
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#include <stdio.h>
-#include <X11/Xproto.h>
-#include <X11/Xlibint.h>
-#include <X11/extensions/xtestext1.h>
-#include <X11/extensions/xtestext1proto.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 acquired 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 acquired 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)(Display *, XEvent *, XPointer);
-
- /*
- * 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 routine 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));
-}
+/*
+ * 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.
+
+*/
+
+/******************************************************************************
+ * include files
+ *****************************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#include <stdio.h>
+#include <X11/Xproto.h>
+#include <X11/Xlibint.h>
+#include <X11/extensions/xtestext1.h>
+#include <X11/extensions/xtestext1proto.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 acquired 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 acquired 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)(Display *, XEvent *, XPointer);
+
+ /*
+ * 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 routine 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/libXext/src/Xcup.c b/libXext/src/Xcup.c
index d050ba0b6..ad78699be 100644
--- a/libXext/src/Xcup.c
+++ b/libXext/src/Xcup.c
@@ -1,262 +1,262 @@
-/*
-
-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.
-
-*/
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-#ifdef WIN32
-#include <X11/Xwindows.h>
-#endif
-
-#include <X11/Xlibint.h>
-#include <X11/extensions/Xcup.h>
-#include <X11/extensions/cupproto.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;
-}
-
+/*
+
+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.
+
+*/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+#ifdef WIN32
+#include <X11/Xwindows.h>
+#endif
+
+#include <X11/Xlibint.h>
+#include <X11/extensions/Xcup.h>
+#include <X11/extensions/cupproto.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/libXext/src/Xdbe.c b/libXext/src/Xdbe.c
index 930b51f60..1b9e2da52 100644
--- a/libXext/src/Xdbe.c
+++ b/libXext/src/Xdbe.c
@@ -1,468 +1,468 @@
-/******************************************************************************
- *
- * 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
- *
- *****************************************************************************/
-
-#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>
-#include <X11/extensions/Xdbe.h>
-#include <X11/extensions/dbeproto.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);
-
- LockDisplay(dpy);
- DbeGetReq(DbeAllocateBackBufferName, req, info);
- req->window = window;
- req->swapAction = (unsigned char)swap_action;
- req->buffer = buffer = XAllocID (dpy);
-
- 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 ();
- Xfree(attr);
- return NULL;
- }
- attr->window = rep.attributes;
-
- UnlockDisplay (dpy);
- SyncHandle ();
-
- return attr;
-}
-
+/******************************************************************************
+ *
+ * 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
+ *
+ *****************************************************************************/
+
+#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>
+#include <X11/extensions/Xdbe.h>
+#include <X11/extensions/dbeproto.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);
+
+ LockDisplay(dpy);
+ DbeGetReq(DbeAllocateBackBufferName, req, info);
+ req->window = window;
+ req->swapAction = (unsigned char)swap_action;
+ req->buffer = buffer = XAllocID (dpy);
+
+ 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 ();
+ Xfree(attr);
+ return NULL;
+ }
+ attr->window = rep.attributes;
+
+ UnlockDisplay (dpy);
+ SyncHandle ();
+
+ return attr;
+}
+
diff --git a/libXext/src/extutil.c b/libXext/src/extutil.c
index 8813c1154..361a3274d 100644
--- a/libXext/src/extutil.c
+++ b/libXext/src/extutil.c
@@ -1,280 +1,280 @@
-/*
- *
-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
- */
-
-#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>
-#include <X11/extensions/ge.h>
-
-/* defined in Xge.c */
-extern _X_HIDDEN Bool
-xgeExtRegister(Display* dpy, int extension, XExtensionHooks* callbacks);
-
-/*
- * 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);
- }
-
- /* register extension for XGE */
- if (strcmp(ext_name, GE_NAME))
- xgeExtRegister(dpy, dpyinfo->codes->major_opcode, hooks);
-
- 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, _Xconst char *ext_name, _Xconst 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 XextErrorHandler _XExtensionErrorFunction;
-
-XextErrorHandler XSetExtensionErrorHandler (XextErrorHandler handler)
-{
- XextErrorHandler oldhandler = _XExtensionErrorFunction;
-
- _XExtensionErrorFunction = (handler ? handler :
- _default_exterror);
- return oldhandler;
-}
-
-
-/*
- * XMissingExtension - call the extension error handler
- */
-int XMissingExtension (Display *dpy, _Xconst char *ext_name)
-{
- XextErrorHandler func = (_XExtensionErrorFunction ?
- _XExtensionErrorFunction : _default_exterror);
-
- if (!ext_name) ext_name = X_EXTENSION_UNKNOWN;
- return (*func) (dpy, ext_name, X_EXTENSION_MISSING);
-}
+/*
+ *
+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
+ */
+
+#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>
+#include <X11/extensions/ge.h>
+
+/* defined in Xge.c */
+extern _X_HIDDEN Bool
+xgeExtRegister(Display* dpy, int extension, XExtensionHooks* callbacks);
+
+/*
+ * 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);
+ }
+
+ /* register extension for XGE */
+ if (strcmp(ext_name, GE_NAME))
+ xgeExtRegister(dpy, dpyinfo->codes->major_opcode, hooks);
+
+ 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, _Xconst char *ext_name, _Xconst 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 XextErrorHandler _XExtensionErrorFunction;
+
+XextErrorHandler XSetExtensionErrorHandler (XextErrorHandler handler)
+{
+ XextErrorHandler oldhandler = _XExtensionErrorFunction;
+
+ _XExtensionErrorFunction = (handler ? handler :
+ _default_exterror);
+ return oldhandler;
+}
+
+
+/*
+ * XMissingExtension - call the extension error handler
+ */
+int XMissingExtension (Display *dpy, _Xconst char *ext_name)
+{
+ XextErrorHandler func = (_XExtensionErrorFunction ?
+ _XExtensionErrorFunction : _default_exterror);
+
+ if (!ext_name) ext_name = X_EXTENSION_UNKNOWN;
+ return (*func) (dpy, ext_name, X_EXTENSION_MISSING);
+}
diff --git a/libXext/src/globals.c b/libXext/src/globals.c
index a40492abe..8b5923de6 100644
--- a/libXext/src/globals.c
+++ b/libXext/src/globals.c
@@ -1,87 +1,87 @@
-/*
-
-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.
-
-*/
-
-/*
- * 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
- */
-ZEROINIT (XextErrorHandler, _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!!!
- */
-
+/*
+
+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.
+
+*/
+
+/*
+ * 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
+ */
+ZEROINIT (XextErrorHandler, _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!!!
+ */
+