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>
31 #include <X11/Xproto.h>
34 #include "dixstruct.h"
35 #include "extnsionst.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
;
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
;
61 ev
.pressure
= pressure
;
63 if (!pClient
->clientGone
)
64 WriteEventsToClient (pClient
, 1, (xEvent
*) &ev
);
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__
);
83 rep
.sequenceNumber
= client
->sequence
;
84 rep
.majorVersion
= XCALIBRATE_MAJOR_VERSION
;
85 rep
.minorVersion
= XCALIBRATE_MINOR_VERSION
;
86 if (client
->swapped
) {
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
);
98 SProcXCalibrateQueryVersion (ClientPtr client
)
100 REQUEST(xXCalibrateQueryVersionReq
);
103 REQUEST_SIZE_MATCH (xXCalibrateQueryVersionReq
);
104 swaps(&stuff
->majorVersion
,n
);
105 swaps(&stuff
->minorVersion
,n
);
106 return ProcXCalibrateQueryVersion(client
);
110 ProcXCalibrateSetRawMode (ClientPtr client
)
112 REQUEST(xXCalibrateRawModeReq
);
113 xXCalibrateRawModeReply rep
;
115 REQUEST_SIZE_MATCH (xXCalibrateRawModeReq
);
117 memset (&rep
, 0, sizeof (rep
));
119 rep
.sequenceNumber
= client
->sequence
;
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
;
133 rep
.status
= AlreadyGrabbed
;
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. */
152 rep
.status
= AlreadyGrabbed
;
160 swaps (&rep
.sequenceNumber
, n
);
161 swaps (&rep
.status
, n
);
163 WriteToClient(client
, sizeof (rep
), (char *) &rep
);
164 return (client
->noClientException
);
169 SProcXCalibrateSetRawMode (ClientPtr client
)
171 REQUEST(xXCalibrateRawModeReq
);
174 REQUEST_SIZE_MATCH (xXCalibrateRawModeReq
);
176 swaps(&stuff
->on
, n
);
178 return ProcXCalibrateSetRawMode(client
);
182 XCalibrateResetProc (ExtensionEntry
*extEntry
)
187 ProcXCalibrateDispatch (ClientPtr client
)
190 switch (stuff
->data
) {
191 case X_XCalibrateQueryVersion
:
192 return ProcXCalibrateQueryVersion(client
);
193 case X_XCalibrateRawMode
:
194 return ProcXCalibrateSetRawMode(client
);
202 SProcXCalibrateDispatch (ClientPtr client
)
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
);
222 XCalibrateClientCallback (CallbackListPtr
*list
,
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
;
241 XCalibrateExtensionInit(void)
243 ExtensionEntry
*extEntry
;
245 if (!AddCallback (&ClientStateCallback
, XCalibrateClientCallback
, 0))
248 extEntry
= AddExtension(XCALIBRATE_NAME
, XCalibrateNumberEvents
, XCalibrateNumberErrors
,
249 ProcXCalibrateDispatch
, SProcXCalibrateDispatch
,
250 XCalibrateResetProc
, StandardMinorOpcode
);
255 XCalibrateReqCode
= (unsigned char)extEntry
->base
;
256 XCalibrateEventBase
= extEntry
->eventBase
;
257 XCalibrateErrorBase
= extEntry
->errorBase
;
259 xcalibrate_client
= 0;