1c43cc173Smrg/************************************************************
2c43cc173Smrg
3c43cc173SmrgCopyright 1989, 1998  The Open Group
4c43cc173Smrg
5c43cc173SmrgPermission to use, copy, modify, distribute, and sell this software and its
6c43cc173Smrgdocumentation for any purpose is hereby granted without fee, provided that
7c43cc173Smrgthe above copyright notice appear in all copies and that both that
8c43cc173Smrgcopyright notice and this permission notice appear in supporting
9c43cc173Smrgdocumentation.
10c43cc173Smrg
11c43cc173SmrgThe above copyright notice and this permission notice shall be included in
12c43cc173Smrgall copies or substantial portions of the Software.
13c43cc173Smrg
14c43cc173SmrgTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15c43cc173SmrgIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16c43cc173SmrgFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
17c43cc173SmrgOPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
18c43cc173SmrgAN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19c43cc173SmrgCONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20c43cc173Smrg
21c43cc173SmrgExcept as contained in this notice, the name of The Open Group shall not be
22c43cc173Smrgused in advertising or otherwise to promote the sale, use or other dealings
23c43cc173Smrgin this Software without prior written authorization from The Open Group.
24c43cc173Smrg
25c43cc173SmrgCopyright 1989 by Hewlett-Packard Company, Palo Alto, California.
26c43cc173Smrg
27c43cc173Smrg			All Rights Reserved
28c43cc173Smrg
29c43cc173SmrgPermission to use, copy, modify, and distribute this software and its
30c43cc173Smrgdocumentation for any purpose and without fee is hereby granted,
31c43cc173Smrgprovided that the above copyright notice appear in all copies and that
32c43cc173Smrgboth that copyright notice and this permission notice appear in
33c43cc173Smrgsupporting documentation, and that the name of Hewlett-Packard not be
34c43cc173Smrgused in advertising or publicity pertaining to distribution of the
35c43cc173Smrgsoftware without specific, written prior permission.
36c43cc173Smrg
37c43cc173SmrgHEWLETT-PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38c43cc173SmrgALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39c43cc173SmrgHEWLETT-PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40c43cc173SmrgANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41c43cc173SmrgWHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42c43cc173SmrgARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
43c43cc173SmrgSOFTWARE.
44c43cc173Smrg
45c43cc173Smrg********************************************************/
46c43cc173Smrg
47c43cc173Smrg/***********************************************************************
48c43cc173Smrg *
49c43cc173Smrg * XSendExtensionEvent - send an extension event to a client.
50c43cc173Smrg *
51c43cc173Smrg */
52f1ee322dSmrg#ifdef HAVE_CONFIG_H
53f1ee322dSmrg#include <config.h>
54f1ee322dSmrg#endif
55c43cc173Smrg
56c43cc173Smrg#include <X11/extensions/XI.h>
57c43cc173Smrg#include <X11/extensions/XIproto.h>
58c43cc173Smrg#include <X11/Xlibint.h>
59c43cc173Smrg#include <X11/extensions/XInput.h>
60c43cc173Smrg#include <X11/extensions/extutil.h>
61c43cc173Smrg#include "XIint.h"
62c43cc173Smrg
63f1ee322dSmrg/* Xlib's wire_vec is defined for a single event only, libXi may return
64f1ee322dSmrg * multiple events.
65f1ee322dSmrg */
66f1ee322dSmrgtypedef Status (*ext_event_to_wire)(Display*, XEvent*, xEvent**, int*);
67f1ee322dSmrg
68c43cc173SmrgStatus
69c27c18e8SmrgXSendExtensionEvent(
70c27c18e8Smrg    register Display	*dpy,
71c27c18e8Smrg    XDevice		*dev,
72c27c18e8Smrg    Window		 dest,
73c27c18e8Smrg    Bool		 prop,
74c27c18e8Smrg    int			 count,
75c27c18e8Smrg    XEventClass		*list,
76c27c18e8Smrg    XEvent		*event)
77c43cc173Smrg{
78c43cc173Smrg    int num_events;
79c43cc173Smrg    int ev_size;
80c43cc173Smrg    xSendExtensionEventReq *req;
81c43cc173Smrg    xEvent *ev;
82f1ee322dSmrg    ext_event_to_wire *fp;
83c43cc173Smrg    Status status;
84c43cc173Smrg    XExtDisplayInfo *info = XInput_find_display(dpy);
85c43cc173Smrg
86c43cc173Smrg    LockDisplay(dpy);
87c43cc173Smrg    if (_XiCheckExtInit(dpy, XInput_Initial_Release, info) == -1)
88c43cc173Smrg	return (NoSuchExtension);
89c43cc173Smrg
90c43cc173Smrg    /* call through display to find proper conversion routine */
91c43cc173Smrg
92f1ee322dSmrg    fp = (ext_event_to_wire*)&dpy->wire_vec[event->type & 0177];
93c43cc173Smrg    if (*fp == NULL)
94c43cc173Smrg	*fp = _XiEventToWire;
95f1ee322dSmrg    status = (*fp) (dpy, event, &ev, &num_events);
96c43cc173Smrg
97c43cc173Smrg    if (status) {
98c43cc173Smrg	GetReq(SendExtensionEvent, req);
99c43cc173Smrg	req->reqType = info->codes->major_opcode;
100c43cc173Smrg	req->ReqType = X_SendExtensionEvent;
101c43cc173Smrg	req->deviceid = dev->device_id;
102c43cc173Smrg	req->destination = dest;
103c43cc173Smrg	req->propagate = prop;
104c43cc173Smrg	req->count = count;
105c43cc173Smrg	req->num_events = num_events;
106c43cc173Smrg	ev_size = num_events * sizeof(xEvent);
107c43cc173Smrg	req->length += (count + (ev_size >> 2));
108c43cc173Smrg
109c43cc173Smrg	/* note: Data is a macro that uses its arguments multiple
110c43cc173Smrg	 * times, so "count" is changed in a separate assignment
111c43cc173Smrg	 * statement.  Any extra events must be sent before the event
112c43cc173Smrg	 * list, in order to ensure quad alignment. */
113c43cc173Smrg
114c43cc173Smrg	Data(dpy, (char *)ev, ev_size);
115c43cc173Smrg
116c43cc173Smrg	count <<= 2;
117c43cc173Smrg	Data32(dpy, (long *)list, count);
118c43cc173Smrg	XFree((char *)ev);
119c43cc173Smrg    }
120c43cc173Smrg
121c43cc173Smrg    UnlockDisplay(dpy);
122c43cc173Smrg    SyncHandle();
123c43cc173Smrg    return (status);
124c43cc173Smrg}
125