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