SendEvent.c revision e9fcaa8a
1/* 2 3Copyright 1986, 1998 The Open Group 4 5Permission to use, copy, modify, distribute, and sell this software and its 6documentation for any purpose is hereby granted without fee, provided that 7the above copyright notice appear in all copies and that both that 8copyright notice and this permission notice appear in supporting 9documentation. 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 18AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 19CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 20 21Except as contained in this notice, the name of The Open Group shall not be 22used in advertising or otherwise to promote the sale, use or other dealings 23in this Software without prior written authorization from The Open Group. 24 25*/ 26 27#ifdef HAVE_CONFIG_H 28#include <config.h> 29#endif 30#include "Xlibint.h" 31 32/* 33 * In order to avoid all images requiring _XEventToWire, we install the 34 * event converter here if it has never been installed. 35 */ 36Status 37XSendEvent( 38 register Display *dpy, 39 Window w, 40 Bool propagate, 41 long event_mask, 42 XEvent *event) 43{ 44 register xSendEventReq *req; 45 xEvent ev; 46 register Status (**fp)( 47 Display * /* dpy */, 48 XEvent * /* re */, 49 xEvent * /* event */); 50 Status status; 51 52 /* initialize all of the event's fields first, before setting 53 * the meaningful ones later. 54 */ 55 memset (&ev, 0, sizeof (ev)); 56 57 LockDisplay (dpy); 58 59 /* call through display to find proper conversion routine */ 60 61 fp = &dpy->wire_vec[event->type & 0177]; 62 if (*fp == NULL) *fp = _XEventToWire; 63 status = (**fp)(dpy, event, &ev); 64 65 if (status) { 66 GetReq(SendEvent, req); 67 req->destination = w; 68 req->propagate = propagate; 69 req->eventMask = event_mask; 70#ifdef WORD64 71 /* avoid quad-alignment problems */ 72 memcpy ((char *) req->eventdata, (char *) &ev, SIZEOF(xEvent)); 73#else 74 req->event = ev; 75#endif /* WORD64 */ 76 } 77 78 UnlockDisplay(dpy); 79 SyncHandle(); 80 return(status); 81} 82