First import
[xorg_rtime.git] / xorg-server-1.4 / Xext / xcalibrate.c
blob97ef3dc38c0eee89cf1223dc427173dfe6bb9755
1 /*
2 * Copyright © 2003 Philip Blundell
4 * Permission to use, copy, modify, distribute, and sell this software and its
5 * documentation for any purpose is hereby granted without fee, provided that
6 * the above copyright notice appear in all copies and that both that
7 * copyright notice and this permission notice appear in supporting
8 * documentation, and that the name of Philip Blundell not be used in
9 * advertising or publicity pertaining to distribution of the software without
10 * specific, written prior permission. Philip Blundell makes no
11 * representations about the suitability of this software for any purpose. It
12 * is provided "as is" without express or implied warranty.
14 * PHILIP BLUNDELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
16 * EVENT SHALL PHILIP BLUNDELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
18 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
19 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
23 #ifdef HAVE_KDRIVE_CONFIG_H
24 #include <kdrive-config.h>
25 #endif
27 #define NEED_EVENTS
28 #define NEED_REPLIES
30 #include <X11/X.h>
31 #include <X11/Xproto.h>
32 #include "misc.h"
33 #include "os.h"
34 #include "dixstruct.h"
35 #include "extnsionst.h"
36 #include "swaprep.h"
38 #include <X11/extensions/xcalibrateproto.h>
39 #include <X11/extensions/xcalibratewire.h>
41 extern void (*tslib_raw_event_hook)(int x, int y, int pressure, void *closure);
42 extern void *tslib_raw_event_closure;
44 static CARD8 XCalibrateReqCode;
45 int XCalibrateEventBase;
46 int XCalibrateReqBase;
47 int XCalibrateErrorBase;
49 static ClientPtr xcalibrate_client;
51 static void
52 xcalibrate_event_hook (int x, int y, int pressure, void *closure)
54 ClientPtr pClient = (ClientPtr) closure;
55 xXCalibrateRawTouchscreenEvent ev;
57 ev.type = XCalibrateEventBase + X_XCalibrateRawTouchscreen;
58 ev.sequenceNumber = pClient->sequence;
59 ev.x = x;
60 ev.y = y;
61 ev.pressure = pressure;
63 if (!pClient->clientGone)
64 WriteEventsToClient (pClient, 1, (xEvent *) &ev);
67 static int
68 ProcXCalibrateQueryVersion (ClientPtr client)
70 REQUEST(xXCalibrateQueryVersionReq);
71 xXCalibrateQueryVersionReply rep;
72 CARD16 client_major, client_minor; /* not used */
74 REQUEST_SIZE_MATCH (xXCalibrateQueryVersionReq);
76 client_major = stuff->majorVersion;
77 client_minor = stuff->minorVersion;
79 fprintf(stderr, "%s(): called\n", __func__);
81 rep.type = X_Reply;
82 rep.length = 0;
83 rep.sequenceNumber = client->sequence;
84 rep.majorVersion = XCALIBRATE_MAJOR_VERSION;
85 rep.minorVersion = XCALIBRATE_MINOR_VERSION;
86 if (client->swapped) {
87 int n;
88 swaps(&rep.sequenceNumber, n);
89 swapl(&rep.length, n);
90 swaps(&rep.majorVersion, n);
91 swaps(&rep.minorVersion, n);
93 WriteToClient(client, sizeof (xXCalibrateQueryVersionReply), (char *)&rep);
94 return (client->noClientException);
97 static int
98 SProcXCalibrateQueryVersion (ClientPtr client)
100 REQUEST(xXCalibrateQueryVersionReq);
101 int n;
103 REQUEST_SIZE_MATCH (xXCalibrateQueryVersionReq);
104 swaps(&stuff->majorVersion,n);
105 swaps(&stuff->minorVersion,n);
106 return ProcXCalibrateQueryVersion(client);
109 static int
110 ProcXCalibrateSetRawMode (ClientPtr client)
112 REQUEST(xXCalibrateRawModeReq);
113 xXCalibrateRawModeReply rep;
115 REQUEST_SIZE_MATCH (xXCalibrateRawModeReq);
117 memset (&rep, 0, sizeof (rep));
118 rep.type = X_Reply;
119 rep.sequenceNumber = client->sequence;
121 if (stuff->on)
123 if (xcalibrate_client == NULL)
125 /* Start calibrating. */
126 xcalibrate_client = client;
127 tslib_raw_event_hook = xcalibrate_event_hook;
128 tslib_raw_event_closure = client;
129 rep.status = GrabSuccess;
131 else
133 rep.status = AlreadyGrabbed;
136 else
138 if (xcalibrate_client == client)
140 /* Stop calibrating. */
141 xcalibrate_client = NULL;
142 tslib_raw_event_hook = NULL;
143 tslib_raw_event_closure = NULL;
144 rep.status = GrabSuccess;
146 /* Cycle input off and on to reload configuration. */
147 KdDisableInput ();
148 KdEnableInput ();
150 else
152 rep.status = AlreadyGrabbed;
156 if (client->swapped)
158 int n;
160 swaps (&rep.sequenceNumber, n);
161 swaps (&rep.status, n);
163 WriteToClient(client, sizeof (rep), (char *) &rep);
164 return (client->noClientException);
168 static int
169 SProcXCalibrateSetRawMode (ClientPtr client)
171 REQUEST(xXCalibrateRawModeReq);
172 int n;
174 REQUEST_SIZE_MATCH (xXCalibrateRawModeReq);
176 swaps(&stuff->on, n);
178 return ProcXCalibrateSetRawMode(client);
181 static void
182 XCalibrateResetProc (ExtensionEntry *extEntry)
186 static int
187 ProcXCalibrateDispatch (ClientPtr client)
189 REQUEST(xReq);
190 switch (stuff->data) {
191 case X_XCalibrateQueryVersion:
192 return ProcXCalibrateQueryVersion(client);
193 case X_XCalibrateRawMode:
194 return ProcXCalibrateSetRawMode(client);
195 default: break;
198 return BadRequest;
201 static int
202 SProcXCalibrateDispatch (ClientPtr client)
204 REQUEST(xReq);
205 int n;
207 swaps(&stuff->length,n);
209 switch (stuff->data) {
210 case X_XCalibrateQueryVersion:
211 return SProcXCalibrateQueryVersion(client);
212 case X_XCalibrateRawMode:
213 return SProcXCalibrateSetRawMode(client);
215 default: break;
218 return BadRequest;
221 static void
222 XCalibrateClientCallback (CallbackListPtr *list,
223 pointer closure,
224 pointer data)
226 NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
227 ClientPtr pClient = clientinfo->client;
229 if (clientinfo->setup == NULL
230 && xcalibrate_client != NULL
231 && xcalibrate_client == pClient)
233 /* Stop calibrating. */
234 xcalibrate_client = NULL;
235 tslib_raw_event_hook = NULL;
236 tslib_raw_event_closure = NULL;
240 void
241 XCalibrateExtensionInit(void)
243 ExtensionEntry *extEntry;
245 if (!AddCallback (&ClientStateCallback, XCalibrateClientCallback, 0))
246 return;
248 extEntry = AddExtension(XCALIBRATE_NAME, XCalibrateNumberEvents, XCalibrateNumberErrors,
249 ProcXCalibrateDispatch, SProcXCalibrateDispatch,
250 XCalibrateResetProc, StandardMinorOpcode);
252 if (!extEntry)
253 return;
255 XCalibrateReqCode = (unsigned char)extEntry->base;
256 XCalibrateEventBase = extEntry->eventBase;
257 XCalibrateErrorBase = extEntry->errorBase;
259 xcalibrate_client = 0;