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>
29
#include <X11/Xproto.h>
32
#include "dixstruct.h"
33
#include "extnsionst.h"
35
#include "protocol-versions.h"
37
#include <X11/extensions/xcalibrateproto.h>
38
#include <X11/extensions/xcalibratewire.h>
40
extern void (*tslib_raw_event_hook)(int x, int y, int pressure, void *closure);
41
extern void *tslib_raw_event_closure;
43
static CARD8 XCalibrateReqCode;
44
int XCalibrateEventBase;
45
int XCalibrateReqBase;
46
int XCalibrateErrorBase;
48
static ClientPtr xcalibrate_client;
51
xcalibrate_event_hook (int x, int y, int pressure, void *closure)
53
ClientPtr pClient = (ClientPtr) closure;
54
xXCalibrateRawTouchscreenEvent ev;
56
ev.type = XCalibrateEventBase + X_XCalibrateRawTouchscreen;
59
ev.pressure = pressure;
61
WriteEventsToClient (pClient, 1, (xEvent *) &ev);
65
ProcXCalibrateQueryVersion (ClientPtr client)
67
REQUEST(xXCalibrateQueryVersionReq);
68
xXCalibrateQueryVersionReply rep;
69
CARD16 client_major, client_minor; /* not used */
71
REQUEST_SIZE_MATCH (xXCalibrateQueryVersionReq);
73
client_major = stuff->majorVersion;
74
client_minor = stuff->minorVersion;
76
fprintf(stderr, "%s(): called\n", __func__);
80
rep.sequenceNumber = client->sequence;
81
rep.majorVersion = SERVER_XCALIBRATE_MAJOR_VERSION;
82
rep.minorVersion = SERVER_XCALIBRATE_MINOR_VERSION;
83
if (client->swapped) {
85
swaps(&rep.sequenceNumber, n);
86
swapl(&rep.length, n);
87
swaps(&rep.majorVersion, n);
88
swaps(&rep.minorVersion, n);
90
WriteToClient(client, sizeof (xXCalibrateQueryVersionReply), (char *)&rep);
95
SProcXCalibrateQueryVersion (ClientPtr client)
97
REQUEST(xXCalibrateQueryVersionReq);
100
REQUEST_SIZE_MATCH (xXCalibrateQueryVersionReq);
101
swaps(&stuff->majorVersion,n);
102
swaps(&stuff->minorVersion,n);
103
return ProcXCalibrateQueryVersion(client);
107
ProcXCalibrateSetRawMode (ClientPtr client)
109
REQUEST(xXCalibrateRawModeReq);
110
xXCalibrateRawModeReply rep;
112
REQUEST_SIZE_MATCH (xXCalibrateRawModeReq);
114
memset (&rep, 0, sizeof (rep));
116
rep.sequenceNumber = client->sequence;
120
if (xcalibrate_client == NULL)
122
/* Start calibrating. */
123
xcalibrate_client = client;
124
tslib_raw_event_hook = xcalibrate_event_hook;
125
tslib_raw_event_closure = client;
126
rep.status = GrabSuccess;
130
rep.status = AlreadyGrabbed;
135
if (xcalibrate_client == client)
137
/* Stop calibrating. */
138
xcalibrate_client = NULL;
139
tslib_raw_event_hook = NULL;
140
tslib_raw_event_closure = NULL;
141
rep.status = GrabSuccess;
143
/* Cycle input off and on to reload configuration. */
149
rep.status = AlreadyGrabbed;
157
swaps (&rep.sequenceNumber, n);
158
swaps (&rep.status, n);
160
WriteToClient(client, sizeof (rep), (char *) &rep);
165
SProcXCalibrateSetRawMode (ClientPtr client)
167
REQUEST(xXCalibrateRawModeReq);
170
REQUEST_SIZE_MATCH (xXCalibrateRawModeReq);
172
swaps(&stuff->on, n);
174
return ProcXCalibrateSetRawMode(client);
178
ProcXCalibrateScreenToCoord (ClientPtr client)
180
REQUEST(xXCalibrateScreenToCoordReq);
181
xXCalibrateScreenToCoordReply rep;
183
REQUEST_SIZE_MATCH (xXCalibrateScreenToCoordReq);
185
memset (&rep, 0, sizeof (rep));
187
rep.sequenceNumber = client->sequence;
191
KdScreenToPointerCoords(&rep.x, &rep.y);
200
WriteToClient(client, sizeof (rep), (char *) &rep);
205
SProcXCalibrateScreenToCoord (ClientPtr client)
207
REQUEST(xXCalibrateScreenToCoordReq);
210
REQUEST_SIZE_MATCH (xXCalibrateScreenToCoordReq);
215
return ProcXCalibrateScreenToCoord(client);
219
ProcXCalibrateDispatch (ClientPtr client)
222
switch (stuff->data) {
223
case X_XCalibrateQueryVersion:
224
return ProcXCalibrateQueryVersion(client);
225
case X_XCalibrateRawMode:
226
return ProcXCalibrateSetRawMode(client);
227
case X_XCalibrateScreenToCoord:
228
return ProcXCalibrateScreenToCoord(client);
237
SProcXCalibrateDispatch (ClientPtr client)
242
swaps(&stuff->length,n);
244
switch (stuff->data) {
245
case X_XCalibrateQueryVersion:
246
return SProcXCalibrateQueryVersion(client);
247
case X_XCalibrateRawMode:
248
return SProcXCalibrateSetRawMode(client);
249
case X_XCalibrateScreenToCoord:
250
return SProcXCalibrateScreenToCoord(client);
259
XCalibrateClientCallback (CallbackListPtr *list,
263
NewClientInfoRec *clientinfo = (NewClientInfoRec *) data;
264
ClientPtr pClient = clientinfo->client;
266
if (clientinfo->setup == NULL
267
&& xcalibrate_client != NULL
268
&& xcalibrate_client == pClient)
270
/* Stop calibrating. */
271
xcalibrate_client = NULL;
272
tslib_raw_event_hook = NULL;
273
tslib_raw_event_closure = NULL;
278
XCalibrateExtensionInit(void)
280
ExtensionEntry *extEntry;
282
if (!AddCallback (&ClientStateCallback, XCalibrateClientCallback, 0))
285
extEntry = AddExtension(XCALIBRATE_NAME, XCalibrateNumberEvents, XCalibrateNumberErrors,
286
ProcXCalibrateDispatch, SProcXCalibrateDispatch,
287
NULL, StandardMinorOpcode);
292
XCalibrateReqCode = (unsigned char)extEntry->base;
293
XCalibrateEventBase = extEntry->eventBase;
294
XCalibrateErrorBase = extEntry->errorBase;
296
xcalibrate_client = 0;