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