Xevie.c revision d9c7fc6c
1/* $XdotOrg: xc/lib/Xevie/Xevie.c,v 1.2 2005/05/22 01:20:14 alanc Exp $ */ 2/************************************************************ 3 4Copyright 2003 Sun Microsystems, Inc. 5 6All rights reserved. 7 8Permission is hereby granted, free of charge, to any person obtaining a 9copy of this software and associated documentation files (the 10"Software"), to deal in the Software without restriction, including 11without limitation the rights to use, copy, modify, merge, publish, 12distribute, and/or sell copies of the Software, and to permit persons 13to whom the Software is furnished to do so, provided that the above 14copyright notice(s) and this permission notice appear in all copies of 15the Software and that both the above copyright notice(s) and this 16permission notice appear in supporting documentation. 17 18THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT 21OF THIRD PARTY RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 22HOLDERS INCLUDED IN THIS NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL 23INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING 24FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, 25NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 26WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 27 28Except as contained in this notice, the name of a copyright holder 29shall not be used in advertising or otherwise to promote the sale, use 30or other dealings in this Software without prior written authorization 31of the copyright holder. 32 33************************************************************/ 34 35#define NEED_EVENTS 36#define NEED_REPLIES 37#include <X11/Xlibint.h> 38#include <X11/extensions/Xevie.h> 39#include <X11/extensions/Xeviestr.h> 40#include <X11/extensions/Xext.h> 41#include <X11/extensions/extutil.h> 42 43static XExtensionInfo _xevie_info_data; 44static XExtensionInfo *xevie_info = &_xevie_info_data; 45static char *xevie_extension_name = XEVIENAME; 46static int major_opcode = 0; 47static long xevie_mask = 0; 48 49 50/***************************************************************************** 51 * * 52 * private utility routines * 53 * * 54 *****************************************************************************/ 55 56static int close_display(); 57static /* const */ XExtensionHooks xevie_extension_hooks = { 58 NULL, /* create_gc */ 59 NULL, /* copy_gc */ 60 NULL, /* flush_gc */ 61 NULL, /* free_gc */ 62 NULL, /* create_font */ 63 NULL, /* free_font */ 64 close_display, /* close_display */ 65 NULL, /* wire_to_event */ 66 NULL, /* event_to_wire */ 67 NULL, /* error */ 68 NULL, /* error_string */ 69}; 70 71static XEXT_GENERATE_FIND_DISPLAY (find_display, xevie_info, 72 xevie_extension_name, 73 &xevie_extension_hooks, 74 0, NULL) 75 76static XEXT_GENERATE_CLOSE_DISPLAY (close_display, xevie_info) 77 78/***************************************************************************** 79 * * 80 * public Xevie Extension routines * 81 * * 82 *****************************************************************************/ 83 84Status 85XevieQueryVersion(dpy, major_version_return, minor_version_return) 86 Display* dpy; 87 int* major_version_return; 88 int* minor_version_return; 89{ 90 XExtDisplayInfo *info = find_display (dpy); 91 xXevieQueryVersionReply rep; 92 xXevieQueryVersionReq *req; 93 94 XextCheckExtension(dpy, info, xevie_extension_name, False); 95 96 major_opcode = info->codes->major_opcode; 97 LockDisplay(dpy); 98 GetReq(XevieQueryVersion, req); 99 req->reqType = major_opcode; 100 req->xevieReqType = X_XevieQueryVersion; 101 req->client_major_version = XEVIE_MAJOR_VERSION; 102 req->client_minor_version = XEVIE_MINOR_VERSION; 103 if (!_XReply(dpy, (xReply *)&rep, 0, xTrue)) { 104 UnlockDisplay(dpy); 105 SyncHandle(); 106 return False; 107 } 108 *major_version_return = rep.server_major_version; 109 *minor_version_return = rep.server_minor_version; 110 UnlockDisplay(dpy); 111 SyncHandle(); 112 return True; 113} 114 115/* Win32 reserves 20 colormap entries for its desktop */ 116#ifndef TYP_RESERVED_ENTRIES 117#define TYP_RESERVED_ENTRIES 20 118#endif 119 120Status 121#if NeedFunctionPrototypes 122XevieStart( 123 Display* dpy) 124#else 125XevieStart(dpy) 126 Display* dpy; 127#endif 128{ 129 XExtDisplayInfo *info = find_display (dpy); 130 xXevieStartReply rep; 131 xXevieStartReq *req; 132 133 XextCheckExtension(dpy, info, xevie_extension_name, False); 134 135 major_opcode = info->codes->major_opcode; 136 LockDisplay(dpy); 137 GetReq(XevieStart, req); 138 req->reqType = major_opcode; 139 req->xevieReqType = X_XevieStart; 140 if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 141 } 142 UnlockDisplay(dpy); 143 SyncHandle(); 144 return(rep.pad1); 145} 146 147Status 148XevieEnd(dpy) 149 Display* dpy; 150{ 151 XExtDisplayInfo *info = find_display (dpy); 152 xXevieEndReply rep; 153 xXevieEndReq *req; 154 155 XextCheckExtension (dpy, info, xevie_extension_name, False); 156 157 LockDisplay(dpy); 158 GetReq(XevieEnd, req); 159 req->reqType = info->codes->major_opcode; 160 req->xevieReqType = X_XevieEnd; 161 162 if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 163 } 164 UnlockDisplay(dpy); 165 SyncHandle(); 166 return True; 167} 168 169Status 170XevieSendEvent(dpy, event, dataType) 171 Display* dpy; 172 XEvent* event; 173 char dataType; 174{ 175 xXevieSendReply rep; 176 xXevieSendReq *req; 177 178 LockDisplay(dpy); 179 GetReq(XevieSend, req); 180 req->reqType = major_opcode; 181 req->xevieReqType = X_XevieSend; 182 req->dataType = dataType; 183 _XEventToWire(dpy, event, &req->event); 184 if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 185 } 186 UnlockDisplay(dpy); 187 SyncHandle(); 188 return True; 189} 190 191Status 192XevieSelectInput(dpy, event_mask) 193 Display* dpy; 194 long event_mask; 195{ 196 xXevieSelectInputReply rep; 197 xXevieSelectInputReq *req; 198 199 LockDisplay(dpy); 200 GetReq(XevieSelectInput, req); 201 req->reqType = major_opcode; 202 req->xevieReqType = X_XevieSelectInput; 203 req->event_mask = event_mask; 204 xevie_mask = event_mask; 205 if (_XReply(dpy, (xReply *)&rep, 0, xFalse)) { 206 } 207 UnlockDisplay(dpy); 208 SyncHandle(); 209 return True; 210} 211 212