Line 0
Link Here
|
|
|
1 |
/* |
2 |
* $Id: xcalibrate.c,v 3.1 2004/06/02 20:49:50 pb Exp $ |
3 |
* |
4 |
* Copyright © 2003 Philip Blundell |
5 |
* |
6 |
* Permission to use, copy, modify, distribute, and sell this software and its |
7 |
* documentation for any purpose is hereby granted without fee, provided that |
8 |
* the above copyright notice appear in all copies and that both that |
9 |
* copyright notice and this permission notice appear in supporting |
10 |
* documentation, and that the name of Philip Blundell not be used in |
11 |
* advertising or publicity pertaining to distribution of the software without |
12 |
* specific, written prior permission. Philip Blundell makes no |
13 |
* representations about the suitability of this software for any purpose. It |
14 |
* is provided "as is" without express or implied warranty. |
15 |
* |
16 |
* PHILIP BLUNDELL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, |
17 |
* INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO |
18 |
* EVENT SHALL PHILIP BLUNDELL BE LIABLE FOR ANY SPECIAL, INDIRECT OR |
19 |
* CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, |
20 |
* DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
21 |
* TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
22 |
* PERFORMANCE OF THIS SOFTWARE. |
23 |
*/ |
24 |
|
25 |
#ifdef HAVE_KDRIVE_CONFIG_H |
26 |
#include <kdrive-config.h> |
27 |
#endif |
28 |
|
29 |
#define NEED_EVENTS |
30 |
#define NEED_REPLIES |
31 |
|
32 |
#include <X11/X.h> |
33 |
#include <X11/Xproto.h> |
34 |
#include "misc.h" |
35 |
#include "os.h" |
36 |
#include "dixstruct.h" |
37 |
#include "extnsionst.h" |
38 |
#include "swaprep.h" |
39 |
|
40 |
#include <X11/extensions/xcalibrateproto.h> |
41 |
#include <X11/extensions/xcalibratewire.h> |
42 |
|
43 |
extern void (*tslib_raw_event_hook)(int x, int y, int pressure, void *closure); |
44 |
extern void *tslib_raw_event_closure; |
45 |
|
46 |
static CARD8 XCalibrateReqCode; |
47 |
int XCalibrateEventBase; |
48 |
int XCalibrateReqBase; |
49 |
int XCalibrateErrorBase; |
50 |
|
51 |
static ClientPtr xcalibrate_client; |
52 |
|
53 |
static void |
54 |
xcalibrate_event_hook (int x, int y, int pressure, void *closure) |
55 |
{ |
56 |
ClientPtr pClient = (ClientPtr) closure; |
57 |
xXCalibrateRawTouchscreenEvent ev; |
58 |
|
59 |
ev.type = XCalibrateEventBase + X_XCalibrateRawTouchscreen; |
60 |
ev.sequenceNumber = pClient->sequence; |
61 |
ev.x = x; |
62 |
ev.y = y; |
63 |
ev.pressure = pressure; |
64 |
|
65 |
if (!pClient->clientGone) |
66 |
WriteEventsToClient (pClient, 1, (xEvent *) &ev); |
67 |
} |
68 |
|
69 |
static int |
70 |
ProcXCalibrateQueryVersion (ClientPtr client) |
71 |
{ |
72 |
REQUEST(xXCalibrateQueryVersionReq); |
73 |
xXCalibrateQueryVersionReply rep; |
74 |
CARD16 client_major, client_minor; /* not used */ |
75 |
|
76 |
REQUEST_SIZE_MATCH (xXCalibrateQueryVersionReq); |
77 |
|
78 |
client_major = stuff->majorVersion; |
79 |
client_minor = stuff->minorVersion; |
80 |
|
81 |
fprintf(stderr, "%s(): called\n", __func__); |
82 |
|
83 |
rep.type = X_Reply; |
84 |
rep.length = 0; |
85 |
rep.sequenceNumber = client->sequence; |
86 |
rep.majorVersion = XCALIBRATE_MAJOR_VERSION; |
87 |
rep.minorVersion = XCALIBRATE_MINOR_VERSION; |
88 |
if (client->swapped) { |
89 |
int n; |
90 |
swaps(&rep.sequenceNumber, n); |
91 |
swapl(&rep.length, n); |
92 |
swaps(&rep.majorVersion, n); |
93 |
swaps(&rep.minorVersion, n); |
94 |
} |
95 |
WriteToClient(client, sizeof (xXCalibrateQueryVersionReply), (char *)&rep); |
96 |
return (client->noClientException); |
97 |
} |
98 |
|
99 |
static int |
100 |
SProcXCalibrateQueryVersion (ClientPtr client) |
101 |
{ |
102 |
REQUEST(xXCalibrateQueryVersionReq); |
103 |
int n; |
104 |
|
105 |
REQUEST_SIZE_MATCH (xXCalibrateQueryVersionReq); |
106 |
swaps(&stuff->majorVersion,n); |
107 |
swaps(&stuff->minorVersion,n); |
108 |
return ProcXCalibrateQueryVersion(client); |
109 |
} |
110 |
|
111 |
static int |
112 |
ProcXCalibrateSetRawMode (ClientPtr client) |
113 |
{ |
114 |
REQUEST(xXCalibrateRawModeReq); |
115 |
xXCalibrateRawModeReply rep; |
116 |
|
117 |
REQUEST_SIZE_MATCH (xXCalibrateRawModeReq); |
118 |
|
119 |
memset (&rep, 0, sizeof (rep)); |
120 |
rep.type = X_Reply; |
121 |
rep.sequenceNumber = client->sequence; |
122 |
|
123 |
if (stuff->on) |
124 |
{ |
125 |
if (xcalibrate_client == NULL) |
126 |
{ |
127 |
/* Start calibrating. */ |
128 |
xcalibrate_client = client; |
129 |
tslib_raw_event_hook = xcalibrate_event_hook; |
130 |
tslib_raw_event_closure = client; |
131 |
rep.status = GrabSuccess; |
132 |
} |
133 |
else |
134 |
{ |
135 |
rep.status = AlreadyGrabbed; |
136 |
} |
137 |
} |
138 |
else |
139 |
{ |
140 |
if (xcalibrate_client == client) |
141 |
{ |
142 |
/* Stop calibrating. */ |
143 |
xcalibrate_client = NULL; |
144 |
tslib_raw_event_hook = NULL; |
145 |
tslib_raw_event_closure = NULL; |
146 |
rep.status = GrabSuccess; |
147 |
|
148 |
/* Cycle input off and on to reload configuration. */ |
149 |
KdDisableInput (); |
150 |
KdEnableInput (); |
151 |
} |
152 |
else |
153 |
{ |
154 |
rep.status = AlreadyGrabbed; |
155 |
} |
156 |
} |
157 |
|
158 |
if (client->swapped) |
159 |
{ |
160 |
int n; |
161 |
|
162 |
swaps (&rep.sequenceNumber, n); |
163 |
swaps (&rep.status, n); |
164 |
} |
165 |
WriteToClient(client, sizeof (rep), (char *) &rep); |
166 |
return (client->noClientException); |
167 |
} |
168 |
|
169 |
|
170 |
static int |
171 |
SProcXCalibrateSetRawMode (ClientPtr client) |
172 |
{ |
173 |
REQUEST(xXCalibrateRawModeReq); |
174 |
int n; |
175 |
|
176 |
REQUEST_SIZE_MATCH (xXCalibrateRawModeReq); |
177 |
|
178 |
swaps(&stuff->on, n); |
179 |
|
180 |
return ProcXCalibrateSetRawMode(client); |
181 |
} |
182 |
|
183 |
static void |
184 |
XCalibrateResetProc (ExtensionEntry *extEntry) |
185 |
{ |
186 |
} |
187 |
|
188 |
static int |
189 |
ProcXCalibrateDispatch (ClientPtr client) |
190 |
{ |
191 |
REQUEST(xReq); |
192 |
switch (stuff->data) { |
193 |
case X_XCalibrateQueryVersion: |
194 |
return ProcXCalibrateQueryVersion(client); |
195 |
case X_XCalibrateRawMode: |
196 |
return ProcXCalibrateSetRawMode(client); |
197 |
default: break; |
198 |
} |
199 |
|
200 |
return BadRequest; |
201 |
} |
202 |
|
203 |
static int |
204 |
SProcXCalibrateDispatch (ClientPtr client) |
205 |
{ |
206 |
REQUEST(xReq); |
207 |
int n; |
208 |
|
209 |
swaps(&stuff->length,n); |
210 |
|
211 |
switch (stuff->data) { |
212 |
case X_XCalibrateQueryVersion: |
213 |
return SProcXCalibrateQueryVersion(client); |
214 |
case X_XCalibrateRawMode: |
215 |
return SProcXCalibrateSetRawMode(client); |
216 |
|
217 |
default: break; |
218 |
} |
219 |
|
220 |
return BadRequest; |
221 |
} |
222 |
|
223 |
static void |
224 |
XCalibrateClientCallback (CallbackListPtr *list, |
225 |
pointer closure, |
226 |
pointer data) |
227 |
{ |
228 |
NewClientInfoRec *clientinfo = (NewClientInfoRec *) data; |
229 |
ClientPtr pClient = clientinfo->client; |
230 |
|
231 |
if (clientinfo->setup == NULL |
232 |
&& xcalibrate_client != NULL |
233 |
&& xcalibrate_client == pClient) |
234 |
{ |
235 |
/* Stop calibrating. */ |
236 |
xcalibrate_client = NULL; |
237 |
tslib_raw_event_hook = NULL; |
238 |
tslib_raw_event_closure = NULL; |
239 |
} |
240 |
} |
241 |
|
242 |
void |
243 |
XCalibrateExtensionInit(void) |
244 |
{ |
245 |
ExtensionEntry *extEntry; |
246 |
|
247 |
if (!AddCallback (&ClientStateCallback, XCalibrateClientCallback, 0)) |
248 |
return; |
249 |
|
250 |
extEntry = AddExtension(XCALIBRATE_NAME, XCalibrateNumberEvents, XCalibrateNumberErrors, |
251 |
ProcXCalibrateDispatch, SProcXCalibrateDispatch, |
252 |
XCalibrateResetProc, StandardMinorOpcode); |
253 |
|
254 |
if (!extEntry) |
255 |
return; |
256 |
|
257 |
XCalibrateReqCode = (unsigned char)extEntry->base; |
258 |
XCalibrateEventBase = extEntry->eventBase; |
259 |
XCalibrateErrorBase = extEntry->errorBase; |
260 |
|
261 |
xcalibrate_client = 0; |
262 |
} |